public ActionResult Create() { var user = db.Users.Find(User.Identity.GetUserId()); var userTickets = ticketHelper.MyProjectTickets(user.Id).Where(t => t.Archived == false).ToList(); var userProjects = projectHelper.ListUserProjects(user.Id).Where(t => t.Archived == false).ToList(); var adminUsers = userRolesHelper.UsersInRole("Admin"); var usersOnProjects = new List <ApplicationUser>(); var tempUsers = new List <ApplicationUser>(); if (User.IsInRole("Admin")) { ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title"); ViewBag.UserId = new SelectList(db.Users, "Id", "DisplayName"); } else { foreach (var project in userProjects) { foreach (var currentUser in project.ProjectUsers) { tempUsers.Add(currentUser); } } foreach (var admin in adminUsers) { tempUsers.Add(admin); } usersOnProjects = tempUsers.Distinct().ToList(); //ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title"); ViewBag.TicketId = new SelectList(userTickets, "Id", "Title"); //ViewBag.UserId = new SelectList(db.Users, "Id", "DisplayName"); ViewBag.UserId = new SelectList(usersOnProjects, "Id", "DisplayName"); } return(View()); }
public ActionResult UserIndex() { var ticketList = new List <Ticket>(); var user = db.Users.Find(User.Identity.GetUserId()); if (User.IsInRole("Project Manager")) { ticketList = ticketsHelper.MyProjectTickets(user.Id).ToList(); } if (User.IsInRole("Developer")) { ticketList = db.Tickets.Where(t => t.AssignedToUserId == user.Id).ToList(); } if (User.IsInRole("Submitter")) { ticketList = ticketsHelper.OwnedTickets(user.Id).ToList(); } ViewBag.UserIndexFlag = true; ViewBag.UserId = user.Id; return(View("Index", ticketList)); }