public Guid Create(CreateNewProductInputDto inputDto) { //if (_productRepo.Exist(i => i.Name == inputDto.Name)) // throw new HozaruException(string.Format("Produk {0} sudah terdaftar.", inputDto.Name)); if (!inputDto.SKU.IsNullOrWhiteSpace() && _productRepo.Exist(i => i.SKU == inputDto.SKU)) { throw new HozaruException(string.Format("Produk dengan SKU {0} sudah terdaftar.", inputDto.SKU)); } var product = Product.Create(inputDto.Name, inputDto.Description, inputDto.Price, inputDto.Weight, inputDto.SKU); _productRepo.Insert(product); foreach (var imageInputDto in inputDto.Images) { var fileName = string.Format("{0}_{1}", product.Name, imageInputDto.Priority); var imageStream = imageInputDto.Image.OpenReadStream(); var imageObj = Image.Load(imageStream); var filePath = _imageGenerator.SaveProductImage(imageObj, fileName, product, JpegFormat.Instance); product.AddImage(filePath, fileName, imageInputDto.Priority); } _productRepo.Update(product); return(product.Id); }
public ProductDto CreateProduct([FromForm] CreateNewProductInputDto inputDto) { var productId = _productAppService.Create(inputDto); return(_productAppService.Get(productId)); }