public IActionResult UpdateManufacturer([FromBody] UpdateManufacturerModel model) { try { var getManufacturer = _manufacturerRepository.GetById(model.Id); if (!getManufacturer.isStatusCodeSuccess() || getManufacturer.Data == null) { return(NotFound()); } var updateResponse = _manufacturerRepository.Update(model.ToEntity(getManufacturer.Data)); if (updateResponse.isStatusCodeSuccess() && updateResponse.Data != null) { return(StatusCode(updateResponse.StatusCode, ManufacturerModel.ToModel(updateResponse.Data))); } else { return(StatusCode(updateResponse.StatusCode)); } } catch (Exception e) { return(InternalServerError()); } }
public async Task <TResponse <bool> > Update(int userId, UpdateManufacturerModel request, int permissionId) { try { var checkValid = await _userService.CheckPermission(userId, permissionId); if (checkValid.IsSuccess) { var canUpdate = await CanUpdate(request); if (canUpdate.IsSuccess) { var result = await WriteRepository.ExecuteAsync(SqlQuery.MANUFACTURER_UPDATE, new { request.Id, request.Name, UserUpdated = userId, DateUpdated = DateTime.Now }); if (result.IsSuccess) { if (result.Data > 0) { #region Update redis cache await _manufacturerCacheService.AddOrUpdate(new ManufacturerCacheModel { Id = request.Id, Name = request.Name }); #endregion return(await Ok(true)); } return(await Fail <bool>(ErrorEnum.BAD_REQUEST.GetStringValue())); } return(await Fail <bool>(result.Message)); } return(await Fail <bool>(canUpdate.Message)); } return(await Fail <bool>(checkValid.Message)); } catch (Exception exception) { return(await Fail <bool>(exception)); } }
private async Task <TResponse <bool> > CanUpdate(UpdateManufacturerModel request) { try { var manufacturer = await _manufacturerCacheService.GetByName(request.Name); if (manufacturer != null && manufacturer.Id != request.Id) { return(await Fail <bool>(ErrorEnum.MANUFACTURER_HAS_EXIST.GetStringValue())); } return(await Ok(true)); } catch (Exception exception) { return(await Fail <bool>(exception)); } }
public async Task <ActionResult <bool> > Update(UpdateManufacturerModel request) { return(Ok(await _manufacturerService.Update(await GetUserId(), request, GetPermissionId()))); }