Example #1
0
        public ActionResult PurchaseInfo(Client client)
        {
            if (!ModelState.IsValid)
            {
                return(View("PurchaseInfo", client));
            }
            using (InternetStoreContext db = new InternetStoreContext())
            {
                db.Clients.Add(client);
                Purchase purchase = new Purchase();
                purchase.Client = client;
                foreach (var item in MyCart.GetInstance().Cart)
                {
                    var it = db.Items.FirstOrDefault(x => x.Id == item.Id);
                    if (it != null)
                    {
                        var _size = it.Sizes.FirstOrDefault(x => x.MySize == item.SizeName);
                        if (_size != null)
                        {
                            _size.Count -= item.Quantity;
                        }
                    }
                    item.Archive = true;
                    purchase.Items.Add(item);
                }
                purchase.PurchaseDateTime = DateTime.Now;

                db.Purchases.Add(purchase);

                db.SaveChanges();

                MyCart.GetInstance().Cart.Clear();
            }
            return(RedirectToAction("ShowCart"));
        }
Example #2
0
        public ActionResult DeleteFromCart(int id)
        {
            Item item;

            if ((item = MyCart.GetInstance().Cart.FirstOrDefault(x => x.Id == id)) != null)
            {
                MyCart.GetInstance().Cart.Remove(item);
            }
            return(RedirectToAction("ShowCart"));
        }
Example #3
0
        public ActionResult AddToCart(int Id, int quantity, string size)
        {
            size = size.Replace("\r\n", "").Trim();
            Item item;

            using (InternetStoreContext db = new InternetStoreContext())
            {
                item = db.Items.FirstOrDefault(x => x.Id == Id);
            }
            if (item != null)
            {
                item.Quantity = quantity;
                item.SizeName = size;
            }

            MyCart.GetInstance().Cart.Add(item);

            return(RedirectToAction("Index"));
        }
Example #4
0
 public ActionResult ShowCart()
 {
     return(View(MyCart.GetInstance().Cart));
 }