public ActionResult BagProductDecrease(int ID) { if (CustomerData.Info == null) { return(Json("-2", JsonRequestBehavior.AllowGet)); } try { BagProducts bp = db.BagProducts.FirstOrDefault(x => x.ID == ID); if (bp.Amount > 1) { bp.Amount -= 1; db.SaveChanges(); return(Json("1", JsonRequestBehavior.AllowGet)); } else { return(Json("0", JsonRequestBehavior.AllowGet)); } } catch (Exception) { return(Json("-1", JsonRequestBehavior.AllowGet)); } }
public async Task ExecuteLoadItemsCommand() { IsBusy = true; try { BagProducts.Clear(); var bagItems = App.shoppingCard.ListProducts(); foreach (var item in bagItems) { BagProducts.Add(item); OnPropertyChanged(); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public ActionResult BagProductAdd(int productID, int amount) { if (CustomerData.Info == null) { return(Json("-2", JsonRequestBehavior.AllowGet)); } try { Products prd = Helpers.GetProduct(productID); if (prd.UnitsInStock < amount) { return(Json("0", JsonRequestBehavior.AllowGet)); } Bags bag = db.Bags.Where(x => x.CustomerID == CustomerData.Info.ID && x.Status == true).FirstOrDefault(); if (bag == null) { Bags newBag = new Bags(); newBag.CreatedDate = DateTime.Now; newBag.CustomerID = CustomerData.Info.ID; newBag.Status = true; newBag.IsSold = false; db.Bags.Add(newBag); db.SaveChanges(); BagProducts newBP = new BagProducts(); newBP.Amount = amount; newBP.BagID = newBag.ID; newBP.ProductID = productID; db.BagProducts.Add(newBP); db.SaveChanges(); return(Json("1", JsonRequestBehavior.AllowGet)); } else { BagProducts bp = db.BagProducts.FirstOrDefault(x => x.BagID == bag.ID && x.ProductID == productID); if (bp == null) { BagProducts newBP = new BagProducts(); newBP.Amount = amount; newBP.BagID = bag.ID; newBP.ProductID = productID; db.BagProducts.Add(newBP); db.SaveChanges(); } else { bp.Amount += 1; db.SaveChanges(); } return(Json("1", JsonRequestBehavior.AllowGet)); } } catch (Exception) { return(Json("-1", JsonRequestBehavior.AllowGet)); } }
public ActionResult BagProductIncrease(int ID) { if (CustomerData.Info == null) { return(Json("-2", JsonRequestBehavior.AllowGet)); } try { BagProducts bp = db.BagProducts.FirstOrDefault(x => x.ID == ID); Products prd = Helpers.GetProduct(bp.ProductID); if (prd.UnitsInStock < bp.Amount + 1) { return(Json("0", JsonRequestBehavior.AllowGet)); } bp.Amount += 1; db.SaveChanges(); return(Json("1", JsonRequestBehavior.AllowGet)); } catch (Exception) { return(Json("-1", JsonRequestBehavior.AllowGet)); } }