Example #1
0
        // GET: TicketHistories/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TicketHistory ticketHistory = db.TicketHistories.Find(id);

            if (ticketHistory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.TicketId = new SelectList(db.Tickets, "Id", "OwnerUserId", ticketHistory.TicketId);
            ViewBag.UserId   = new SelectList(db.Users, "Id", "LastName", ticketHistory.UserId);
            return(View(ticketHistory));
        }
        public ActionResult Edit(Tickets tickets)
        {
            if (ModelState.IsValid)
            {

                var userId = User.Identity.GetUserId();
                var changed = System.DateTimeOffset.Now;
                var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == tickets.Id);
                var AssignedUser = db.Users.Find(tickets.AssignedToUserId);
                EmailService es = new EmailService();
                if (oldTicket.Title != tickets.Title)
                {
                    var history1 = new TicketHistory();
                    history1.TicketsId = tickets.Id;
                    history1.Property = "Title";
                    history1.OldValue = oldTicket.Title;
                    history1.NewValue = tickets.Title;
                    history1.Changed = changed;
                    history1.UserId = userId;
                    db.TicketHistories.Add(history1);
                }

                if (oldTicket.Description != tickets.Description)
                {
                    var history2 = new TicketHistory();
                    history2.TicketsId = tickets.Id;
                    history2.Property = "Description";
                    history2.OldValue = oldTicket.Description;
                    history2.NewValue = tickets.Description;
                    history2.Changed = changed;
                    history2.UserId = userId;
                    db.TicketHistories.Add(history2);
                }

                if (oldTicket.TicketPriorityId != tickets.TicketPriorityId)
                {
                    var history3 = new TicketHistory();
                    history3.TicketsId = tickets.Id;
                    history3.Property = "Priority";
                    history3.OldValue = oldTicket.TicketPriority.Name;
                    history3.NewValue = db.TicketPriorities.Find(tickets.TicketPriorityId).Name;
                    history3.Changed = changed;
                    history3.UserId = userId;
                    db.TicketHistories.Add(history3);
                    IdentityMessage im3 = new IdentityMessage
                    {
                        Subject = "Ticket Priority Change",
                        Body = tickets.Title + " had a priority change.",
                        Destination = AssignedUser.Email
                    };
                    es.SendAsync(im3);

                    var notification3 = new TicketNotification();
                    notification3.TicketsId = tickets.Id;
                    notification3.TimeStamp = changed;
                    notification3.UserId = userId;
                    notification3.Message = "Subject: " + im3.Subject + "Message: " + im3.Body;
                    notification3.Message = im3.Subject;
                    db.TicketNotification.Add(notification3);
                }

                if (oldTicket.TicketStatusId != tickets.TicketStatusId)
                {
                    var history4 = new TicketHistory();
                    history4.TicketsId = tickets.Id;
                    history4.Property = "Status";
                    history4.OldValue = oldTicket.TicketStatus.Name;
                    history4.NewValue = db.TicketStatus.Find(tickets.TicketStatusId).Name;
                    history4.Changed = changed;
                    history4.UserId = userId;
                    db.TicketHistories.Add(history4);
                    IdentityMessage im4 = new IdentityMessage
                    {
                        Subject = "Ticket Status Change",
                        Body = tickets.Title + " has had a status change.",
                        Destination = AssignedUser.Email
                    };
                    es.SendAsync(im4);

                    var notification4 = new TicketNotification();
                    notification4.TicketsId = tickets.Id;
                    notification4.TimeStamp = changed;
                    notification4.UserId = userId;
                    notification4.Message = "Subject: " + im4.Subject + "Message: " + im4.Body;
                    notification4.Message = im4.Subject;
                    db.TicketNotification.Add(notification4);
                }

                if (oldTicket.TicketTypeId != tickets.TicketTypeId)
                {
                    var history5 = new TicketHistory();
                    history5.TicketsId = tickets.Id;
                    history5.Property = "Type of Ticket";
                    history5.OldValue = oldTicket.TicketType.Name;
                    history5.NewValue = db.TicketType.Find(tickets.TicketTypeId).Name;
                    history5.Changed = changed;
                    history5.UserId = userId;
                    db.TicketHistories.Add(history5);
                }

                if (oldTicket.AssignedToUserId != tickets.AssignedToUserId)
                {
                    var history6 = new TicketHistory();
                    history6.TicketsId = tickets.Id;
                    history6.Property = "Assigned To";
                    history6.OldValue = oldTicket.AssignedToUser == null ? "" : oldTicket.AssignedToUser.FirstName;
                    history6.NewValue = db.Users.Find(tickets.AssignedToUserId).FirstName;

                    history6.Changed = changed;
                    history6.UserId = userId;
                    db.TicketHistories.Add(history6);

                    IdentityMessage im6 = new IdentityMessage
                    {
                        Subject = "Ticket Assignment",
                        Body = tickets.Title + " has been assigned to you.",
                        Destination = AssignedUser.Email
                    };
                    es.SendAsync(im6);

                    var notification6 = new TicketNotification();
                    notification6.TicketsId = tickets.Id;
                    notification6.TimeStamp = changed;
                    notification6.UserId = userId;
                    notification6.Message = "Subject: " + im6.Subject + "Message : " + im6.Body;
                    db.TicketNotification.Add(notification6);
                }

                tickets.Updated = DateTimeOffset.Now;
                db.Tickets.Attach(tickets);
                db.Entry(tickets).Property(p => p.AssignedToUserId).IsModified = true;
                db.Entry(tickets).Property(p => p.Description).IsModified = true;
                db.Entry(tickets).Property(p => p.TicketStatusId).IsModified = true;
                db.Entry(tickets).Property(p => p.TicketTypeId).IsModified = true;
                db.Entry(tickets).Property(p => p.TicketPriorityId).IsModified = true;

                if(tickets.TicketStatusId == 1)
                {
                    tickets.AssignedToUserId = null;
                }

                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name", tickets.ProjectId);
            ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", tickets.TicketPriorityId);
            ViewBag.TicketStatusId = new SelectList(db.TicketStatus, "Id", "Name", tickets.TicketStatusId);
            ViewBag.TicketTypeId = new SelectList(db.TicketType, "Id", "Name", tickets.TicketTypeId);
            ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "FirstName");
            return RedirectToAction("Index");
        }
        public ActionResult Edit(Ticket ticket)
        {
            var user = db.Users.Find(User.Identity.GetUserId());
            var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticket.Id);
            if (ModelState.IsValid)
            {
                if (oldTicket.Body != ticket.Body)
                {
                    var notification = new TicketNotification();
                    var history = new TicketHistory();
                    history.OldValue = oldTicket.Body;
                    history.NewValue = ticket.Body;
                    history.ChangedById = User.Identity.GetUserId();
                    history.TicketId = ticket.Id;
                    db.TicketHistories.Add(history);
                    notification.UserId = ticket.AssignedUserId;
                    notification.TicketId = ticket.Id;
                    notification.Content =  "changed the body of the ticket!";
                    db.TicketNotifications.Add(notification);

                }

                if (oldTicket.Title != ticket.Title)
                {
                    var notification = new TicketNotification();
                    var history = new TicketHistory();
                    history.OldValue = oldTicket.Title;
                    history.NewValue = ticket.Title;
                    history.ChangedById = User.Identity.GetUserId();
                    history.TicketId = ticket.Id;
                    db.TicketHistories.Add(history);
                    notification.UserId = ticket.AssignedUserId;
                    notification.TicketId = ticket.Id;
                    notification.Content =  "changed the title of the ticket!";
                    db.TicketNotifications.Add(notification);

                }

                //if (oldTicket.AssignedUserId != ticket.AssignedUserId)
                //{
                //    var notification = new TicketNotification();
                //    var history = new TicketHistory();
                //    history.OldValue = oldTicket.AssignedUser.DisplayName;
                //    history.NewValue = db.Tickets.Find(ticket.Id).AssignedUser.DisplayName;
                //    history.ChangedById = User.Identity.GetUserId();
                //    history.TicketId = ticket.Id;
                //    db.TicketHistories.Add(history);
                //    notification.UserId = ticket.AssignedUserId;
                //    notification.TicketId = ticket.Id;
                //    db.TicketNotifications.Add(notification);
                //}

                if (oldTicket.PriorityId != ticket.PriorityId)
                {
                    var notification = new TicketNotification();
                    var history = new TicketHistory();
                    history.OldValue = oldTicket.Priority.Name;
                    history.NewValue = db.TicketPriorities.Find(ticket.PriorityId).Name;
                    history.ChangedById = User.Identity.GetUserId();
                    history.TicketId = ticket.Id;
                    db.TicketHistories.Add(history);
                    notification.UserId = ticket.AssignedUserId;
                    notification.TicketId = ticket.Id;
                    notification.Content =  "changed the priority of the ticket!";
                    db.TicketNotifications.Add(notification);
                }

                if (oldTicket.ProjectId != ticket.ProjectId)
                {
                    var notification = new TicketNotification();
                    var history = new TicketHistory();
                    history.OldValue = oldTicket.Project.Name;
                    history.NewValue = db.Projects.Find(ticket.ProjectId).Name;
                    history.ChangedById = User.Identity.GetUserId();
                    history.TicketId = ticket.Id;
                    db.TicketHistories.Add(history);
                    notification.UserId = ticket.AssignedUserId;
                    notification.TicketId = ticket.Id;
                    notification.Content =  "changed the project of the ticket!";
                    db.TicketNotifications.Add(notification);
                }

                if (oldTicket.StatusId != ticket.StatusId)
                {
                    var notification = new TicketNotification();
                    var history = new TicketHistory();
                    history.OldValue = oldTicket.Status.Name;
                    history.NewValue = db.TicketStatuses.Find(ticket.StatusId).Name;
                    history.ChangedById = User.Identity.GetUserId();
                    history.TicketId = ticket.Id;
                    db.TicketHistories.Add(history);
                    notification.UserId = ticket.AssignedUserId;
                    notification.TicketId = ticket.Id;
                    notification.Content =  "changed the status of the ticket!";
                    db.TicketNotifications.Add(notification);
                }

                if (oldTicket.TypeId != ticket.TypeId)
                {
                    var notification = new TicketNotification();
                    var history = new TicketHistory();
                    history.OldValue = oldTicket.Type.Name;
                    history.NewValue = db.TicketTypes.Find(ticket.TypeId).Name;
                    history.ChangedById = User.Identity.GetUserId();
                    history.TicketId = ticket.Id;
                    db.TicketHistories.Add(history);
                    notification.UserId = ticket.AssignedUserId;
                    notification.TicketId = ticket.Id;
                    notification.Content =  "changed the type of the ticket!";
                    db.TicketNotifications.Add(notification);

                }

                db.Tickets.Add(ticket);
                ticket.Updated = DateTimeOffset.Now;

                db.Entry(ticket).State = EntityState.Modified;

                db.SaveChanges();

            }
            return RedirectToAction("Details", new { id = ticket.Id });
        }
        public ActionResult AddAttachment([Bind(Include = "TicketId,Description")]TicketAttachment ticketAttachment, HttpPostedFileBase file, int ticketId)
        {
            if (file != null && file.ContentLength > 0)
            {
                var ext = Path.GetExtension(file.FileName).ToLower();

                if (ext != ".png" && ext != ".jpg" && ext != ".gif" && ext != ".bmp" && ext != ".txt" && ext != ".pfd")
                {
                    ModelState.AddModelError("file", "Invalid Format.");
                }
            }

            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    var filePath = "/img/";
                    var absPath = Server.MapPath("~" + filePath);
                    ticketAttachment.FileUrl = filePath + file.FileName;
                    file.SaveAs(Path.Combine(absPath, file.FileName));
                }

                var user = db.Users.Find(User.Identity.GetUserId());

                Ticket ticket = db.Tickets.Find(ticketId);

                bool notificationChecker = false;

                var attachmentHistory = new TicketHistory()
                {
                    TicketId = ticketId,
                    Property = "Attachments",
                    PropertyDisplay = "Attachment",
                    OldValue = ticket.Attachments.Count().ToString(),
                    OldValueDisplay = ticket.Attachments.Count().ToString(),
                    NewValue = (ticket.Attachments.Count() + 1).ToString(),
                    NewValueDisplay = (ticket.Attachments.Count() + 1).ToString(),
                    Changed = DateTimeOffset.Now,
                    UserId = user.DisplayName,
                    Ticket = db.Tickets.Find(ticketId),
                    User = user
                };

                var assignedUser = ticket.AssignedToUser;

                var notification = assignedUser != null ? new IdentityMessage()
                {
                    Subject = "An attachment has been added to a ticket that you're assigned to.",
                    Destination = assignedUser.Email,
                    Body = user.DisplayName + " has added an attachment to a ticket you're assigned to. The ticket title is '" + ticket.Title + "'.<br /><br />Following is informaton regarding the attachment:<br /><b>Created: </b>" + ticketAttachment.Created + "<br /><b>Description: </b>" + ticketAttachment.Description != null ? ticketAttachment.Description : null
                } : null;

                if (notification != null) 
                { 
                    var mailer = new EmailService();
                    mailer.SendAsync(notification);
                    notificationChecker = true;
                }

                ticketAttachment.UserId = User.Identity.GetUserId();
                ticketAttachment.Created = DateTimeOffset.Now;
                db.TicketAttachments.Add(ticketAttachment);
                db.TicketHistories.Add(attachmentHistory);

                if (notificationChecker)
                {
                    var notificationHistory = new TicketHistory()
                    {
                        TicketId = ticketId,
                        Property = "Notifications",
                        PropertyDisplay = "Notification",
                        OldValue = ticket.Notifications.Count().ToString(),
                        OldValueDisplay = ticket.Notifications.Count().ToString(),
                        NewValue = (ticket.Notifications.Count() + 1).ToString(),
                        NewValueDisplay = (ticket.Notifications.Count() + 1).ToString(),
                        Changed = DateTimeOffset.Now,
                        UserId = user.DisplayName,
                        Ticket = db.Tickets.Find(ticketId),
                        User = user
                    };
                    db.TicketHistories.Add(notificationHistory);
                }

                db.SaveChanges();
                return RedirectToAction("Details", new { id = ticketId });
            }
            return View(ticketAttachment);
        }
        public ActionResult CreateComment([Bind(Include = "TicketId,Comment,Created")]TicketComment ticketComment, int ticketId)
        {
            if (ModelState.IsValid)
            {
                var user = db.Users.Find(User.Identity.GetUserId());

                Ticket ticket = db.Tickets.Find(ticketId);

                bool notificationChecker = false;

                var commentHistory = new TicketHistory()
                {
                    TicketId = ticketId,
                    Property = "Comments",
                    PropertyDisplay = "Comment",
                    OldValue = ticket.Comments.Count().ToString(),
                    OldValueDisplay = ticket.Comments.Count().ToString(),
                    NewValue = (ticket.Comments.Count() + 1).ToString(),
                    NewValueDisplay = (ticket.Comments.Count() + 1).ToString(),
                    Changed = DateTimeOffset.Now,
                    UserId = user.DisplayName,
                    Ticket = db.Tickets.Find(ticketId),
                    User = user
                };

                var assignedUser = ticket.AssignedToUser;

                var notification = assignedUser != null ? new IdentityMessage()
                    {
                        Subject = "A comment has been made on a ticket you're assigned to.",
                        Destination = assignedUser.Email,
                        Body = user.DisplayName + " left the following comment on your ticket titled '" + ticket.Title + "': <br /><br />" + ticketComment.Comment
                    } : null;

                if (notification != null) 
                { 
                    var mailer = new EmailService();
                    mailer.SendAsync(notification);
                    notificationChecker = true;
                }
                
                ticketComment.UserId = User.Identity.GetUserId();
                ticketComment.Created = DateTimeOffset.Now;
                db.TicketComments.Add(ticketComment);
                db.TicketHistories.Add(commentHistory);

                if (notificationChecker)
                {
                    var notificationHistory = new TicketHistory()
                    {
                        TicketId = ticketId,
                        Property = "Notifications",
                        PropertyDisplay = "Notification",
                        OldValue = ticket.Notifications.Count().ToString(),
                        OldValueDisplay = ticket.Notifications.Count().ToString(),
                        NewValue = (ticket.Notifications.Count() + 1).ToString(),
                        NewValueDisplay = (ticket.Notifications.Count() + 1).ToString(),
                        Changed = DateTimeOffset.Now,
                        UserId = user.DisplayName,
                        Ticket = db.Tickets.Find(ticketId),
                        User = user
                    };
                    db.TicketHistories.Add(notificationHistory);
                }

                db.SaveChanges();
                return RedirectToAction("Details", new { id = ticketId });
            }
            return View(ticketComment);
        }
 private void CreateHist(int newTicketId, string property, string oldValue, string newValue)
 {
     var tHist = new TicketHistory();
     tHist.TicketId = newTicketId;
     tHist.Property = property;
     tHist.OldValue = oldValue;
     tHist.NewValue = newValue;
     tHist.Changed = DateTimeOffset.UtcNow;
     tHist.UserId = User.Identity.GetUserId();
     db.Entry(tHist).State = EntityState.Added;
     db.SaveChanges();
     return;
 }
        // TicketHistoryHelper is only for Changes to Tickets Edit, not for New Tickets Created

        public TicketHistory FindTicketChanges(Ticket newticket)
        {
            TicketHistory tickethistory = new TicketHistory();

            var myTicketChanged = false;
            var oldticket       = db.Tickets.Find(newticket.Id);

            tickethistory.TicketId = newticket.Id;
            tickethistory.Changed  = DateTime.Now;

            if (newticket.Title != oldticket.Title)
            {
                myTicketChanged        = true;
                tickethistory.Property = "Title";
                tickethistory.OldValue = oldticket.Title;
                tickethistory.NewValue = newticket.Title;
            }

            if (newticket.Description != oldticket.Description)
            {
                myTicketChanged        = true;
                tickethistory.Property = "Description";
                tickethistory.OldValue = oldticket.Description;
                tickethistory.NewValue = newticket.Description;
            }

            if (newticket.ProjectId != oldticket.ProjectId)
            {
                myTicketChanged        = true;
                tickethistory.Property = "Project";
                tickethistory.OldValue = oldticket.Project.Name;
                tickethistory.NewValue = newticket.Project.Name;
                //tickethistory.NewValue = newticket.ProjectId.ToString();
            }

            if (newticket.TicketTypeId != oldticket.TicketTypeId)
            {
                myTicketChanged        = true;
                tickethistory.Property = "Ticket Type";
                tickethistory.OldValue = oldticket.TicketType.Name;
                //tickethistory.NewValue = newticket.TicketType.Name;
                //tickethistory.NewValue = newticket.TicketTypeId.ToString();
                var ticketType = db.TicketTypes.Find(newticket.TicketTypeId);
                tickethistory.NewValue = ticketType.Name;
            }

            if (newticket.TicketPriorityId != oldticket.TicketPriorityId)
            {
                myTicketChanged        = true;
                tickethistory.Property = "Ticket Priority";
                tickethistory.OldValue = oldticket.TicketPriority.Name;
                //tickethistory.NewValue = newticket.TicketPriority.Name;
                //tickethistory.NewValue = newticket.TicketPriorityId.ToString();
                var ticketPriority = db.TicketPriorities.Find(newticket.TicketPriorityId);
                tickethistory.NewValue = ticketPriority.Name;
            }

            if (newticket.TicketStatusId != oldticket.TicketStatusId)
            {
                myTicketChanged        = true;
                tickethistory.Property = "Ticket Status";
                tickethistory.OldValue = oldticket.TicketStatus.Name;
                //tickethistory.NewValue = newticket.TicketStatus.Name;
                //tickethistory.NewValue = newticket.TicketStatusId.ToString();
                var ticketStatus = db.TicketStatuses.Find(newticket.TicketStatusId);
                tickethistory.NewValue = ticketStatus.Name;
            }

            if (newticket.OwnerUserId != oldticket.OwnerUserId)
            {
                myTicketChanged        = true;
                tickethistory.Property = "Owner User";
                tickethistory.OldValue = oldticket.OwnerUser.DisplayName;
                tickethistory.NewValue = newticket.OwnerUser.DisplayName;
                //tickethistory.NewValue = newticket.OwnerUserId;
            }

            if (newticket.AssignedToUserId != oldticket.AssignedToUserId)
            {
                myTicketChanged        = true;
                tickethistory.Property = "AssignedTo User";
                tickethistory.NewValue = newticket.AssignedToUser.DisplayName;
                if (oldticket.AssignedToUserId == null)
                {
                    tickethistory.OldValue = "Unassigned-To User";
                }
                else
                {
                    tickethistory.OldValue = oldticket.AssignedToUser.DisplayName;
                }
            }

            if (myTicketChanged == false)
            {
                // No changes were made - Set tickethistory so
                tickethistory.Property = "No changes made";
                tickethistory.OldValue = "None";
                tickethistory.NewValue = "None";
            }
            return(tickethistory);
        }
