Пример #1
0
        public async Task <ActionResult <Product> > CreateOrUpdateProductSize(ProductSizeToCreateDto productSizeToCreate)
        {
            var spec    = new ProductWithTypesAndBrandsSpecification(productSizeToCreate.ProductId);
            var product = await _unitOfWork.Repository <Product>().GetEntityWithSpec(spec);

            if (productSizeToCreate != null)
            {
                product.AddOrUpdateProductSize(productSizeToCreate.Size, productSizeToCreate.Quantity);

                _unitOfWork.Repository <Product>().Update(product);

                var result = await _unitOfWork.Complete();

                if (result <= 0)
                {
                    return(BadRequest(new ApiResponse(400, "Problem creating product")));
                }
            }
            var productSize = product.ProductSizes.FirstOrDefault(x => x.Size == productSizeToCreate.Size);

            return(Ok(_mapper.Map <ProductSize, WarehouseToReturnDto>(productSize)));
        }
Пример #2
0
        public async Task <ActionResult <ProductToReturnDto> > AddOrUpdateProductSize(int id, ProductSizeToCreateDto sizeDto)
        {
            var spec    = new ProductWithTypesAndBrandsSpecification(id);
            var product = await _unitOfWork.Repository <Product>().GetEntityWithSpec(spec);

            if (sizeDto != null)
            {
                // product.AddPhoto(sizeDto.PictureUrl, photo.FileName);

                product.AddOrUpdateProductSize(sizeDto.Size, sizeDto.Quantity);

                _unitOfWork.Repository <Product>().Update(product);

                var result = await _unitOfWork.Complete();

                if (result <= 0)
                {
                    return(BadRequest(new ApiResponse(400, "Problem adding size product")));
                }
            }
            else
            {
                return(BadRequest(new ApiResponse(400, "problem saving photo to disk")));
            }
            return(_mapper.Map <Product, ProductToReturnDto>(product));
        }