public ActionResult Assign([Bind(Include = "Users,projectId")] ProjectAssignViewModel model) { Project project = db.Projects.Find(model.projectId); if (ModelState.IsValid) { foreach (var user in model.Users) { if (!URManager.UserIsInRole(user, "Guest")) { if (!project.Users.Select(u => u.Id).Contains(user)) { PAManager.AddUserToProject(user, project.Id); } } } ViewBag.Message = "Project Assignments have been saved"; return(RedirectToAction("Details", new { id = model.projectId })); } model = new ProjectAssignViewModel(); model.projectId = project.Id; model.UnassignedUserList = db.Users.Where(u => !u.Projects.Select(p => p.Id).Contains(project.Id)).ToList(); return(View(model)); }
public ActionResult AssignUsers(ProjectAssignViewModel model) { //STEP 1: Find the project var project = db.Projects.FirstOrDefault(p => p.Id == model.Id); //STEP 2: Remove all assigned users from this project var assignedUsers = project.Users.ToList(); foreach (var user in assignedUsers) { project.Users.Remove(user); } //STEP 3: Assign users to the project if (model.SelectedUsers != null) { foreach (var userId in model.SelectedUsers) { var user = db.Users.FirstOrDefault(p => p.Id == userId); project.Users.Add(user); } } //STEP 4: Save changes to the database db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult AssignUsers(int id) { var model = new ProjectAssignViewModel(); model.Id = id; var project = db.Projects.FirstOrDefault(p => p.Id == id); var users = db.Users.ToList(); var userIdsAssignedToProject = project.Users.Select(p => p.Id).ToList(); model.UserList = new MultiSelectList(users, "Id", "Name", userIdsAssignedToProject); return(View(model)); }
public ActionResult ProjectAssign(int id) { var model = new ProjectAssignViewModel(); model.Id = id; var project = Context.Projects.FirstOrDefault(p => p.Id == id); var users = Context.Users.ToList(); var userIdsAssignedToProject = project.Users.ToList(); model.Users = users; model.UsersInProject = userIdsAssignedToProject; return(View(model)); }
public ActionResult ProjectAssign(ProjectAssignViewModel model) { if (ModelState.IsValid) { var currentUsers = helper.ListUsersOnAProject((int)model.projectId); foreach (var user in currentUsers) { helper.RemoveUserFromAProject(user.Id, (int)model.projectId); } if (model.selectedvalue.Any()) { foreach (var user in model.selectedvalue) { helper.AddUserToAProject(user, (int)model.projectId); db.SaveChanges(); } } return(RedirectToAction("Index")); } return(View()); }
public ActionResult ProjectAssign(int?Id) { var userId = User.Identity.GetUserId(); var user = db.Users.Find(userId); if (Id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Project project = db.Projects.Find(Id); if (project == null) { return(HttpNotFound()); } if (project.ProjectManagerId == userId || User.IsInRole("Admin") || User.IsInRole("Administrator")) { ProjectAssignViewModel pa = new ProjectAssignViewModel(); pa.projectId = Id; pa.selectedvalue = helper.ListUsersOnAProject((int)Id).Select(u => u.Id).ToArray(); pa.Users = new MultiSelectList(db.Users, "Id", "FirstName", pa.selectedvalue); return(View(pa)); } else { var Temporary = "You must be an Admin or the project manager for this project in order to assign developers."; TempData["message"] = Temporary; return(RedirectToAction("Index", "Projects")); } }
public ActionResult Assign(int?projectId) { if (projectId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Project project = db.Projects.Find(projectId); if (project == null) { return(HttpNotFound()); } var userId = User.Identity.GetUserId(); if (!URManager.UserIsInRole(userId, "Administrator")) { if (userId != project.InChargeOfId) { return(RedirectToAction("Login", "Account")); } } //archive handling if (project.Archived ?? false) { ViewBag.ErrorMessage = ""; return(RedirectToAction("Login", "Account")); } ProjectAssignViewModel model = new ProjectAssignViewModel(); model.projectId = projectId; model.UnassignedUserList = db.Users.Where(u => !u.Projects.Select(p => p.Id).Contains(project.Id)).ToList(); return(View(model)); }