public async Task <MainRolePermissionResponse> AddRolePermission(RolePermissionRequest rolePermissionRequest) { var rolePermissions = _mapper.Map <RolePermissions>(rolePermissionRequest); try { var isExist = _rolePermissionRepository.GetRolesPerminssion(rolePermissionRequest); if (rolePermissions.RolePermissionId == 0 && isExist.Result == null) { rolePermissions.CreatedBy = rolePermissionRequest.UserId.ToString(); var dataRole = await _rolePermissionRepository.AddAsync(rolePermissions); } else { _response.Message = Constants.RolePermission_Already_Exists; _response.Status = false; return(_response); } _response.Message = Constants.RolePermission_Created_Success; _response.Status = true; } catch (Exception) { _response.Status = false; _response.Message = Constants.DEFAULT_ERROR_MSG; } return(_response); }
public async Task <RolePermissionResponse> GetRolesPerminssion(RolePermissionRequest rolePermissionRequest) { RolePermissionResponse rolePermission = new RolePermissionResponse(); try { rolePermission = (from rp in ObjContext.RolePermissions where rp.RoleId == rolePermissionRequest.RoleId && rp.ScreenId == rolePermissionRequest.ScreenId && rp.PermissionId == rolePermissionRequest.PermissionId && rp.IsDeleted == false select new RolePermissionResponse { rolePermissionId = rp.RolePermissionId, RoleId = rp.RoleId, ScreenId = rp.ScreenId, PermissionId = rp.PermissionId, CreatedOn = rp.CreatedOn, CreatedBy = Convert.ToInt32(rp.CreatedBy) }).FirstOrDefault(); return(rolePermission); } catch (System.Exception ex) { var msg = ex.Message; throw; } }
public IActionResult Modify([FromBody] RolePermissionRequest rolePermissionRequest) { RolePermission rolePermission = AutoMap.Map <RolePermissionRequest, RolePermission>(rolePermissionRequest); this._rolePermissionService.Modify(rolePermission.Identity, rolePermission); RolePermissionResponse rolePermissionResponse = AutoMap.Map <RolePermissionRequest, RolePermissionResponse>(rolePermissionRequest); return(Ok(new BaseResponse <RolePermissionResponse>(rolePermissionResponse))); }
public async Task <ActionResult> UpdateRolePermission([FromBody] RolePermissionRequest rolePermissionRequest) { try { _response = await _rolePermissionService.UpdateRolePermission(rolePermissionRequest); return(new OkObjectResult(_response)); } catch (Exception ex) { _response.Message = ex.Message; _response.Status = false; return(BadRequest("")); } }
public async Task <MainRolePermissionResponse> UpdateRolePermission(RolePermissionRequest rolePermissionRequest) { var rolePermissions = _mapper.Map <RolePermissions>(rolePermissionRequest); try { var data = _rolePermissionRepository.GetRolesPerminssionById(rolePermissionRequest); if (data.Result != null) { var rolePermission = _mapper.Map <RolePermissions>(data.Result); rolePermission.RoleId = rolePermissions.RoleId; rolePermission.ScreenId = rolePermissions.ScreenId; rolePermission.PermissionId = rolePermissions.PermissionId; rolePermission.ModifiedOn = DateTime.Now; rolePermission.ModifiedBy = rolePermissionRequest.UserId.ToString(); rolePermission.IsActive = rolePermissionRequest.IsActive; var dataRole = await _rolePermissionRepository.UpdateAsync(rolePermission); } else { _response.Message = Constants.RolePermission_Not_Update; _response.Status = false; return(_response); } _response.Message = Constants.RolePermission_Update; _response.Status = true; return(_response); } catch (Exception ex) { var msg = ex.Message; _response.Status = false; _response.Message = Constants.DEFAULT_ERROR_MSG; } return(_response); }
public async Task <IActionResult> DeletePermissionOnRole(RolePermissionRequest request) { //Recupero l'elemento dal business layer var entity = AuthorizationLayer.GetPermissionRole(request.PermissionId, request.RoleId); //Se l'utente non hai i permessi non posso rimuovere entità con userId nullo if (entity == null) { return(NotFound()); } //Invocazione del service layer var validations = await AuthorizationLayer.DeletePermissionRole(entity, PlatformUtils.GetIdentityUserId(User)); if (validations.Count > 0) { return(BadRequest(validations)); } var permissions = AuthorizationLayer.FetchPermissionsOnRole(entity.RoleId); //Return contract return(Ok(permissions.As(ContractUtils.GenerateContract))); }