public async Task<IHttpActionResult> PostProduct(Product product) {
     if (ModelState.IsValid) {
         await Repository.SaveProductAsync(product);
         return Ok();
     } else {
         return BadRequest(ModelState);
     }
 }
Пример #2
0
 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();
 }
Пример #4
0
        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
                });
            }
        }
Пример #5
0
 public void RemoveLine(Product product)
 {
     lineCollection.RemoveAll(line => line.Product.ProductID == product.ProductID);
 }
Пример #6
0
 public async Task<ActionResult> SaveProduct(Product product) {
     await repo.SaveProductAsync(product);
     return RedirectToAction("Index");
 }
Пример #7
0
 public override void RemoveLine(Product product)
 {
     base.RemoveLine(product);
     Session.SetJson("Cart", this);
 }
Пример #8
0
 public override void AddItem(Product product, int quantity)
 {
     base.AddItem(product, quantity);
     Session.SetJson("Cart", this);
 }
Пример #9
0
 public override void RemoveLine(Product product)
 {
     base.RemoveLine(product);
     Session.SetJson("Cart", this);  //extends functionality
 }
Пример #10
0
 public override void AddItem(Product product, int quantity)
 {
     base.AddItem(product, quantity);   //calls method from base class
     Session.SetJson("Cart", this);
 }