public async Task <IActionResult> EditProjectRoleGroup(ProjectRoleGroup model) { if (ModelState.IsValid) { await _projectRepo.EditProjectRoleGroupAsync(model); return(RedirectToAction(nameof(ViewProjectRoleGroups))); } return(View(model)); }
public ActionResult Edit(int?id) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.ProjectRoleGroup)) { return(RedirectToPermissionDenied()); } // Check if a project role group ID was provided if (id == null) { return(RedirectToIndex()); } int projectRoleGroupId = (int)id; // Entry try-catch from here // Make sure any errors are displayed try { // Get the project role group data var projectRoleGroupModel = ProjectRoleGroupProcessor.GetProjectRoleGroup(projectRoleGroupId); if (projectRoleGroupModel == null) { return(RedirectToIndexIdNotFound(projectRoleGroupId)); } // Convert the model data to non-model data ProjectRoleGroup projectRoleGroup = new ProjectRoleGroup(projectRoleGroupModel); // Get list of all project roles var projectRoleModels = ProjectRoleProcessor.GetAllProjectRoles(); // Get the links which are assigned to this group projectRoleGroup.Links = GetLinksForGroup(projectRoleGroup.ProjectRoleGroupId, projectRoleModels); // Setup the dropdown list with all project roles SetupRoleDropDownList(projectRoleModels); // Pass the data to the view return(View(projectRoleGroup)); } catch (Exception e) { return(RedirectToIndex(e)); } }
public async Task <int> EditProjectRoleGroupAsync(ProjectRoleGroup model) { try { using (var connection = _connectionProvider.Create()) { return(await connection.QuerySingleAsync <int>("dbig5_admin.UPDATE_PROJECT_ROLE_GROUP_VIASQLDEV", new { pProjectRoleGroup_ID = model.ProjectRoleGroup_ID, pPROJECTROLEGROUP_TYPE = model.ProjectRoleGroup_TYPE }, commandType : CommandType.StoredProcedure)); } } catch (Exception ex) { Console.WriteLine(ex); } return(0); }
public async Task <int> CreateProjectRoleGroupAsync(ProjectRoleGroup model) { try { using (var connection = _connectionProvider.Create()) { return(await connection.ExecuteScalarAsync <int>("dbig5_admin.ADD_PROJECT_ROLE_GROUP_VIASQLDEV", new { pPROJECTROLEGROUP_TYPE = model.ProjectRoleGroup_TYPE }, commandType : CommandType.StoredProcedure)); } } catch (Exception ex) { Console.WriteLine(ex); } // Return failed to insert return(0); }
public async Task <IActionResult> CreateProjectRoleGroup(ProjectRoleGroup model) { try { if (ModelState.IsValid) { await _projectRepo.CreateProjectRoleGroupAsync(model); return(RedirectToAction(nameof(ViewProjectRoleGroups))); } } catch (Exception ex) { Console.WriteLine(ex); } return(View(model)); }
public ActionResult Create(ProjectRoleGroup projectRoleGroup) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.ProjectRoleGroup)) { return(RedirectToPermissionDenied()); } // Make sure the entered data is valid if (ModelState.IsValid) { // Update the project within the database try { ProjectRoleGroupProcessor.CreateProjectRoleGroup(projectRoleGroup.Name); TempData[LabelSuccess] = "Created new group: " + projectRoleGroup.Name; return(RedirectToIndex()); } catch (Exception e) { ModelState.AddModelError("", e.Message); } } else { //show error var errors = ModelState.Values.SelectMany(v => v.Errors); } // Return to same page with same data return(View(projectRoleGroup)); }
public ActionResult Delete(ProjectRoleGroup projectRoleGroup) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.ProjectRoleGroup)) { return(RedirectToPermissionDenied()); } // Delete the project from the database try { ProjectRoleGroupProcessor.DeleteProjectRoleGroup(projectRoleGroup.ProjectRoleGroupId); TempData[LabelSuccess] = "Deleted group: " + projectRoleGroup.Name; return(RedirectToIndex()); } catch (Exception e) { return(RedirectToIndex(e)); } }
public ActionResult Edit(ProjectRoleGroup projectRoleGroup) { // Make sure the user is logged in and that they have permission if (!IsUserLoggedIn) { return(RedirectToLogin()); } if (!UserHasPermission(PermissionName.ProjectRoleGroup)) { return(RedirectToPermissionDenied()); } // Enter main body of the function try { // Check which submit button was pressed if (Request.Form["Save"] != null) { // Make sure the user is logged in if (!IsUserLoggedIn) { return(RedirectToLogin()); } // Make sure the entered data is valid if (ModelState.IsValid) { // Update the project role group within the database try { ProjectRoleGroupProcessor.UpdateProjectRoleGroup( projectRoleGroup.ProjectRoleGroupId, projectRoleGroup.Name); TempData[LabelSuccess] = "Updated group: " + projectRoleGroup.Name; return(RedirectToIndex()); } catch (Exception e) { ModelState.AddModelError("", e.Message); } } else { //show error var errors = ModelState.Values.SelectMany(v => v.Errors); } } else if (Request.Form["Add"] != null) { // Add a role link the project role group try { ProjectRoleLinkProcessor.CreateProjectRoleLink( projectRoleGroup.AddLink, projectRoleGroup.ProjectRoleGroupId); ViewBag.Added = "Added project role to group"; } catch (Exception e) { ViewBag.AddFail = e.Message; } } else { // Remove a role link the project role group try { const string marker = "Delete."; foreach (string key in Request.Form.AllKeys) { if (key.StartsWith(marker)) { ProjectRoleLinkProcessor.DeleteProjectRoleLink(Convert.ToInt32(key.Substring(marker.Length))); ViewBag.Removed = "Removed project role from group"; break; } } } catch (Exception e) { ViewBag.RemoveFail = e.Message; } } // Get the project role group data var projectRoleGroupModel = ProjectRoleGroupProcessor.GetProjectRoleGroup(projectRoleGroup.ProjectRoleGroupId); if (projectRoleGroupModel == null) { return(RedirectToIndexIdNotFound(projectRoleGroup.ProjectRoleGroupId)); } // Convert the model data to non-model data projectRoleGroup = new ProjectRoleGroup(projectRoleGroupModel); // Get list of all project roles var projectRoleModels = ProjectRoleProcessor.GetAllProjectRoles(); // Get the links which are assigned to this group projectRoleGroup.Links = GetLinksForGroup(projectRoleGroup.ProjectRoleGroupId, projectRoleModels); // Setup the dropdown list with all project roles SetupRoleDropDownList(projectRoleModels); // Return to same page with same data return(View(projectRoleGroup)); } catch (Exception e) { return(RedirectToIndex(e)); } }