public async Task <ActionResult> AssignTicket(Ticket model) { var ticket = db.Tickets.Find(model.Id); ticket.AssignedToUserId = model.AssignedToUserId; var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticket.Id); db.SaveChanges(); NotificationHelper.CreateAssignmentNotification(oldTicket, ticket); HistoryHelper.CreateHistoryRecord(oldTicket, ticket); var callbackUrl = Url.Action("Details", "Tickets", new { id = ticket.Id }, protocol: Request.Url.Scheme); try { EmailService ems = new EmailService(); IdentityMessage msg = new IdentityMessage(); ApplicationUser user = db.Users.Find(model.AssignedToUserId); msg.Body = "You have been assigned to a new Ticket." + Environment.NewLine + "please click the following link to view details" + "<a href=\"" + callbackUrl + "\">NEW TICKET</a>"; msg.Destination = user.Email; msg.Subject = "Invite to Household"; await ems.SendAsync(msg); } catch (Exception) { await Task.FromResult(0); } return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,ProjectId,TicketTypeId,TicketStatusId,TicketPriorityId,OwnerUserId,AssignedToUserId,Title,Description,Created,Updated")] Ticket ticket) { if (ModelState.IsValid) { //Go out to the database and get a copy of the ticket before it is changed var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticket.Id); db.Entry(ticket).State = EntityState.Modified; ticket.Updated = DateTime.Now; db.SaveChanges(); //Call the NotificationHelper to determine if a Notification needs to be created NotificationHelper.CreateAssignmentNotification(oldTicket, ticket); NotificationHelper.CreateChangeNotification(oldTicket, ticket); // NotificationHelper.ManageNotifications(oldTicket, ticket); //HistoryHelper HistoryHelper.CreateHistoryRecord(oldTicket, ticket); return(RedirectToAction("Index")); } ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "FirstName", ticket.AssignedToUserId); ViewBag.OwnerUserId = new SelectList(db.Users, "Id", "FirstName", ticket.OwnerUserId); ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name", ticket.ProjectId); ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", ticket.TicketPriorityId); ViewBag.TicketStatusId = new SelectList(db.TicketStatuses, "Id", "Name", ticket.TicketStatusId); ViewBag.TicketTypeId = new SelectList(db.TicketTypes, "Id", "Name", ticket.TicketTypeId); return(View(ticket)); }