Ejemplo n.º 1
0
        /// <summary>
        /// removes One CartItem to existing Cartitem in cart. then calculates new values
        /// </summary>
        /// <param name="id">
        /// ID of CartItem in Cart
        /// </param>
        /// <returns>
        /// return New values for values in CartItem
        /// </returns>
        public ActionResult CountM(int id)
        {
            {
                var Temp = db.CartItem.Single(
                    Temp1 => Temp1.CartItemID == id);

                Temp.Count   = Temp.Count - 1;
                Temp.totPris = Temp.Produkt.Pris * Temp.Count;
                db.SaveChanges();


                var cart = ShoppingCart.GetCart(this.HttpContext);

                if (Temp.Count > 0)
                {
                    // Display the confirmation message
                    var results = new CountModelView
                    {
                        Message   = ("En " + Temp.Produkt.ProduktNamn + " har tagits bort från din varukorg."),
                        ItemCount = Temp.Count,
                        CartTotal = cart.GetTotal() * 1.25,
                        CartCount = cart.GetCount(),
                        ItemID    = Temp.ProduktID,
                        TotPris   = getCartItemTotalPris(Temp)
                    };
                    db.SaveChanges();
                    return(Json(results));
                }
                else
                {
                    Temp.Count   = Temp.Count + 1;
                    Temp.totPris = Temp.Produkt.Pris * Temp.Count;
                    db.SaveChanges();
                    cart.RemoveFromCart(Temp.ProduktID);
                    var results = new CountModelView
                    {
                        Message   = (Temp.Produkt.ProduktNamn + " har tagits bort från din varukorg."),
                        CartTotal = cart.GetTotal() * 1.25,
                        CartCount = cart.GetCount(),
                        ItemID    = Temp.ProduktID,
                        TotPris   = Temp.totPris
                    };
                    db.SaveChanges();
                    return(Json(results));
                }
            }
        }
Ejemplo n.º 2
0
        public ActionResult CountP(int id)
        {
            var Temp = db.CartItem.Single(
                Temp1 => Temp1.CartItemID == id);

            Temp.Count   = Temp.Count + 1;
            Temp.totPris = Temp.Produkt.Pris * Temp.Count;
            db.SaveChanges();

            var cart = ShoppingCart.GetCart(this.HttpContext);

            if (Temp.Count <= Temp.Produkt.AntalILager)
            {
                var results = new CountModelView
                {
                    Message   = Temp.Produkt.ProduktNamn + " har ändrats till " + Temp.Count + " stcken.",
                    ItemCount = Temp.Count,
                    TotPris   = Temp.totPris,
                    CartTotal = cart.GetTotal() * 1.25,
                    CartCount = cart.GetCount(),
                    ItemID    = Temp.ProduktID
                };
                db.SaveChanges();
                return(Json(results));
            }
            else
            {
                Temp.Count   = Temp.Count - 1;
                Temp.totPris = Temp.Produkt.Pris * Temp.Count;
                db.SaveChanges();
                var results = new CountModelView
                {
                    Message   = "Inga mer Produkter i Lager.",
                    ItemCount = Temp.Count,
                    TotPris   = Temp.totPris,
                    CartTotal = cart.GetTotal() * 1.25,
                    CartCount = cart.GetCount(),
                    ItemID    = Temp.ProduktID
                };
                db.SaveChanges();
                return(Json(results));
            }
        }