Ejemplo n.º 1
0
        public ActionResult Edit([Bind(Include = "Id,Title,Description,Created,Updated,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusid,OwnerUserId,AssignToUserId")] Ticket ticket)
        {
            ViewBag.UserTimeZone     = db.Users.Find(User.Identity.GetUserId()).TimeZone;
            ViewBag.AssignToUserId   = new SelectList(db.Users, "Id", "FirstName", ticket.AssignToUserId);
            ViewBag.OwnerUserId      = new SelectList(db.Users, "Id", "FirstName", ticket.OwnerUserId);
            ViewBag.ProjectId        = new SelectList(db.Projects, "Id", "Title", ticket.ProjectId);
            ViewBag.TicketPriorityId = new SelectList(db.TicketPrioritites, "Id", "Name", ticket.TicketPriorityId);
            ViewBag.TicketStatusid   = new SelectList(db.TicketStatuses, "Id", "Name", ticket.TicketStatusid);
            ViewBag.TicketTypeId     = new SelectList(db.TicketTypes, "Id", "Name", ticket.TicketTypeId);
            var user = db.Users.Find(User.Identity.GetUserId());

            if (ModelState.IsValid)
            {
                ticket.Updated = DateTimeOffset.UtcNow;
                HistoryHelper helper = new HistoryHelper();

                TicketHistory ticketHistory = new TicketHistory();
                Ticket        oldTicket     = db.Tickets.AsNoTracking().First(t => t.Id == ticket.Id);
                if (oldTicket.Title != ticket.Title)
                {
                    helper.AssignTicketTitle(ticket, user.Id);
                }
                if (oldTicket.Description != ticket.Description)
                {
                    helper.AssignTicketDescription(ticket, user.Id);
                }
                if (oldTicket.TicketPriorityId != ticket.TicketPriorityId)
                {
                    helper.AssignTicketPriority(ticket, user.Id);
                }
                if (oldTicket.TicketStatusid != ticket.TicketStatusid)
                {
                    helper.AssignTicketStatus(ticket, user.Id);
                }
                if (oldTicket.TicketTypeId != ticket.TicketTypeId)
                {
                    helper.AssignTickettype(ticket, user.Id);
                }

                if (ticket.TicketStatusid == 1)
                {
                    ticket.Archive = true;
                }



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



                return(RedirectToAction("Details", new { id = ticket.Id }));
            }

            return(View(ticket));
        }