public override async Task <ActionResult <UpdateCatalogItemResponse> > HandleAsync(UpdateCatalogItemRequest request, CancellationToken cancellationToken) { var response = new UpdateCatalogItemResponse(request.CorrelationId()); var existingItem = await _itemRepository.GetByIdAsync(request.Id, cancellationToken); existingItem.UpdateDetails(request.Name, request.Description, request.Price); existingItem.UpdateBrand(request.CatalogBrandId); existingItem.UpdateType(request.CatalogTypeId); await _itemRepository.UpdateAsync(existingItem, cancellationToken); var dto = new CatalogItemDto { Id = existingItem.Id, CatalogBrandId = existingItem.CatalogBrandId, CatalogTypeId = existingItem.CatalogTypeId, Description = existingItem.Description, Name = existingItem.Name, PictureUri = _uriComposer.ComposePicUri(existingItem.PictureUri), Price = existingItem.Price }; response.CatalogItem = dto; return(response); }
public override async Task <ActionResult <UpdateCatalogItemResponse> > HandleAsync(UpdateCatalogItemRequest request, CancellationToken cancellationToken) { var response = new UpdateCatalogItemResponse(request.CorrelationId()); var existingItem = await _itemRepository.GetByIdAsync(request.Id, cancellationToken); existingItem.UpdateDetails(request.Name, request.Description, request.Price); existingItem.UpdateBrand(request.CatalogBrandId); existingItem.UpdateType(request.CatalogTypeId); if (string.IsNullOrEmpty(request.PictureBase64) && string.IsNullOrEmpty(request.PictureUri)) { existingItem.UpdatePictureUri(string.Empty); } else { var picName = $"{existingItem.Id}{Path.GetExtension(request.PictureName)}"; if (await _webFileSystem.SavePicture($"{picName}", request.PictureBase64, cancellationToken)) { existingItem.UpdatePictureUri(picName); } } await _itemRepository.UpdateAsync(existingItem, cancellationToken); var dto = new CatalogItemDto { Id = existingItem.Id, CatalogBrandId = existingItem.CatalogBrandId, CatalogTypeId = existingItem.CatalogTypeId, Description = existingItem.Description, Name = existingItem.Name, PictureUri = _uriComposer.ComposePicUri(existingItem.PictureUri), Price = existingItem.Price }; response.CatalogItem = dto; return(response); }