public async ValueTask <(bool isSuccess, string error)> UpdateGallery(GalleryDTO galleryDTO, Gallery oldGallery) { if (oldGallery.NormalizeAlias != galleryDTO.Alias.TransformToId()) { var entity = await _repository.GetGallery(galleryDTO.Alias); if (entity != null) { return(false, "Галерея с таким наименованием уже существует"); } } await _photoEntityUpdater.LoadPhotosToEntity(oldGallery, galleryDTO, maxPixel : 1600); oldGallery.Alias = galleryDTO.Alias; oldGallery.NormalizeAlias = galleryDTO.Alias.TransformToId(); oldGallery.IsVisible = galleryDTO.IsVisible ?? true; return(await _repository.UpdateGallery(oldGallery)); }
public async Task <IActionResult> GetGallery([FromQuery] string galleryIdentify) { Gallery gallery; if (Int32.TryParse(galleryIdentify, out var galleryId)) { gallery = await _repository.GetGallery(galleryId); } else { gallery = await _repository.GetGallery(galleryIdentify); } if (gallery == null) { var msg = $"Не удалось найти галерею с идентификатором \"{galleryIdentify}\"."; _logger.LogError(msg); return(BadRequest(msg)); } return(Success(gallery.Photos)); }
public async Task <IActionResult> AddOrUpdate([FromForm] GalleryDTO galleryDTO) { const string API_LOCATE = CONTROLLER_LOCATE + ".AddOrUpdate"; var error = ERROR; try { bool isSuccess; if (galleryDTO.GalleryId <= 0) { (isSuccess, error) = await _service.AddGallery(galleryDTO); } else { var oldGallery = await _repository.GetGallery(galleryDTO.GalleryId); if (oldGallery is null) { return(LogBadRequest( _logger, API_LOCATE, customError: $"Что-то пошло не так, не удалось найти галерею.\n\tГалерея: {galleryDTO.GalleryId}" )); } (isSuccess, error) = await _service.UpdateGallery(galleryDTO, oldGallery); } if (!isSuccess) { return(LogBadRequest( _logger, API_LOCATE, customError: error )); } return(Success(isSuccess)); } catch (Exception ex) { return(LogBadRequest( _logger, API_LOCATE, exception: ex, customError: error )); } }