Exemplo n.º 1
0
        public Guid Edit(EditProductInputDto inputDto)
        {
            var product = _productRepo.Get(inputDto.Id);

            Validate.Found(product, "Produk");

            if (product.SKU != inputDto.SKU && _productRepo.Count(i => i.SKU == inputDto.SKU) > 0)
            {
                throw new HozaruException(string.Format("Produk dengan SKU {0} sudah terdaftar.", inputDto.SKU));
            }

            product.Update(inputDto.Name, inputDto.Description, inputDto.Price, inputDto.Weight, inputDto.SKU);

            var pathFileDirectory = AppSettingConfigurationHelper.GetSection("PathFileStorageDirectory").Value;

            foreach (var priority in inputDto.DeletedImagesByPriority)
            {
                var productImage = product.Images.FirstOrDefault(i => i.Priority == priority);
                if (productImage.IsNotNull())
                {
                    var imagePath = Path.Combine(pathFileDirectory, productImage.ImageUrl);
                    File.Delete(imagePath);
                    product.RemoveImage(productImage);
                }
            }

            foreach (var image in inputDto.Images)
            {
                var fileName    = string.Format("{0}_{1}", product.Name, image.Priority);
                var imageStream = image.Image.OpenReadStream();
                var imageObj    = Image.Load(imageStream);
                var filePath    = _imageGenerator.SaveProductImage(imageObj, fileName, product, JpegFormat.Instance);
                product.AddImage(filePath, fileName, image.Priority);
            }
            _productRepo.Update(product);

            return(product.Id);
        }
Exemplo n.º 2
0
        public ProductDto Edit([FromForm] EditProductInputDto inputDto)
        {
            var productId = _productAppService.Edit(inputDto);

            return(_productAppService.Get(productId));
        }