示例#1
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Ticket ticket = _db.Tickets.Find(id);

            if (ticket == null)
            {
                return(HttpNotFound());
            }

            var userId            = User.Identity.GetUserId();
            var userCanEditTicket = _ticketHelper.CanEdit(userId, ticket);

            if (!userCanEditTicket)
            {
                return(RedirectToAction("Dashboard", "Tickets", new { ticket.Id }));
            }

            ViewBag.CanEdit             = userCanEditTicket;
            ViewBag.CanChangeAssignment = _ticketHelper.CanChangeAssignment(userId, ticket);
            ViewBag.CanChangeStatus     = _ticketHelper.CanChangeStatus(userId, ticket);
            ViewBag.CanChangeOwner      = false;

            List <ApplicationUser> developersOnProject = new List <ApplicationUser>();

            List <ApplicationUser> submittersOnProject = new List <ApplicationUser>();

            var project = _db.Projects.Find(ticket.ProjectId);

            if (project != null)
            {
                developersOnProject = _projectHelper.ListUsersOnProjectInRole(project.Id, "Developer");
                developersOnProject.AddRange(_projectHelper.ListUsersOnProjectInRole(project.Id, "DemoDeveloper"));
                submittersOnProject = _projectHelper.ListUsersOnProjectInRole(project.Id, "Submitter");
                submittersOnProject.AddRange(_projectHelper.ListUsersOnProjectInRole(project.Id, "DemoSubmitter"));
            }

            ViewBag.AssignedToId     = new SelectList(developersOnProject, "Id", "DisplayName", ticket.AssignedToId);
            ViewBag.ProjectId        = new SelectList(_db.Projects, "Id", "Name", ticket.ProjectId);
            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);
            ViewBag.Message          = "";
            ViewBag.OwnerId          = new SelectList(submittersOnProject, "Id", "DisplayName", ticket.OwnerId);
            return(View(ticket));
        }