コード例 #1
0
        public async Task <IActionResult> Update([FromForm] ProductDto updatedProduct)
        {
            var product = await _productRepository.Get(updatedProduct.Id);

            _mapper.Map <ProductDto, Product>(updatedProduct, product);
            if (product.StartingTime > DateTime.Now && product.StartingTime < product.EndingTime)
            {
                product.Status = ProductStatus.Inactive;
            }
            else if (product.StartingTime < DateTime.Now && product.StartingTime < product.EndingTime)
            {
                product.Status = ProductStatus.Active;
            }
            else
            {
                return(new StatusCodeResult(400));
            }
            if (updatedProduct.IsFileModified)
            {
                _fileUploadService.RemoveExistingImagesFromStorage(product.Photos.ToList());
                product.Photos.Clear();
                product.Photos = _fileUploadService.UploadFiles(updatedProduct.Photos);
            }
            _productRepository.SaveChanges();
            return(Ok());
        }