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