public async Task <GenericResponse <UserDto> > Post([FromBody] UserDto dto) { UserBo bo = UserBo.ConvertToBusinessObject(dto); // Yetki kontrolü yapılıyor ServiceResult <bool> resultAutorized = await GetAutorizedUserStatusById(bo); if (!resultAutorized.Success || !resultAutorized.Data) { return(GenericResponse <UserDto> .Error(ResultType.Error, "Not Autorized Access!", "U_PST_01", StatusCodes.Status203NonAuthoritative)); } ServiceResult <UserBo> result = await serviceManager.User_Service.CreateAsync(bo); if (result.Success) { bo = result.Data; dto.Id = bo.Id; if (dto.Role != null && dto.Role.Count > 0) { UserRoleBo userRoleBo; foreach (var role in dto.Role) { userRoleBo = new UserRoleBo() { UserId = dto.Id, RoleId = role.Id }; await serviceManager.UserRole_Service.CreateAsync(userRoleBo); } } await serviceManager.CommitAsync(); } else { return(GenericResponse <UserDto> .Error(ResultType.Error, result.Error, "U_PST_02", StatusCodes.Status500InternalServerError)); } return(GenericResponse <UserDto> .Ok(dto)); }
public async Task <GenericResponse> Put(long id, UserDto dto) { if (id != dto.Id) { return(GenericResponse.Error(ResultType.Error, "Ids are mismatch!", "U_PT_01", StatusCodes.Status500InternalServerError)); } try { UserBo bo = UserBo.ConvertToBusinessObject(dto); // Yetki kontrolü yapılıyor ServiceResult <bool> resultAutorized = await GetAutorizedUserStatusById(bo); if (!resultAutorized.Success || !resultAutorized.Data) { return(GenericResponse.Error(ResultType.Error, "Not Autorized Access!", "U_PT_02", StatusCodes.Status203NonAuthoritative)); } ServiceResult serviceResult = await serviceManager.User_Service.UpdateAsync(id, bo); if (serviceResult.Success) { if (dto.Role != null && dto.Role.Count > 0) { await serviceManager.UserRole_Service.DeleteByUserIdAsync(dto.Id); UserRoleBo userRole; foreach (var role in dto.Role) { userRole = new UserRoleBo() { UserId = dto.Id, RoleId = role.Id }; await serviceManager.UserRole_Service.CreateAsync(userRole); } } await serviceManager.CommitAsync(); return(GenericResponse.Ok()); } else { return(GenericResponse.Error(ResultType.Error, serviceResult.Error, "U_PT_03", StatusCodes.Status500InternalServerError)); } } catch (DbUpdateConcurrencyException ex) { Log(ex.Message, LogLevel.Error, this.ControllerContext.RouteData.Values); bool exist = await UserExists(id); if (!exist) { return(GenericResponse.Error(ResultType.Error, "Not Found!", "U_PT_04", StatusCodes.Status404NotFound)); } else { return(GenericResponse.Error(ResultType.Error, ex.Message, "U_PT_05", StatusCodes.Status500InternalServerError)); } } }