public ActionResult EditProject(int id) { var project = _dataManager.FindProjectById(id); if (project == null) { return(HttpNotFound()); } var userId = HttpContext.User.Identity.GetUserId(); var userAccessList = _dataManager.GetUserAccessOnProject(id); bool isOwner = project.OwnerId.Equals(userId); if (!isOwner && !userAccessList.Any(access => access.UserId.Equals(userId))) { //TODO: Update to display error that the user does not have access to the project return(HttpNotFound()); } ProjectCreateOrEditViewModel viewViewModel = new ProjectCreateOrEditViewModel() { Id = project.Id, Name = project.Name }; return(View("AddProject", viewViewModel)); }
public ActionResult SaveProject(ProjectCreateOrEditViewModel project) { if (!ModelState.IsValid) { return(View("AddProject", project)); } ProjectModel projectModel = new ProjectModel() { Id = project.Id, Name = project.Name, OwnerId = project.OwnerId }; if (projectModel.Id == 0) { var userId = HttpContext.User.Identity.GetUserId(); projectModel.OwnerId = userId; var proj = _dataManager.CreateNewProject(projectModel); _dataManager.AddUserAccessToProject( new UserAccessModel() { ProjectId = proj.Id, UserId = userId }); _dataManager.SaveChanges(); } else { _dataManager.UpdateProject(projectModel); _dataManager.SaveChanges(); } return(RedirectToAction("Index", "Projects")); }
public ActionResult NewProject() { ProjectCreateOrEditViewModel viewModel = new ProjectCreateOrEditViewModel(); return(View("AddProject", viewModel)); }