Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- public ActionResult Create(HelpViewModel model)
- {
- if (ModelState.IsValid)
- {
- Help help = Mapper.Map<HelpViewModel, Help>(model);
- ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
- help.Email = user.Email;
- help.Condition = HelpStatus.Unassigned;
- help.Priority = (Priority)Priority.Low;
- help.DateCreated = DateTime.Now;
- SendMail(help.Condition);
- unitOfWork.HelpRepository.Insert(help);
- unitOfWork.Save();
- return RedirectToAction("Index");
- }
- return View(model);
- }
- private void SendMail(HelpStatus Condition)
- {
- using (var smtp = new SmtpClient())
- {
- var credential = new NetworkCredential
- {
- UserName = "HighSepton",
- Password = ""
- };
- smtp.Credentials = credential;
- smtp.Host = "post.example.com";
- smtp.Port = 587;
- smtp.EnableSsl = true;
- MailMessage mailMessage = new MailMessage();
- mailMessage.From = new MailAddress("HighSepton@example.com");
- mailMessage.To.Add("HighSepton@example.com");
- switch (Condition)
- {
- case HelpStatus.Unassigned:
- mailMessage.Subject = "New question created";
- break;
- case HelpStatus.Assigned:
- mailMessage.Subject = "Question has been assigned with solutions or employees";
- break;
- case HelpStatus.Completed:
- mailMessage.Subject = "Question solutions have been completed";
- break;
- }
- mailMessage.Body = "Hello my friend!";
- smtp.Send(mailMessage);
- }
- }
Add Comment
Please, Sign In to add comment