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