Пример #1
0
        public override async Task <ActionResult <UpdateCatalogItemResponse> > HandleAsync(UpdateCatalogItemRequest request)
        {
            var response = new UpdateCatalogItemResponse(request.CorrelationId());

            var existingItem = await _itemRepository.GetByIdAsync(request.Id);

            existingItem.UpdateDetails(request.Name, request.Description, request.Price);
            existingItem.UpdateBrand(request.CatalogBrandId);
            existingItem.UpdateType(request.CatalogTypeId);

            await _itemRepository.UpdateAsync(existingItem);

            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);
        }
Пример #2
0
        public override async Task <ActionResult <CreateCatalogItemResponse> > HandleAsync(CreateCatalogItemRequest request, CancellationToken cancellationToken)
        {
            var response = new CreateCatalogItemResponse(request.CorrelationId());

            var newItem = new CatalogItem(request.CatalogTypeId, request.CatalogBrandId, request.Description, request.Name, request.Price, request.PictureUri);

            newItem = await _itemRepository.AddAsync(newItem, cancellationToken);

            if (newItem.Id != 0)
            {
                var picName = $"{newItem.Id}{Path.GetExtension(request.PictureName)}";
                if (await _webFileSystem.SavePicture(picName, request.PictureBase64, cancellationToken))
                {
                    newItem.UpdatePictureUri(picName);
                    await _itemRepository.UpdateAsync(newItem, cancellationToken);
                }
            }

            var dto = new CatalogItemDto
            {
                Id             = newItem.Id,
                CatalogBrandId = newItem.CatalogBrandId,
                CatalogTypeId  = newItem.CatalogTypeId,
                Description    = newItem.Description,
                Name           = newItem.Name,
                PictureUri     = _uriComposer.ComposePicUri(newItem.PictureUri),
                Price          = newItem.Price
            };

            response.CatalogItem = dto;
            return(response);
        }
Пример #3
0
        public override async Task <ActionResult <CreateCatalogItemResponse> > HandleAsync(CreateCatalogItemRequest request, CancellationToken cancellationToken)
        {
            var response = new CreateCatalogItemResponse(request.CorrelationId());

            var newItem = new CatalogItem(request.CatalogTypeId, request.CatalogBrandId, request.Description, request.Name, request.Price, request.PictureUri);

            newItem = await _itemRepository.AddAsync(newItem, cancellationToken);

            if (newItem.Id != 0)
            {
                //We disabled the upload functionality and added a default/placeholder image to this sample due to a potential security risk
                //  pointed out by the community. More info in this issue: https://github.com/dotnet-architecture/eShopOnWeb/issues/537
                //  In production, we recommend uploading to a blob storage and deliver the image via CDN after a verification process.

                newItem.UpdatePictureUri("eCatalog-item-default.png");
                await _itemRepository.UpdateAsync(newItem, cancellationToken);
            }

            var dto = new CatalogItemDto
            {
                Id             = newItem.Id,
                CatalogBrandId = newItem.CatalogBrandId,
                CatalogTypeId  = newItem.CatalogTypeId,
                Description    = newItem.Description,
                Name           = newItem.Name,
                PictureUri     = _uriComposer.ComposePicUri(newItem.PictureUri),
                Price          = newItem.Price
            };

            response.CatalogItem = dto;
            return(response);
        }
Пример #4
0
        public override async Task <ActionResult <CreateCatalogItemResponse> > HandleAsync(CreateCatalogItemRequest request)
        {
            var response = new CreateCatalogItemResponse(request.CorrelationId());

            CatalogItem newItem = new CatalogItem(request.CatalogTypeId, request.CatalogBrandId, request.Description, request.Name, request.Price, request.PictureUri);

            newItem = await _itemRepository.AddAsync(newItem);

            var dto = new CatalogItemDto
            {
                Id             = newItem.Id,
                CatalogBrandId = newItem.CatalogBrandId,
                CatalogTypeId  = newItem.CatalogTypeId,
                Description    = newItem.Description,
                Name           = newItem.Name,
                PictureUri     = newItem.PictureUri,
                Price          = newItem.Price
            };

            response.CatalogItem = dto;
            return(response);
        }
Пример #5
0
        public override async Task <ActionResult <UpdateCatalogItemResponse> > HandleAsync(UpdateCatalogItemRequest request)
        {
            var response = new UpdateCatalogItemResponse(request.CorrelationId());

            var existingItem = await _itemRepository.GetByIdAsync(request.Id);

            existingItem.UpdateDetails(request.Name, request.Description, request.Price);
            existingItem.UpdateBrand(request.CatalogBrandId);
            existingItem.UpdateType(request.CatalogTypeId);

            if (string.IsNullOrEmpty(request.PictureBase64))
            {
                existingItem.UpdatePictureUri(string.Empty);
            }
            else
            {
                var picName = $"{existingItem.Id}{Path.GetExtension(request.PictureName)}";
                if (await _webFileSystem.SavePicture($"{picName}", request.PictureBase64))
                {
                    existingItem.UpdatePictureUri(picName);
                }
            }

            await _itemRepository.UpdateAsync(existingItem);

            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);
        }