0

i would like to add some more functionalities to my method, such as an email to be sent once the user has successfully edited the data. i could need with some help as i do not how to approach this functionality.

     [HttpPost]
    public ActionResult Edit(EditPTG eptg)
    {
        try
        {
            using (ManageGrade gradLogic = new ManageGrade(ref uow))
            {
                foreach (var ptg in eptg.ptgForGrade)
                {
                    ptg.Overwritten = true;
                    ptg.Active = true;
                    productToGradeLogic.Update(ptg);
                }


                gradLogic.Update(eptg.grade);


                TempData["Success"] = "Edit Successful";
                MailMessage mail = new MailMessage();

                return RedirectToAction("Index");
            }
        }
        catch
        {
            TempData["Failure"] = "Edit Failed, Please Review Your Selections and Try Again.";
            return View(eptg);
        }
    }
cedPound
  • 367
  • 1
  • 3
  • 14
  • Can you provide more details? I think you have the right idea with MailMessage but this obviously needs more detailed implementation. You need to specify server, sender, recipient etc. Isn't that what you are trying to do or is there more to it? – Imran Saeed Dec 22 '16 at 11:50
  • Possible duplicate of [How to send email in ASP.NET C#](http://stackoverflow.com/questions/18326738/how-to-send-email-in-asp-net-c-sharp) – tym32167 Dec 22 '16 at 11:56
  • @i.net yes that is what i am trying to do but struggling to do it at the moment. and to answer your question, ideally i would like the mail to be sent after the gradLogic.update has been called – cedPound Dec 22 '16 at 11:57
  • Assuming that gradLogic.Update throws an error or is synchronous then your email will be sent after this method. See @tym32167 comment for how to send emails from ASP.Net C#. I think this will answer your question – Imran Saeed Dec 22 '16 at 12:01
  • @i.net thanks i follow the example – cedPound Dec 22 '16 at 13:09
  • @tym32167 thanks for the link – cedPound Dec 22 '16 at 13:09

0 Answers0