protected void deleteSubmit_Click(object sender, EventArgs e) { try { IRolePermissionRepository rolePermRepo = RepositoryFactory.Get <IRolePermissionRepository>(); RolePermission deleteMe = rolePermRepo.GetById(int.Parse(deletePermLabel.Text)); rolePermRepo.DeleteRolePermission(deleteMe.permissionID); rolePermRepo.SubmitChanges(); //return a validation message errorLabel.Text = "Permission has been deleted"; errorLabel.Visible = true; //hide the panel deletePanel.Visible = false; } catch (Exception) { //error message errorLabel.Text = "Database error when deleting role permission"; errorLabel.Visible = true; } updateRolePermissionTable(); }
public IHttpActionResult SaveRoleAndPermissionDetails(List <RolePermissionAc> permission) { try { if (HttpContext.Current.User.Identity.IsAuthenticated) { var userID = HttpContext.Current.User.Identity.GetUserId(); var companyDetails = _companyRepository.GetCompanyDetailByUserId(userID); foreach (var permissionDetails in permission) { foreach (var permissions in permissionDetails.Permission) { foreach (var childPermission in permissions.Children) { if (childPermission.IsChecked) { var rolePermission = new RolePermission(); rolePermission.CreatedDateTime = DateTime.UtcNow; rolePermission.ChildPermissionId = childPermission.PermissionId; rolePermission.CompanyId = companyDetails.Id; rolePermission.RoleId = permissionDetails.RoleId; rolePermission.IsChecked = true; _workFlowRepository.AddRoleAndPermission(rolePermission); } else { var rolePermission = new RolePermission(); rolePermission.CreatedDateTime = DateTime.UtcNow; rolePermission.ChildPermissionId = childPermission.PermissionId; rolePermission.CompanyId = companyDetails.Id; rolePermission.RoleId = permissionDetails.RoleId; _workFlowRepository.DeleteRolePermission(rolePermission); } } } } return(Ok(new { IsResult = true })); } else { return(BadRequest()); } } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
public EmptyResult DeleteRolePermission(DeleteRolePermissionCommand command) { if (string.IsNullOrEmpty(command.RoleId)) { return(new Result <bool>(AuthorizationServiceErrors.InvalidDeleteEntityError(nameof(command.RoleId)))); } if (!command.OrganizationId.HasValue) { return(new Result <bool>(AuthorizationServiceErrors.InvalidDeleteEntityError(nameof(command.OrganizationId)))); } rolePermissionRepository.DeleteRolePermission(command); return(new Result <bool>()); }