public ActionResult ADEdit([Bind(Include = "Id,Title,Description,Updated,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,AssignedToUserId")] Tickets tickets)
        {
            if (ModelState.IsValid)
            {
                var changes  = new List <TickectsHistory>();
                var MyTicket = db.Tickets.First(p => p.Id == tickets.Id);
                MyTicket.Id               = tickets.Id;
                MyTicket.Title            = tickets.Title;
                MyTicket.Description      = tickets.Description;
                MyTicket.Updated          = DateTimeOffset.Now;
                MyTicket.TicketTypeId     = tickets.TicketTypeId;
                MyTicket.TicketPriorityId = tickets.TicketPriorityId;
                MyTicket.TicketStatusId   = tickets.TicketStatusId;
                MyTicket.ProjectId        = tickets.ProjectId;

                var originalValues = db.Entry(MyTicket).OriginalValues;
                var currentValues  = db.Entry(MyTicket).CurrentValues;

                foreach (var property in originalValues.PropertyNames)
                {
                    var originalValue = originalValues[property]?.ToString();
                    var currentValue  = currentValues[property]?.ToString();

                    if (originalValue != currentValue)
                    {
                        var history = new TickectsHistory();
                        history.Changed   = DateTimeOffset.Now;
                        history.NewValue  = GetValueFromKey(property, currentValue);
                        history.OldValue  = GetValueFromKey(property, originalValue);
                        history.Property  = property;
                        history.TicketsId = MyTicket.Id;
                        history.UsersId   = User.Identity.GetUserId();
                        changes.Add(history);
                    }
                }
                db.TickectsHistories.AddRange(changes);

                db.SaveChanges();
                var devId = db.Roles.Where(p => p.Name == "Developer").Select(p => p.Id).FirstOrDefault();
                if (MyTicket.AssignedToUser.Roles.Any(p => p.RoleId == devId))
                {
                    var personalEmailService = new PersonalEmailService();

                    var mailMessage = new MailMessage(
                        WebConfigurationManager.AppSettings["emailto"], MyTicket.AssignedToUser.Email

                        );
                    mailMessage.Body       = "Your ticket has changed, please confirm it as soon as possible";
                    mailMessage.Subject    = "Ticket status changed";
                    mailMessage.IsBodyHtml = true;
                    personalEmailService.Send(mailMessage);
                }
                return(RedirectToAction("AdminIndex"));
            }
            ViewBag.ProjectId        = new SelectList(db.Projects, "Id", "Name", tickets.Id);
            ViewBag.TicketPriorityId = new SelectList(db.TicketPriority, "Id", "Name", tickets.TicketPriorityId);
            ViewBag.TicketStatusId   = new SelectList(db.TicketStatus, "Id", "Name", tickets.TicketStatusId);
            ViewBag.TicketTypeId     = new SelectList(db.TicketType, "Id", "Name", tickets.TicketTypeId);
            return(View("Edit", tickets));
        }
        public ActionResult SBEdit([Bind(Include = "Id,Title,Description,Updated")] Tickets tickets)
        {
            if (ModelState.IsValid)
            {
                var changes  = new List <TickectsHistory>();
                var MyTicket = db.Tickets.First(p => p.Id == tickets.Id);
                MyTicket.Id          = tickets.Id;
                MyTicket.Title       = tickets.Title;
                MyTicket.Description = tickets.Description;
                MyTicket.Updated     = DateTimeOffset.Now;

                var originalValues = db.Entry(MyTicket).OriginalValues;
                var currentValues  = db.Entry(MyTicket).CurrentValues;

                foreach (var property in originalValues.PropertyNames)
                {
                    var originalValue = originalValues[property]?.ToString();
                    var currentValue  = currentValues[property]?.ToString();

                    if (originalValue != currentValue)
                    {
                        var history = new TickectsHistory();
                        history.Changed   = DateTimeOffset.Now;
                        history.NewValue  = GetValueFromKey(property, currentValue);
                        history.OldValue  = GetValueFromKey(property, originalValue);
                        history.Property  = property;
                        history.TicketsId = MyTicket.Id;
                        history.UsersId   = User.Identity.GetUserId();
                        changes.Add(history);
                    }
                }
                db.TickectsHistories.AddRange(changes);

                db.SaveChanges();
                return(RedirectToAction("SubmitterIndex"));
            }
            return(View(tickets));
        }