Exemplo n.º 1
0
        private TicketHistoryEntry UpdateTitle(string newValue, IPrincipal User, ApplicationDbContext context)
        {
            var history = new TicketHistoryEntry()
            {
                UserId = User.Identity.GetUserId(), ParentTicketId = this.Id, EntryType = TicketHistoryEntry.TicketHistoryEntryType.TitleModified, OldData = this.Title, NewData = newValue, OccuredAt = DateTime.Now
            };

            context.TicketNotifications.AddRange(
                TicketNotification.GenerateNotifications(context, User.Identity.GetUserId(), this.Id, $"Title was updated from '{this.Title}' to '{newValue}'")
                );

            var ticket = context.Tickets.Find(this.Id);

            ticket.LastInteractionAt = DateTime.Now;
            ticket.Title             = newValue;

            context.SaveChanges();

            return(history);
        }
Exemplo n.º 2
0
        public static ICollection <TicketNotification> GenerateNotifications(ApplicationDbContext context, string senderId, int ticketId, string body, bool forceToReporter = false, bool forceToAllStaff = false)
        {
            var output     = new List <TicketNotification>();
            var recipients = GetNotificationRecipients(context, senderId, ticketId);
            var now        = DateTime.Now;

            foreach (string recip in recipients)
            {
                var notif = new TicketNotification()
                {
                    ParentTicketId     = ticketId
                    , Created          = now
                    , IsRead           = false
                    , NotificationBody = body
                    , RecipientId      = recip
                    , SenderId         = senderId
                };
                output.Add(notif);
            }

            return(output);
        }