Exemplo n.º 1
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Project project = db.Projects.Find(id);
            var     ticket  = db.Tickets.Where(t => t.ProjectId == project.Id).ToList();

            if (project == null)
            {
                return(View("Error"));
            }
            var pm = rHelp.IsUserInRole(User.Identity.GetUserId(), "Project_Manager") || rHelp.IsUserInRole(User.Identity.GetUserId(), "DemoProject_Manager");

            if (pm)
            {
                if (!pHelp.IsUserOnProject(User.Identity.GetUserId(), project.Id))
                {
                    return(View("Error"));
                }
            }
            var dev = rHelp.IsUserInRole(User.Identity.GetUserId(), "Developer") || rHelp.IsUserInRole(User.Identity.GetUserId(), "DemoDeveloper");

            if (dev)
            {
                if (!pHelp.IsUserOnProject(User.Identity.GetUserId(), project.Id))
                {
                    return(View("Error"));
                }
            }
            var sub = rHelp.IsUserInRole(User.Identity.GetUserId(), "Submitter") || rHelp.IsUserInRole(User.Identity.GetUserId(), "DemoSubmitter");

            if (sub)
            {
                if (!pHelp.IsUserOnProject(User.Identity.GetUserId(), project.Id))
                {
                    return(View("Error"));
                }
            }

            ViewBag.ProjectId = id;

            var AdminId = db.Users.ToList().Where(u => u.Id == User.Identity.GetUserId());

            if (User.IsInRole("Admin") || User.IsInRole("DemoAdmin"))
            {
                ViewBag.AdminId = new SelectList(AdminId, "Id", "FullName", pHelp.ListUsersOnProjectIn2Roles((int)id, "Admin", "DemoAdmin").FirstOrDefault());
            }
            else
            {
                ViewBag.AdminId = new SelectList(rHelp.UsersIn2Roles("Admin", "DemoAdmin"), "Id", "FullName", pHelp.ListUsersOnProjectIn2Roles((int)id, "Admin", "DemoAdmin").FirstOrDefault());
            }
            ViewBag.ProjectManagerId = new SelectList(rHelp.UsersIn2Roles("Project_Manager", "DemoProject_Manager"), "Id", "FullName", pHelp.ListUsersOnProjectIn2Roles((int)id, "Project_Manager", "DemoProject_Manager").FirstOrDefault());
            ViewBag.Developers       = new MultiSelectList(rHelp.UsersIn2Roles("Developer", "DemoDeveloper"), "Id", "FullName", pHelp.ListUsersOnProjectIn2Roles((int)id, "Developer", "DemoDeveloper"));
            ViewBag.Submitters       = new MultiSelectList(rHelp.UsersIn2Roles("Submitter", "DemoSubmitter"), "Id", "FullName", pHelp.ListUsersOnProjectIn2Roles((int)id, "Submitter", "DemoSubmitter"));
            var meh = new ProjectDetailsViewModel();

            meh.Projects   = project;
            meh.TicketList = ticket;
            return(View(meh));
        }