コード例 #1
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Description,TicketTypeId,TicketPriorityId,TicketStatusId,AssignedToUserId")] Ticket ticket, string developer)
        {
            var allDevelopers = rolesHelper.UsersInRole("Developer");

            if (ModelState.IsValid)
            {
                var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticket.Id);
                var newTicket = db.Tickets.Find(ticket.Id);
                newTicket.AssignedToUserId = developer;
                newTicket.TicketTypeId     = ticket.TicketTypeId;
                newTicket.TicketPriorityId = ticket.TicketPriorityId;
                newTicket.TicketStatusId   = ticket.TicketStatusId;
                newTicket.Description      = ticket.Description;
                newTicket.Updated          = DateTime.Now;
                db.SaveChanges();
                projectHelper.AddUserToProject(newTicket.AssignedToUserId, newTicket.ProjectId);
                ticketHelper.CreateChangeNotification(oldTicket, newTicket);
                ticketHelper.CreateHistoryRecord(oldTicket, newTicket);
                await ticketHelper.CreateAssignmentNotification(oldTicket, newTicket);

                return(RedirectToAction("Details", "Tickets", new { Id = ticket.Id }));
            }
            ViewBag.Developers       = new SelectList(allDevelopers, "Id", "FullName", ticket.AssignedToUserId);
            ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", ticket.TicketPriorityId);
            ViewBag.TicketStatusId   = new SelectList(db.TicketStatuses, "Id", "Name", ticket.TicketStatusId);
            ViewBag.TicketTypeId     = new SelectList(db.TicketTypes, "Id", "Name", ticket.TicketTypeId);
            return(View(ticket));
        }