public async Task <GenericResponse> Put(long id, RoleDto dto) { if (id != dto.Id) { return(GenericResponse.Error(ResultType.Error, "Ids are mismatch!", "UR_PT_01", StatusCodes.Status500InternalServerError)); } try { RoleBo bo = RoleBo.ConvertToBusinessObject(dto); ServiceResult serviceResult = await serviceManager.Role_Service.UpdateAsync(id, bo); if (serviceResult.Success) { await serviceManager.CommitAsync(); return(GenericResponse.Ok()); } else { return(GenericResponse.Error(ResultType.Error, serviceResult.Error, "R_PT_02", StatusCodes.Status500InternalServerError)); } } catch (Exception ex) { Log(ex.Message, LogLevel.Error, this.ControllerContext.RouteData.Values); return(GenericResponse.Error(ResultType.Error, ex.Message, "R_PT_03", StatusCodes.Status500InternalServerError)); } }
public async Task <GenericResponse <RoleDto> > Post([FromBody] RoleDto dto) { RoleBo bo = RoleBo.ConvertToBusinessObject(dto); ServiceResult <RoleBo> result = await serviceManager.Role_Service.CreateAsync(bo); if (result.Success) { bo = result.Data; await serviceManager.CommitAsync(); } else { return(GenericResponse <RoleDto> .Error(ResultType.Error, result.Error, "R_PST_01", StatusCodes.Status500InternalServerError)); } if (bo == null) { return(GenericResponse <RoleDto> .Error(ResultType.Error, "Not Found!", "R_PST_02", StatusCodes.Status404NotFound)); } return(GenericResponse <RoleDto> .Ok(RoleBo.ConvertToDto(bo))); }