private static void GenerateNotification(TicketNotification notification) { var db = new ApplicationDbContext(); var newNotification = new TicketNotification { Created = DateTime.Now, SenderId = HttpContext.Current.User.Identity.GetUserId(), RecipientId = notification.RecipientId, Message = notification.Message, HasBeenRead = false, TicketId = notification.TicketId, }; db.Notifications.Add(newNotification); db.SaveChanges(); //newNotification.SenderId = HttpContext.Current.User.Identity.GetUserId(); }
public ActionResult Create([Bind(Include = "TicketId,CommentBody")] TicketComment comment, int id) { var ticket = _db.Tickets.Find(id); if (ticket == null) { ModelState.AddModelError("Ticket", @"Failed to find associated Ticket"); return(RedirectToAction("Index", "Tickets")); } if (ModelState.IsValid) { var userId = User.Identity.GetUserId(); var canAddContent = _ticketHelper.CanAddContent(userId, ticket); if (canAddContent) { comment.TicketId = id; comment.AuthorId = User.Identity.GetUserId(); comment.Created = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); _db.TicketComments.Add(comment); var res = _db.SaveChanges(); if (ticket.AssignedToId != null) { comment.Author = _db.Users.Find(userId); var commentAuthorName = comment.Author == null ? "UNKNOWN" : comment.Author.DisplayName; var notificationCreationDateTime = DateTime.Now; var notification = new TicketNotification { TicketId = ticket.Id, Created = notificationCreationDateTime, Subject = $"A ticket you're Assigned to '{ticket.Title}' has a new Comment!", IsRead = false, RecipientId = ticket.AssignedToId, NotificationBody = $"Ticket '{ticket.Title}' ({ticket.DisplayableId}) has a new Comment from {commentAuthorName}" }; _db.TicketNotifications.Add(notification); _db.SaveChanges(); } } } return(RedirectToAction("Dashboard", "Tickets", new { id })); }
private void GenerateAssignmentNotification(Ticket oldTicket, Ticket newTicket) { var senderId = HttpContext.Current.User.Identity.GetUserId(); var notification = new TicketNotification { Created = DateTime.Now, Subject = $"You were assigned to Ticket Id {newTicket.Id} on {DateTime.Now}", Read = false, RecipientId = newTicket.AssignedToUserId, SenderId = HttpContext.Current.User.Identity.GetUserId(), NotificationBody = $"Please acknowledge that you have read this notification by checking 'Read'", TicketId = newTicket.Id }; db.TicketNotifications.Add(notification); db.SaveChanges(); }
private void GenerateAssignmentNotification(Ticket oldTicket, Ticket newTicket) { var senderId = HttpContext.Current.User.Identity.GetUserId(); var notification = new TicketNotification { Created = DateTime.Now, Subject = $"You were assigned to Ticket '{newTicket.Title}' on {DateTime.Now.ToString("M/d/yyyy mm:hhtt")}", IsRead = false, RecipientId = newTicket.AssignedToUserId, SenderId = senderId, NotificationBody = $"Please acknowledge that you have read this notification by marking it as 'READ'.", TicketId = newTicket.Id }; db.TicketNotifications.Add(notification); db.SaveChanges(); }
public static void CreateCommentNotification(Ticket ticket, TicketComment ticketComment) { var authorName = db.Users.Find(ticketComment.AuthorId).FirstName; var notification = new TicketNotification { Created = DateTime.Now, Subject = $"commented on {ticket.Title}.", Read = false, RecipientId = ticket.AssignedToUserId, SenderId = HttpContext.Current.User.Identity.GetUserId(), NotificationBody = $"{authorName} commented: {ticketComment.CommentBody}", TicketId = ticket.Id }; db.TicketNotifications.Add(notification); db.SaveChanges(); }
// GET: TicketNotifications/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TicketNotification ticketNotification = db.TicketNotifications.Find(id); if (ticketNotification == null) { return(HttpNotFound()); } ViewBag.RecipientId = new SelectList(db.Users, "Id", "FirstName", ticketNotification.RecipientId); ViewBag.SubmitterId = new SelectList(db.Users, "Id", "FirstName", ticketNotification.SubmitterId); ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketNotification.TicketId); return(View(ticketNotification)); }
public void AddAttachmentNotification(TicketAttachment ticket) { var title = db.Tickets.Where(t => t.Id == ticket.TicketId).FirstOrDefault().Title; var notification = new TicketNotification { TicketId = ticket.TicketId, isRead = false, SenderId = ticket.UserId, RecipientId = db.Tickets.Where(t => t.Id == ticket.TicketId).FirstOrDefault().DeveloperId, Created = DateTime.Now, //NotificationBody = $"{ticket.User.DisplayName} added an attachment was added to Ticket #{ticket.TicketId}: {title}." NotificationBody = $"An attachment was added to Ticket #{ticket.TicketId}: {title}." }; db.TicketNotifications.Add(notification); db.SaveChanges(); }
public static void GenerateCommentNotification(Ticket ticket) { var localDate = DateTime.UtcNow.AddHours(-4); var notification = new TicketNotification { Created = localDate, Subject = $"A comment was added to {ticket.Title} on {DateTime.Now}", IsRead = false, RecipientId = ticket.AssignedToUserId, SenderId = HttpContext.Current.User.Identity.GetUserId(), NotificationBody = $"Please acknowledge that you have read this notification by marking as read", TicketId = ticket.Id }; db.TicketNotifications.Add(notification); db.SaveChanges(); }
private void GenerateUnAssignmentNotification(Ticket oldTicket, Ticket newTicket) { var localDate = DateTime.UtcNow.AddHours(-4); var notification = new TicketNotification { Created = localDate, Subject = $"You were unassigned from {newTicket.Title} on {DateTime.Now}", IsRead = false, RecipientId = oldTicket.AssignedToUserId, SenderId = HttpContext.Current.User.Identity.GetUserId(), NotificationBody = $"Please acknowledge that you have read this notification by marking it as read", TicketId = newTicket.Id }; db.TicketNotifications.Add(notification); db.SaveChanges(); }
public void CommentEditNotification(ApplicationUser commentor, TicketComment tComment, DateTimeOffset commentTimeStamp) { var assignedUserId = (db.TicketPosts.Find(tComment.TicketID).AssignedToUser != null) ? db.TicketPosts.Find(tComment.TicketID).AssignedToUser.Id : "Unassigned"; if (assignedUserId != "Unassigned") { var newTicketNotification = new TicketNotification(); newTicketNotification.Notification = " Has edited a comment on Ticket # " + tComment.TicketID + "."; newTicketNotification.TriggeredByUserId = commentor.Id; newTicketNotification.TicketID = tComment.TicketID; newTicketNotification.Created = commentTimeStamp; newTicketNotification.UserID = assignedUserId; db.TicketNotifications.Add(newTicketNotification); //Save Ticket Notification db.SaveChanges(); } }
//Assignment Notification public static void GenerateAssignmentNotification(Ticket oldTicket, Ticket newTicket) { HistoryHelper.RecordDeveloperAssignment(oldTicket, newTicket); var notification = new TicketNotification { Created = DateTime.Now, //Subject = $"You were unassigned from Ticket {newTicket.Id} on {DateTime.Now.ToString("MM/dd/yyyy h:mm tt")}", ReadStatus = false, RecieverId = newTicket.AssignedToUserId, SenderId = HttpContext.Current.User.Identity.GetUserId(), NotificationBody = $"You were assigned to Ticket {oldTicket.Id} on {DateTime.Now.ToString("MM/dd/yyyy h:mm tt")}.", TicketId = oldTicket.Id }; db.TicketNotifications.Add(notification); db.SaveChanges(); }
//CREATE TICKET public void createTicketComment(TicketComment model, string userId) { var ticket = TicketRepo.GetEntity(x => x.Id == model.TicketId); var ticketComment = TicketCommentRepo.GetEntity(x => x.Comment == model.Comment && x.TicketId == ticket.Id); if (ticketComment == null) { TicketComment newticketComment = new TicketComment(model.Comment, model.Created, userId, model.TicketId); TicketCommentRepo.Add(newticketComment); } if (ticket.AssignedToUserId != null) { TicketNotification notification = new TicketNotification(ticket.AssignedToUserId, ticket.Id, true); TicketNotificationRepo.Add(notification); } }
public async Task UnassignmentNotification(int ticket, string user) { var msg = new IdentityMessage(); msg.Subject = "BugTracer Ticket Reassigned"; msg.Destination = db.Users.Find(user).Email; msg.Body = String.Format("Ticket number {0} (Title: {1}) has been assigned to another developer. You are no longer responsible for this ticket.", ticket, db.Tickets.Find(ticket).title); await email.SendAsync(msg); // create db record for notification var ticketNotification = new TicketNotification(); ticketNotification.TicketId = ticket; ticketNotification.UserId = user; db.TicketNotifications.Add(ticketNotification); db.SaveChanges(); }
public void AddTicketNotification(int ticketId, string oldAssignedToId, string newAssignedToId) { if (String.IsNullOrEmpty(oldAssignedToId) && String.IsNullOrEmpty(newAssignedToId)) { return; } //Assigning if (String.IsNullOrEmpty(oldAssignedToId) && !String.IsNullOrEmpty(newAssignedToId)) { //Grab a copy of the ticket var ticket = db.Tickets.AsNoTracking().Include("Project").FirstOrDefault(t => t.Id == ticketId); //Create a new TicketNotification and set some default properties var userId = HttpContext.Current.User.Identity.GetUserId(); var ticketNotification = new TicketNotification(); ticketNotification.SenderId = userId; ticketNotification.Created = DateTime.Now; ticketNotification.TicketId = ticketId; ticketNotification.RecipientId = newAssignedToId; //Assemble body of the message var msgBody = new StringBuilder(); msgBody.AppendFormat("Hello {0},", db.Users.FirstOrDefault(u => u.Id == newAssignedToId).FirstName); msgBody.AppendFormat(""); msgBody.AppendFormat("You have been assigned a freakin Ticket! Here's the info: "); msgBody.AppendFormat(" Ticket Id: " + ticketId); msgBody.AppendFormat(" Ticket Title: " + ticket.Title); msgBody.AppendFormat(" Project Id: " + ticket.ProjectId); msgBody.AppendFormat(" Project Title: " + ticket.Project.Name); msgBody.AppendFormat(""); msgBody.AppendFormat("Let me know if you have any questions!"); msgBody.AppendFormat(db.Users.FirstOrDefault(u => u.Id == userId).FirstName); //Set Body ticketNotification.Body = msgBody.ToString(); db.TicketNotifications.Add(ticketNotification); db.SaveChanges(); //TODO: Here I can also send an email notification... //Start code: Add code here to email password reset link } }
private async Task GenerateAssignmentNotification(Ticket oldTicket, Ticket newTicket) { var notification = new TicketNotification { Created = DateTime.Now, Subject = $"assigned you to a new ticket", Read = false, RecipientId = newTicket.AssignedToUserId, SenderId = HttpContext.Current.User.Identity.GetUserId(), NotificationBody = $"You have been assigned to ticket {newTicket.Title}.", TicketId = newTicket.Id }; db.TicketNotifications.Add(notification); db.SaveChanges(); var newNotification = db.TicketNotifications.Include("Sender").Include("Recipient").FirstOrDefault(t => t.Id == notification.Id); await GenerateNotificationEmail(newNotification); }
public ActionResult Create([Bind(Include = "Id,TicketId,UserId,Notice,Read")] TicketNotification ticketNotification, string notice) { var Helper = new UserNotificationsHelper(); ViewBag.Notifications = Helper.filterNotifications(User.Identity.GetUserId()); if (ModelState.IsValid) { db.TicketNotifications.Add(new TicketNotification { Notice = notice, TicketId = ticketNotification.TicketId, Read = false, UserId = db.Tickets.Find(ticketNotification.TicketId).OwnerUser.Id }); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketNotification.TicketId); return View(ticketNotification); }
public void TicketNewAttachmentAdded(TicketAttachment newAttachment) { var CurrUser = newAttachment.ticket.project.Users.FirstOrDefault(); foreach (var user in ticketHelper.ListTicketUsers(newAttachment.ticket.Id)) { var newNotification = new TicketNotification() { TicketId = newAttachment.TicketId, UserId = user.Id, Created = DateTime.Now, Icon = "fa-ticket", NotificationType = "success", Subject = $"New Comment Added to {newAttachment.TicketId}", Message = $"Hello {user.FullName}, A new Comment has been added to the Ticket: {newAttachment.TicketId}, by {CurrUser.FullName}", }; db.Notifications.Add(newNotification); } }
public ActionResult Delete(int?id) { if (User.Identity.GetUserId() == "db9a774b-807c-4b9b-9b22-34c191872996" || User.Identity.GetUserId() == "3eaa1491-7553-40fa-b7e1-b994e05d05e0" || User.Identity.GetUserId() == "5f84068f-4213-4d02-81a4-21936ae10cdc" || User.Identity.GetUserId() == "60f316c5-536c-4f06-83d3-38a555febc29") { return(RedirectToAction("InvalidAttempt", "Home")); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TicketNotification ticketNotification = db.TicketNotifications.Find(id); if (ticketNotification == null) { return(HttpNotFound()); } return(View(ticketNotification)); }
//Overloaded method to send email to user when comment added to ticket public async Task AddTicketNotification(TicketComment comment) { var myComment = db.Tickets.AsNoTracking().Include("Project").FirstOrDefault(t => t.Id == comment.TicketId); var user = db.Users.FirstOrDefault(u => u.Id == myComment.AssignedToUserId); if (user != null) { //Create new notification var ticketNotification = new TicketNotification(); ticketNotification.SenderId = comment.UserId; ticketNotification.Created = DateTime.Now; ticketNotification.TicketId = comment.TicketId; ticketNotification.RecipientId = myComment.AssignedToUserId; //Assemble notification body var msgBody = new StringBuilder(); msgBody.AppendFormat("Hello {0}", user.FirstName); msgBody.AppendLine(""); msgBody.AppendLine("A comment has been added to ticket: " + myComment.Title + ", for project: " + myComment.Project.Name); //Set Body ticketNotification.Body = msgBody.ToString(); db.TicketNotifications.Add(ticketNotification); db.SaveChanges(); //Send email var from = "Kink Fix<*****@*****.**>"; var to = db.Users.Find(myComment.AssignedToUserId).Email; var email = new MailMessage(from, to) { Subject = "Kink Fix: You have a new notification", Body = "A comment has been added to one of your assigned tickets. Please sign into your Kink Fix account to view details.", IsBodyHtml = true }; var svc = new PersonalEmail(); await svc.SendAsync(email); } }
public ActionResult CreateComment([Bind(Include = "Id,TicketId,Comment,Created")] TicketComment ticketcomment) { if (ModelState.IsValid) { // TempData["UserPreferences"] is read in at Start of Action var userPref = (UserPreferencesViewModel)TempData["UserPreferences"]; if (ticketcomment.Comment == null) { ViewBag.StatusMessage = "Please enter a valid comment."; ViewBag.CommentErrorMsg = "Please enter a valid comment."; return(RedirectToAction("Details", new { id = ticketcomment.TicketId })); } ticketcomment.Created = DateTime.Now; ticketcomment.UserId = User.Identity.GetUserId(); db.TicketComments.Add(ticketcomment); db.SaveChanges(); TicketNotification ticketnotif = new TicketNotification(); ticketnotif.TicketId = ticketcomment.TicketId; ticketnotif.UserId = db.Tickets.Find(ticketnotif.TicketId).AssignedToUserId; var sendtoemail = db.Tickets.Find(ticketnotif.TicketId).AssignedToUser.Email; ticketnotif.Message = "A new comment was added to a ticket you are assigned to on BugTracker.Pro."; ticketnotif.Created = DateTime.Now; db.Entry(ticketnotif).State = EntityState.Modified; db.TicketNotifications.Add(ticketnotif); db.SaveChanges(); // TempData["UserPreferences"] is rewritten at End of Action TempData["UserPreferences"] = userPref; ViewBag.FilterByTickets = userPref.FilterByTickets; ViewBag.FilterByStatus = userPref.FilterByStatus; return(RedirectToAction("EmailNotification", "Account", new { sendemail = sendtoemail, sendmsg = ticketnotif.Message, ticketId = ticketnotif.TicketId })); } ViewBag.StatusMessage = "An error occurred submitting your comment; please try again later."; ViewBag.CommentErrorMsg = "An error occurred submitting your comment; please try again later."; return(RedirectToAction("Details", new { id = ticketcomment.TicketId })); }
public ActionResult AddTicketUsers(TicketUserViewModel ticketUser) { var applicationUserId = User.Identity.GetUserId(); var developerRole = DbContext.Roles.FirstOrDefault(r => r.Name == "Developer").Id; var unassignedDeveloperUsers = DbContext.Users; var user = DbContext.Users.Where(u => u.Roles.Any(p => p.RoleId == developerRole)) .FirstOrDefault(p => p.Id == ticketUser.UserID); var ticket = DbContext.Tickets.FirstOrDefault( p => p.ID == ticketUser.ID); if (user == null) { return(RedirectToAction(nameof(ManageProjectUsersController.EditProjectUsers))); } var historyWriter = new CustomHelpers(); historyWriter.MakeTicketHistories(ticket, user, applicationUserId); var message = new IdentityMessage { Destination = $"{user.Email}", Subject = $"You've been assigned to a new a new ticket: {ticket.Title}", Body = $"new ticket--- {ticket.Title}: {ticket.Description}" }; var emailService = new EmailService(); emailService.SendAsync(message); ticket.AssignedToUserID = user.Id; var ticketNotification = new TicketNotification { UserID = user.Id, TicketID = ticket.ID }; DbContext.TicketNotifications.Add(ticketNotification); DbContext.SaveChanges(); return(RedirectToAction("EditTicketUsers", "ManageTicketUsers", new { id = ticketUser.ID })); }
public void TicketNewCommentAdded(TicketComment newComment) { var CurrUser = db.Users.Find(HttpContext.Current.User.Identity.GetUserId()); foreach (var user in ticketHelper.ListTicketUsers(newComment.TicketId)) { var newNotification = new TicketNotification() { TicketId = newComment.TicketId, UserId = user.Id, Created = DateTime.Now, Icon = "fa-ticket", Subject = $"New Comment Added to {newComment.TicketId}", Message = $"Hello {user.FullName}, A new Comment has been added to the Ticket: {newComment.TicketId}, by {CurrUser.FullName}", NotificationType = "info" }; db.Notifications.Add(newNotification); } db.SaveChanges(); }
//UPDATE TICKET public void updateTicket(CreateTicketViewModel model, string userId) { var ticketCopy = TicketRepo.GetEntity(x => x.Id == model.Id); TicketTypeRepo.Update(ticketCopy.TicketTypeId, model.TicketTypeName); TicketPriorityRepo.Update(ticketCopy.TicketPriorityId, model.Priority); if (ticketCopy.AssignedToUserId != null) { TicketNotification notification = new TicketNotification(ticketCopy.AssignedToUserId, ticketCopy.Id, true); TicketNotificationRepo.Add(notification); } TicketHistory history = new TicketHistory(model.Id, "property", ticketCopy.Description, model.Description, true, userId); TicketHistoryRepo.Add(history); TicketRepo.Update(model); }
public bool InitializeNoti(int ticketId, string userId, string notiReci, string message) { TicketNotification noti = new TicketNotification(); noti.TicketId = ticketId; noti.UserId = userId; noti.Recipient = notiReci; noti.Message = message; bool result = Notification(noti.Recipient, noti.Message); if (result == true) { noti.NotiSent = true; noti.SentDate = System.DateTimeOffset.Now; db.TicketNotification.Add(noti); db.SaveChanges(); } return(true); }
public async Task CommentNotification(int ticket, string user, string ticketTitle, string commentBody, string commentAuthor) { var msg = new IdentityMessage(); msg.Subject = "New BugTracker Comment"; msg.Destination = db.Users.Find(user).Email; msg.Body = String.Format(@"A comment has been posted to a ticket to which you are assigned. <br /> Ticket: {0}, {1} <br /> Comment: {2} <br /> Posted By: {3}", ticket, ticketTitle, commentBody, commentAuthor); await email.SendAsync(msg); // create db record for notification var ticketNotification = new TicketNotification(); ticketNotification.TicketId = ticket; ticketNotification.UserId = user; db.TicketNotifications.Add(ticketNotification); db.SaveChanges(); }
public async Task <ActionResult> Create([Bind(Include = "Id,Comment,Created,TicketId,UserId")] TicketComment ticketComment) { if (ModelState.IsValid) { var ticket = db.Tickets.Find(ticketComment.TicketId); var sendeeemail = db.Users.Find(ticket.AssignedToUserId).Email; ticketComment.UserId = User.Identity.GetUserId(); ticketComment.Created = DateTime.Now; db.TicketComments.Add(ticketComment); db.SaveChanges(); var callbackUrl = Url.Action("Details", "Tickets", new { id = ticket.Id }, protocol: Request.Url.Scheme); try { EmailService ems = new EmailService(); IdentityMessage msg = new IdentityMessage(); msg.Body = "A new comment has been added. " + Environment.NewLine + "Please click the following link to view the details" + "<a href=\"" + callbackUrl + "\"> New Commment</a>"; msg.Destination = sendeeemail; msg.Subject = "New Comment"; TicketNotification ticketNotification = new TicketNotification(); ticketNotification.TicketId = ticketComment.TicketId; ticketNotification.Created = DateTime.Now; ticketNotification.UserId = User.Identity.GetUserId(); ticketNotification.Message = msg.Body; db.TicketNotifications.Add(ticketNotification); db.SaveChanges(); await ems.SendMailAsync(msg); } catch (Exception ex) { await Task.FromResult(0); } return(RedirectToAction("Details", "Tickets", new { id = ticketComment.TicketId })); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketComment.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketComment.UserId); return(RedirectToAction("Details", "Tickets", new { id = ticketComment.TicketId })); }
public void TicketClosedNotification(Ticket ticket) { if (ticket.IsResolved == true) { foreach (var user in ticketHelper.ListTicketUsers(ticket.Id)) { var newNotification = new TicketNotification() { TicketId = ticket.Id, UserId = user.Id, Created = DateTime.Now, Icon = "fa-ticket", Subject = $"Ticket Id: {ticket.Id} Has been Closed", NotificationType = "info", Message = $"Hello, {user.FullName} you have been assigned to Ticket: {ticket.Issue} on Project {ticket.project.Name}", }; db.Notifications.Add(newNotification); } } }
public async Task AssignmentNotification(int ticket, string user) { // send email to developer var msg = new IdentityMessage(); msg.Subject = "New BugTracker Assignment"; msg.Destination = db.Users.Find(user).Email; msg.Body = "You are the assigned develper for ticket number " + ticket + "\nTicket Title: " + db.Tickets.Find(ticket).title; await email.SendAsync(msg); // create db record for notification var ticketNotification = new TicketNotification(); ticketNotification.TicketId = ticket; ticketNotification.UserId = user; db.TicketNotifications.Add(ticketNotification); db.SaveChanges(); }
public void CreateChangeNotification(Ticket oldTicket, Ticket newTicket) { var messageBody = new StringBuilder(); foreach (var property in WebConfigurationManager.AppSettings["TrackedTicketProperties"].Split(',')) { var oldValue = Utilities.MakeReadable(property, oldTicket.GetType().GetProperty(property).GetValue(oldTicket, null)?.ToString()); var newValue = Utilities.MakeReadable(property, newTicket.GetType().GetProperty(property).GetValue(newTicket, null)?.ToString()); if (oldValue != newValue) { messageBody.AppendLine(new String('-', 45)); messageBody.AppendLine($"A change was made to Property: {property}."); messageBody.AppendLine($"The old value was: {oldValue?.ToString()}"); messageBody.AppendLine($"The new value is: {newValue?.ToString()}"); } } if (!string.IsNullOrEmpty(messageBody.ToString())) { var message = new StringBuilder(); message.AppendLine($"Changes were made to Ticket Id: {newTicket.Id} on {newTicket.Updated.GetValueOrDefault().ToString("MMM d, yyyy")}"); message.AppendLine(messageBody.ToString()); var senderId = HttpContext.Current.User.Identity.GetUserId(); var notification = new TicketNotification { TicketId = newTicket.Id, Created = DateTime.Now, Subject = $"Ticket Id: {newTicket.Id} has changed", RecipientId = oldTicket.AssignedToUserId, SenderId = senderId, NotificationBody = message.ToString(), isRead = false }; db.TicketNotifications.Add(notification); db.SaveChanges(); } }
private static void ManageAssignmentNotifs(Ticket oldTicket, Ticket newTicket) { var assigned = oldTicket.AssignedToUserId == null && newTicket.AssignedToUserId != null; var unassigned = oldTicket.AssignedToUserId != null && newTicket.AssignedToUserId == null; var reassigned = newTicket.AssignedToUserId != null && newTicket.AssignedToUserId != oldTicket.AssignedToUserId; TicketNotification notif = new TicketNotification(); notif.TicketId = oldTicket.Id; //Check if assigned/unass/reass if (assigned) { notif.RecipientUserId = newTicket.AssignedToUserId; notif.NotifBody = $"Assigned: {newTicket.Title}"; notif.NotifType = "Urgent"; notif.Created = DateTime.Now; GenerateNotif(notif); } else if (unassigned) { notif.RecipientUserId = oldTicket.AssignedToUserId; notif.NotifBody = $"Unassigned: {newTicket.Title}"; notif.NotifType = "Low"; notif.Created = DateTime.Now; GenerateNotif(notif); } else if (reassigned) { notif.RecipientUserId = oldTicket.AssignedToUserId; notif.NotifBody = $"You have been unassigned to Ticket ID: {oldTicket.Id}, titled: {oldTicket.Title}"; notif.NotifType = "Low"; notif.Created = DateTime.Now; GenerateNotif(notif); notif.RecipientUserId = newTicket.AssignedToUserId; notif.NotifBody = $"You have been assigned to Ticket ID: {newTicket.Id}, titled: {newTicket.Title}"; notif.NotifType = "Urgent"; notif.Created = DateTime.Now; GenerateNotif(notif); } }