Example #8
0
        public void CreateHistory(Tickets oldTicket, Tickets newTicket, string userId, string userName)
        {
            if (oldTicket.TicketTypeId != newTicket.TicketTypeId)
            {
                TicketHistory history = new TicketHistory();
                history.TicketId = newTicket.Id;
                history.UserId = userId;
                history.UserName = userName;
                history.ChangedDate = System.DateTimeOffset.Now;
                history.OldValue = oldTicket.TicketType.TicketName;
                history.NewValue = getTicketName(newTicket.TicketTypeId);
                history.Property = "Ticket Type";
                db.TicketHistory.Add(history);

                // Notification
                string notiReci = getAssignedUserEmail(newTicket.AssignedToUserId);
                string notiMessage = "Hello " + notiReci + ". Ticket Type has been changed for the following ticket <U>" + newTicket.Id + "</U>";
                InitializeNoti(newTicket.Id, userId, notiReci, notiMessage);

                // SignalR
                var srUser = db.Users.Find(newTicket.AssignedToUserId);
                sr.SendNotifications(srUser.UserName, "Ticket Type Changed For Ticket Id : " + newTicket.Id + ".");
            }
            if (oldTicket.TicketStatusId != newTicket.TicketStatusId)
            {
                TicketHistory history1 = new TicketHistory();
                history1.TicketId = newTicket.Id;
                history1.UserId = userId;
                history1.UserName = userName;
                history1.ChangedDate = System.DateTimeOffset.Now;
                history1.OldValue = oldTicket.TicketStatus.StatusName;
                history1.NewValue = getStatusName(newTicket.TicketStatusId);
                history1.Property = "Ticket Status";
                db.TicketHistory.Add(history1);

                // Notification

                String notiReci = getAssignedUserEmail(newTicket.AssignedToUserId);
                string notiMessage = "Hello " + notiReci + ". Ticket Status has been changed for the following ticket <U>" + newTicket.Id +
                    "</U>";
                InitializeNoti(newTicket.Id, userId, notiReci, notiMessage);

                // SignalR
                var srUser = db.Users.Find(newTicket.AssignedToUserId);
                sr.SendNotifications(srUser.UserName, "Ticket Status Changed For Ticket Id : " + newTicket.Id + ".");

            }
            if (oldTicket.TicketPriorityId != newTicket.TicketPriorityId)
            {
                TicketHistory history2 = new TicketHistory();
                history2.TicketId = newTicket.Id;
                history2.UserId = userId;
                history2.UserName = userName;
                history2.ChangedDate = System.DateTimeOffset.Now;
                history2.OldValue = oldTicket.TicketPriority.PriorityName;
                history2.NewValue = getPriorityName(newTicket.TicketPriorityId);
                history2.Property = "Ticket Priority";
                db.TicketHistory.Add(history2);

                // Notification
                string notiReci = getAssignedUserEmail(newTicket.AssignedToUserId);
                string notiMessage = "Hello " + notiReci + ". Ticket Priority has been changed for the following ticket <U>" + newTicket.Id +
                    "</U>";
                InitializeNoti(newTicket.Id, userId, notiReci, notiMessage);

                // SignalR
                var srUser = db.Users.Find(newTicket.AssignedToUserId);
                sr.SendNotifications(srUser.UserName, "Ticket Priority Changed For Ticket Id : " + newTicket.Id + ".");
            }
            if (oldTicket.AssignedToUserId != newTicket.AssignedToUserId)
            {
                //string empt = "";

                TicketHistory history3 = new TicketHistory();
                history3.TicketId = newTicket.Id;
                history3.UserId = userId;
                history3.UserName = userName;
                history3.ChangedDate = System.DateTimeOffset.Now;

                if(oldTicket.AssignedToUserId == null)
                {
                    history3.OldValue = "Unassigned";
                }
                else
                {
                    history3.OldValue = oldTicket.AssignedToUser.FirstName;
                }
                history3.NewValue = getAssignedUser(newTicket.AssignedToUserId);
                history3.Property = "Assigned To";
                db.TicketHistory.Add(history3);

                //Notification
                string notiReci = getAssignedUserEmail(newTicket.AssignedToUserId);
                string notiMessage = "Hello " + notiReci + ". You have been assigned the following ticket <U>" + newTicket.Id + "</U>";
                InitializeNoti(newTicket.Id,userId,notiReci,notiMessage);

                // SignalR
                var srUser = db.Users.Find(newTicket.AssignedToUserId);
                sr.SendNotifications(srUser.UserName, "You Have Been  Assigned A New Ticket : " + newTicket.Id + ".");
            }
            db.SaveChanges();
        }