public async Task <ActionResult> Create(/*[Bind(Include = "Id,Barcode,Name,Description,Image,Type,PriceId")]*/ Product product, Nutrient nutrient, Collection <Price> prices, Price price, HttpPostedFileBase file) { if (ModelState.IsValid) { byte[] imgData; using (BinaryReader reader = new BinaryReader(file.InputStream)) { imgData = reader.ReadBytes((int)file.InputStream.Length); } product.Image = imgData; price.Product = product; price.CreationDate = System.DateTime.Now; nutrient.Product = product; product.Nutrient = nutrient; //product.Prices = new List<Price> { price }; db.Products.Add(product); db.Nutrients.Add(nutrient); db.Prices.Add(price); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(product)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Barcode,Name,Description,Image,Type,PriceId")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(product)); }