Guest User

Untitled

a guest
Oct 30th, 2017
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. [HttpPost]
  2. public ActionResult Create(HelpViewModel model)
  3. {
  4. if (ModelState.IsValid)
  5. {
  6. Help help = Mapper.Map<HelpViewModel, Help>(model);
  7. ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
  8. help.Email = user.Email;
  9. help.Condition = HelpStatus.Unassigned;
  10. help.Priority = (Priority)Priority.Low;
  11. help.DateCreated = DateTime.Now;
  12. SendMail(help.Condition);
  13. unitOfWork.HelpRepository.Insert(help);
  14. unitOfWork.Save();
  15. return RedirectToAction("Index");
  16. }
  17.  
  18. return View(model);
  19. }
  20.  
  21. private void SendMail(HelpStatus Condition)
  22. {
  23. using (var smtp = new SmtpClient())
  24. {
  25. var credential = new NetworkCredential
  26. {
  27. UserName = "HighSepton",
  28. Password = ""
  29. };
  30. smtp.Credentials = credential;
  31. smtp.Host = "post.example.com";
  32. smtp.Port = 587;
  33. smtp.EnableSsl = true;
  34. MailMessage mailMessage = new MailMessage();
  35. mailMessage.From = new MailAddress("HighSepton@example.com");
  36. mailMessage.To.Add("HighSepton@example.com");
  37. switch (Condition)
  38. {
  39. case HelpStatus.Unassigned:
  40. mailMessage.Subject = "New question created";
  41. break;
  42. case HelpStatus.Assigned:
  43. mailMessage.Subject = "Question has been assigned with solutions or employees";
  44. break;
  45. case HelpStatus.Completed:
  46. mailMessage.Subject = "Question solutions have been completed";
  47. break;
  48. }
  49. mailMessage.Body = "Hello my friend!";
  50. smtp.Send(mailMessage);
  51. }
  52. }
Add Comment
Please, Sign In to add comment