public async Task <RoleOperationDto> AddRoleOperationAsync(RoleOperationDto model) { try { var existingPermission = await _roleOperationRepository.ExistsAsync(x => x.RoleId == model.RoleId && x.OperationId == model.OperationId); if (!existingPermission) { var dbEntity = model.ToEntity <RoleOperation>(_mapper); await _roleOperationRepository.InsertAsync(dbEntity); await _unitOfWork.SaveChangesAsync(); model.RoleOperationId = dbEntity.RoleOperationId; } else { throw new ApplicationException("RoleOperation already exist."); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); throw ex; } return(model); }
public async Task <ActionResult> PatchRoleOperation([FromBody] RoleOperationDto model) { if (model == null) { return(BadRequest()); } await _roleManagementService.UpdateRoleOperationAsync(model); return(NoContent()); }
public async Task <ActionResult> PostRoleOperation([FromBody] RoleOperationDto model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _roleManagementService.AddRoleOperationAsync(model); return(Ok(result)); }
public async Task DeleteRoleOperationAsync(RoleOperationDto model) { try { var dbEntity = await _roleOperationRepository.FindAsync(model.RoleOperationId); _roleOperationRepository.Delete(dbEntity); await _unitOfWork.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError(ex, ex.Message); throw ex; } }
public async Task <ActionResult> DeleteRoleOperation(RoleOperationDto model) { await _roleManagementService.DeleteRoleOperationAsync(model); return(NoContent()); }