public async Task UpdateProduct( long Id, string Name, decimal Price, string Description, long?CoverImageId, long[] ProductImages, long?BrandId, long[] ProductCategories) { Product product = await Get(Id, 0); product.Name = Name; product.Price = Price; product.Description = Description; product.BrandId = BrandId; if (product.CoverImageId.HasValue && product.CoverImage.ImageId != CoverImageId.Value) { product.CoverImage = new ProductCoverImage { ImageId = CoverImageId.Value }; } if (CoverImageId.HasValue) { ProductCoverImage cover = new ProductCoverImage { ImageId = CoverImageId.Value }; product.CoverImage = cover; } product.ProductCategories = new List <ProductCategory>(); foreach (long category in ProductCategories) { ProductCategory productCategory = new ProductCategory { CategoryId = category }; product.ProductCategories.Add(productCategory); } product.ProductImages = new List <ProductImage>(); foreach (long image in ProductImages) { ProductImage productImage = new ProductImage { ImageId = image }; product.ProductImages.Add(productImage); } await ProductRepository.UpdateAsync(product); }
public async Task CreateProduct( string Name, decimal Price, string Description, long?CoverImageId, long[] ProductImages, long SellerId, long?BrandId, long[] ProductCategories ) { Product product = new Product { Name = Name, BrandId = BrandId, SellerId = SellerId, Description = Description, Price = Price }; if (CoverImageId.HasValue) { ProductCoverImage cover = new ProductCoverImage { ImageId = CoverImageId.Value }; product.CoverImage = cover; } product.ProductCategories = new List <ProductCategory>(); foreach (long category in ProductCategories) { ProductCategory productCategory = new ProductCategory { CategoryId = category }; product.ProductCategories.Add(productCategory); } product.ProductImages = new List <ProductImage>(); foreach (long image in ProductImages) { ProductImage productImage = new ProductImage { ImageId = image }; product.ProductImages.Add(productImage); } await ProductRepository.InsertAsync(product); }