Exemple #1
0
        // GET: Tickets/Edit/5
        public ActionResult Edit(int id)
        {
            Ticket ticket = db.Tickets.Find(id);
            var    userId = User.Identity.GetUserId();
            var    proj   = ticket.ProjectId;

            if (User.IsInRole("Submitter") && userId != ticket.OwnerUserId)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (User.IsInRole("Developer") && userId != ticket.AssignedToUserId)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var isuseronproject = projectHelper.IsUserOnProject(userId, proj);

            if (User.IsInRole("Project Manager") && !isuseronproject)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

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

            var projUsers = projectHelper.UsersOnProject(ticket.ProjectId);
            //var devs = projUsers.Where(B => UserRoleHelper.IsUserInRole(B.Id, "Developer"));

            var devs = projectHelper.UsersOnProjectWithRole("Developer", ticket.ProjectId);

            ViewBag.AssignedToUserId = new SelectList(devs, "Id", "Email", ticket.AssignedToUserId);
            if (User.IsInRole("Submitter"))
            {
                var projId = archivedHelper.GetMyActiveProjects(userId);
                ViewBag.ProjectId = new SelectList(projId, "Id", "Name", ticket.ProjectId);
            }
            else
            {
                var projId = archivedHelper.GetActiveProjects();
                ViewBag.ProjectId = new SelectList(projId, "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);
            return(View(ticket));
        }