// GET: /Projects/AddUsers public ActionResult AddUsers(int projectID) { // check your inputs if (projectID == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // We are ADDING users NOT already in the project, so find user not in project. //var usersNotInProj = db.Users // .Include(u => u.Projects) // .Where(u => !u.Projects.Any(p => p.ID == projectID)); // much cleaner ways of selecting users in a project. var usersInProj = db.Projects.Find(projectID).Users.Select(u => u.ID); var usersNotInProj = db.Users.Where(u => !usersInProj.Contains(u.ID)).Select(u => new { u.ID, u.ASPUserName }); // build VM ProjectUserViewModel model = new ProjectUserViewModel { ID = projectID, ProjectName = db.Projects.Find(projectID).ProjectName, Users = new MultiSelectList(usersNotInProj, "ID", "ASPUserName") }; // return list. return(View(model)); }
public ActionResult Edit(int?projectId) { if (projectId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var projectModel = new ProjectUserViewModel(); Project project = db.Projects.Find(projectId); var helper = new ProjectUserHelper(); // make sure project exists if (project != null) { projectModel.ProjectId = project.Id; projectModel.ProjectName = project.Name; //get the user Ids that are associated with the project var userIdList = helper.UsersInProject((int)projectId); var userInfoList = helper.getUserInfo(userIdList); projectModel.UsersAssignedtoProject = new MultiSelectList(userInfoList, "UserId", "UserName"); //get the user Ids not associated with the project var nonUserIdList = helper.UsersNotInProject((int)projectId); var nonUserInfoList = helper.getUserInfo(nonUserIdList); projectModel.UsersNotAssignedToProject = new MultiSelectList(nonUserInfoList, "UserId", "UserName"); return(View(projectModel)); } else { return(HttpNotFound()); } }
public ActionResult RemoveUsers([Bind(Include = "ID,SelectedUsers")] ProjectUserViewModel projectUserVM) { // check your inputs if (ModelState.IsValid) { // add each selected user to the project //var proj = db.Projects.Where(p => p.ID == projectVM.ID).ToList(); var proj = new Project { ID = projectUserVM.ID }; db.Projects.Attach(proj); foreach (int userName in projectUserVM.SelectedUsers) { // get User, add current project, save changes. var user = db.Users.Include(u => u.Projects).Single(u => u.ID == userName); // add the project to the user. user.Projects.Remove(proj); // save changes db.SaveChanges(); } // return to Project Index return(RedirectToAction("Index")); } // ViewModel was messed up, need to return with error message. return(View("Error")); }
private bool DoUpdateProjectUser(ProjectUserViewModel model) { var svc = new ProjectUserAppSvcGeneric(); var updated = svc.Update(model.GetEntity()); return(updated != null); }
//GET: Projects/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var project = db.Projects.Find(id); if (project == null) { return(HttpNotFound()); } if (User.IsInRole("Admin") || User.IsInRole("ProjectManager") || project.Users.Any(u => u.Id == User.Identity.GetUserId())) { ProjectUserViewModel projectUserVM = new ProjectUserViewModel(); projectUserVM.Project = project; projectUserVM.ProjectId = project.Id; projectUserVM.ProjectOwner = db.Users.Find(project.AuthorId).FullName; projectUserVM.AssignedUsersList = project.Users.ToList(); //projectUserVM.AssignedUsers = project.Users.Select(u => u.Id).ToArray(); //Sends the assigned Users' Ids to an array //projectUserVM.Users = new MultiSelectList(db.Users.ToList(), "Id", "FullName", projectUserVM.AssignedUsers); // Verifying that the current user is involved with this project return(View(projectUserVM)); } else { return(RedirectToAction("Index", "Home")); } }
private bool DoCreateProjectUser(ProjectUserViewModel model) { var svc = new ProjectUserAppSvcGeneric(); var created = svc.Create(model.GetEntity()); return(created.Id > 0); }
public ActionResult ShowAddProjectUserPopup(int projectId) { var model = new ProjectUserViewModel { ProjectId = projectId }; return(PartialView("_AddProjectUser", model)); }
public ActionResult SaveProjectUser(ProjectUserViewModel model) { if (!model.IsEdit) { return(CreateProjectUserAction(model)); } return(EditProjectUserAction(model)); }
public ActionResult AddUserToProject(string userId, int projectId, ProjectUserViewModel projectUser) { ViewBag.UserId = new SelectList(_userBL.GetAllUsers(), "Id", "UserName"); ViewBag.ProjectId = new SelectList(_pBL.GetAllProjects(), "Id", "Name"); _userBL.AddAProjectManagerToAProject(projectId, userId); return(View(projectUser)); }
public ActionResult New(int?id) { var viewModelParaPagina = new ProjectUserViewModel(); if (id.HasValue) { viewModelParaPagina = new ProjectUserViewModel(id.Value); } return(View("ProjectUserControl", viewModelParaPagina)); }
public ActionResult AddUserToProject() { var projectUser = new ProjectUserViewModel(); projectUser.Users = _userBL.GetAllUsers().ToList(); projectUser.Projects = db.Projects; ViewBag.UserId = new SelectList(projectUser.Users, "Id", "UserName"); ViewBag.ProjectId = new SelectList(projectUser.Projects, "Id", "Name"); return(View(projectUser)); }
private ActionResult CreateProjectUserAction(ProjectUserViewModel model) { var createResult = DoCreateProjectUser(model); if (createResult) { return(RedirectToAction("List")); } ViewBag.ErrorMessage = "Erro ao Criar o Projeto"; return(View("ProjectUserControl", model)); }
public ActionResult ProjectUser(int id) { var project = db.Projects.Find(id); ProjectUserViewModel projectUserVM = new ProjectUserViewModel(); projectUserVM.Project = project; projectUserVM.ProjectId = project.Id; projectUserVM.AssignedUsers = project.Users.Select(u => u.Id).ToArray(); //Sends the assigned Users' Ids to an array projectUserVM.Users = new MultiSelectList(db.Users.ToList(), "Id", "FullName", projectUserVM.AssignedUsers); return(View(projectUserVM)); }
private ActionResult EditProjectUserAction(ProjectUserViewModel model) { var updateResult = DoUpdateProjectUser(model); if (updateResult) { return(RedirectToAction("List")); } ViewBag.ErrorMessage = "Erro ao Editar o projeto"; return(View("ProjectUserControl", model)); }
public ActionResult ProjectUser(int id) { var project = db.Projects.Find(id); ProjectUserViewModel projectuserVM = new ProjectUserViewModel(); projectuserVM.AssignProject = project; projectuserVM.AssignProjectId = id; projectuserVM.SelectedUsers = project.Users.Select(u => u.Id).ToArray(); projectuserVM.Users = new MultiSelectList(db.Users.ToList(), "Id", "FullName", projectuserVM.SelectedUsers); //can call FullName if prefer return(View(projectuserVM)); }
//GET: assign users to projects public ActionResult AssignUsers(int Id) { var project = db.Project.Find(Id); ProjectUserViewModel ViewModel = new ProjectUserViewModel(); UserProjectsHelper helper = new UserProjectsHelper(); var user = new ApplicationUser(); var selected = helper.ListProjectUsers(Id).Select(a => a.Id).ToArray(); ViewModel.Users = new MultiSelectList(db.Users, "Id", "DisplayName", selected); ViewModel.Project = project; return(View(ViewModel)); }
public ActionResult ProjectUser(ProjectUserViewModel model) { ProjectAssignHelper helper = new ProjectAssignHelper(); foreach (var userId in db.Users.Select(r => r.Id).ToList()) { helper.RemoveUserFromProject(userId, model.ProjectId); } foreach (var userId in model.AssignedUsers) { helper.AddUserToProject(userId, model.ProjectId); } return(RedirectToAction("Index", "Home")); }
public ActionResult CreateProjectUser(ProjectUserViewModel model) { UserBL userBL = new UserBL(); OperationDetails operationDetails; UserModel user = userBL.GetUserByPfid(model.Pfid); if (user != null) { if (user.RoleId == (int)EnumHelper.Role.SuperAdmin) { return(Json(new { success = false, message = "Cannot assign project to admin user." }, JsonRequestBehavior.AllowGet)); } } else { // If user not found in User table, get user from HRMS service. user = userBL.GetUserFromService(model.Pfid); if (user == null) { return(Json(new { success = false, message = "Employee with this PFID does not exist." }, JsonRequestBehavior.AllowGet)); } user.CreatedBy = CurrentUser.Pfid; operationDetails = userBL.AddUser(user); if (operationDetails.OperationStatus != 1) { return(Json(new { success = false, message = "Something went wrong!!" }, JsonRequestBehavior.AllowGet)); } } ProjectMappingModel projectMapping = new ProjectMappingModel(); projectMapping.Pfid = model.Pfid; projectMapping.ProjectId = model.ProjectId; projectMapping.IsProjectAdmin = model.IsAdmin ? 1 : 0; projectMapping.CreatedBy = CurrentUser.Pfid; operationDetails = userBL.AddProjectMapping(projectMapping); if (operationDetails.OperationStatus == 1) { return(Json(new { success = true, message = "User added to project successfully." }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false, message = "Something went wrong!!" }, JsonRequestBehavior.AllowGet)); }
public ActionResult AssignUsers(int id) { Project project = db.Projects.Find(id); ProjectAssignHelper helper = new ProjectAssignHelper(); var projectUser = new ProjectUserViewModel(); projectUser.Project = project; projectUser.Id = project.Id; projectUser.Name = project.Name; projectUser.Users = db.Users.ToList(); projectUser.SelectedUsers = helper.ListProjectUsers(projectUser.Id).Select(p => p.Id).ToArray(); projectUser.ProjectUsers = new MultiSelectList(db.Users, "Id", "LastName", projectUser.SelectedUsers); return(View(projectUser)); }
public ActionResult AssignUsers(ProjectUserViewModel model) { var project = db.Projects.Find(model.Id); foreach (var UserRm in db.Users.Select(r => r.Id).ToList()) { helper.RemoveUserFromProject(UserRm, project.Id); } //foreach (var UserAdd in db.Users.Select(r => r.Id).ToList()) foreach (var UserAdd in model.SelectedUsers) { helper.AddUserToProject(UserAdd, project.Id); } return(RedirectToAction("Details", "Projects", new { id = model.Id })); }
public ActionResult AddProjectUsers(ProjectUserViewModel projectUser) { var user = DbContext.Users.FirstOrDefault( p => p.Id == projectUser.UserID); var project = DbContext.Projects.FirstOrDefault( p => p.ID == projectUser.ID); if (user == null) { return(RedirectToAction(nameof(ManageProjectUsersController.EditProjectUsers))); } user.Projects.Add(project); DbContext.SaveChanges(); return(RedirectToAction("EditProjectUsers", "ManageProjectUsers", new { ID = projectUser.ID })); }
public IActionResult Post(ProjectUserViewModel viewModel) { var user = GetUser(); var project = _projectRepository.FindById(viewModel.ProjectId); if (project == null) { return(BadRequest()); } if (project.UserInProject.Any(x => x.UserModelId == user.Id)) { return(Ok("User exist in project")); } project.UserInProject.Add(new UserInProject { UserModelId = user.Id }); _unitOfWork.SaveChanges(); return(Ok()); }
public List <ProjectUserViewModel> CreateProjectViewModel(List <Project> projects) { var ProjectInfo = new List <ProjectUserViewModel>(); foreach (var project in projects) { var ProjUser = new ProjectUserViewModel(); ProjUser.ProjectId = project.Id; ProjUser.Name = project.Name; ProjUser.Priority = project.Priority; foreach (var user in project.ProjectUsers) { var userToAdd = AdminLogic.GetUserById(user.UserId); ProjUser.UserName.Add(userToAdd.UserName); } ProjectInfo.Add(ProjUser); } return(ProjectInfo); }
public ActionResult AssignUsers(ProjectUserViewModel model) { UserProjectsHelper helper = new UserProjectsHelper(); foreach (var user in model.SelectedUsers) { if (!helper.IsUserOnProject(user, model.Project.Id)) { helper.AddUserToProject(user, model.Project.Id); } } foreach (var user in db.Users.ToList()) { if (!model.SelectedUsers.Contains(user.Id)) { helper.RemoveUserFromProject(user.Id, model.Project.Id); } } db.SaveChanges(); return(RedirectToAction("Index", "Projects", model)); }