public async Task<IHttpActionResult> PostProduct(Product product) { if (ModelState.IsValid) { await Repository.SaveProductAsync(product); return Ok(); } else { return BadRequest(ModelState); } }
public void InsertProduct() { Product myProduct = new Product(); if (TryUpdateModel(myProduct, new FormValueProvider(ModelBindingExecutionContext))) { repo.SaveProduct(myProduct); } }
public async Task<int> SaveProductAsync(Product product) { if (product.Id == 0) { context.Products.Add(product); } else { Product dbEntry = context.Products.Find(product.Id); if (dbEntry != null) { dbEntry.Name = product.Name; dbEntry.Description = product.Description; dbEntry.Price = product.Price; dbEntry.Category = product.Category; } } return await context.SaveChangesAsync(); }
public void AddItem(Product product, int quantity) { var line = lineCollection .Where(l => l.Product.ProductID == product.ProductID) .FirstOrDefault(); if(line != null) { line.Quantity += quantity; } else { lineCollection.Add(new CartLine { Product = product, Quantity = quantity }); } }
public void RemoveLine(Product product) { lineCollection.RemoveAll(line => line.Product.ProductID == product.ProductID); }
public async Task<ActionResult> SaveProduct(Product product) { await repo.SaveProductAsync(product); return RedirectToAction("Index"); }
public override void RemoveLine(Product product) { base.RemoveLine(product); Session.SetJson("Cart", this); }
public override void AddItem(Product product, int quantity) { base.AddItem(product, quantity); Session.SetJson("Cart", this); }
public override void RemoveLine(Product product) { base.RemoveLine(product); Session.SetJson("Cart", this); //extends functionality }
public override void AddItem(Product product, int quantity) { base.AddItem(product, quantity); //calls method from base class Session.SetJson("Cart", this); }