Esempio n. 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 sub = rHelp.IsUserInRole(User.Identity.GetUserId(), "Submitter") || rHelp.IsUserInRole(User.Identity.GetUserId(), "DemoSubmitter");

            if (sub)
            {
                if (ticket.SubmitterId != User.Identity.GetUserId())
                {
                    return(View("Error"));
                }
            }
            var dev = rHelp.IsUserInRole(User.Identity.GetUserId(), "Developer") || rHelp.IsUserInRole(User.Identity.GetUserId(), "DemoDeveloper");

            if (dev)
            {
                if (ticket.DeveloperId != User.Identity.GetUserId())
                {
                    return(View("Error"));
                }
            }
            //db.Projects.Find(ticketid)
            var pm = rHelp.IsUserInRole(User.Identity.GetUserId(), "Project_Manager") || rHelp.IsUserInRole(User.Identity.GetUserId(), "DemoProject_Manager");

            if (pm)
            {
                if (!pHelp.IsUserOnProject(User.Identity.GetUserId(), ticket.ProjectId))
                {
                    return(View("Error"));
                }
            }

            //var pj = db.Projects.Where(p => p.Id == ticket.ProjectId).FirstOrDefault();
            var pj  = db.Projects.FirstOrDefault(p => p.Id == ticket.ProjectId);
            var meh = pHelp.ListUsersOnProjectIn2RolesMKII(pj.Id, "Developer", "DemoDeveloper");

            ViewBag.DeveloperId = new SelectList(pHelp.ListUsersOnProjectIn2RolesMKII(pj.Id, "Developer", "DemoDeveloper"), "Id", "FullName", ticket.DeveloperId);
            //ViewBag.DeveloperId = new SelectList(rHelp.UsersIn2Roles("Developer", "DemoDeveloper"), "Id", "FullName", ticket.DeveloperId);
            //ViewBag.DeveloperId = new SelectList(db.Users, "Id", "FullName", ticket.DeveloperId);
            ViewBag.ProjectId        = new SelectList(db.Projects, "Id", "Name", ticket.ProjectId);
            ViewBag.SubmitterId      = new SelectList(rHelp.UsersIn2Roles("Submitter", "DemoSubmitter"), "Id", "FullName", ticket.SubmitterId);
            ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "PriorityName", ticket.TicketPriorityId);
            ViewBag.TicketStatusId   = new SelectList(db.TicketStatuses, "Id", "StatusName", ticket.TicketStatusId);
            ViewBag.TicketTypeId     = new SelectList(db.TicketTypes, "Id", "TypeName", ticket.TicketTypeId);

            return(View(ticket));
        }