public ActionResult EditUserProject(int projectId) { var project = db.Projects.Find(projectId); UserProjectModel projectModel = new UserProjectModel(); // Creating an object of helper class UserProjectHelpers helper = new UserProjectHelpers(); // Calling Helper Method var selected = helper.ListOfUsers(projectId).Select(l=>l.Id); // Only Developers will be displayed for the Project Manager. var userRole = roleHelpers.UsersInRole("Developer"); if (User.IsInRole("Admin")) { projectModel.ApplicationUser = new MultiSelectList(db.Users, "Id", "FirstName", selected); } if (User.IsInRole("ProjectManager")) { projectModel.ApplicationUser = new MultiSelectList(userRole, "Id", "FirstName", selected); } projectModel.Project = project; return View(projectModel); }
// GET: Tickets/Edit/5 public ActionResult Edit(int? id) { UserRoleHelpers roleHelpers = new UserRoleHelpers(); UserProjectHelpers helper = new UserProjectHelpers(); if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Tickets tickets = db.Tickets.Find(id); if (tickets == null) { return HttpNotFound(); } var projId = db.Projects.Find(tickets.ProjectId); var projUsers = projId.Users.ToList(); var resultList = new List<ApplicationUser>(); foreach (var user in projUsers) { if (roleHelpers.IsUserInRole(user.Id,"Developer")) { resultList.Add(user); } } ViewBag.AssignedToUserId = new SelectList(resultList, "Id", "FirstName", tickets.AssignedToUserId); ViewBag.TicketStatusId = new SelectList(db.TicketStatus, "Id", "StatusName", tickets.TicketStatusId); ViewBag.TicketTypeId = new SelectList(db.TicketType, "Id", "TicketName", tickets.TicketTypeId); ViewBag.TicketPriorityId = new SelectList(db.TicketPriority, "Id", "PriorityName", tickets.TicketPriorityId); return View(tickets); }
public ActionResult EditUserProject(int projectId, UserProjectModel projectModel) { UserProjectHelpers helper = new UserProjectHelpers(); if (ModelState.IsValid) { string[] empt = { }; projectModel.SelectedUsers = projectModel.SelectedUsers ?? empt; foreach (var user in db.Users) { if (projectModel.SelectedUsers.Contains(user.Id)) { helper.AddUserToProject(projectId, user.Id); } //If not selected remove else { helper.RemoveUserFromProject(projectId, user.Id); } } // Hema if(User.IsInRole("ProjectManager")) { var user = db.Users.Find(User.Identity.GetUserId()); helper.AddUserToProject(projectId, user.Id); } } return RedirectToAction("ProjectList"); }