예제 #1
0
        public ActionResult RemoveFromCart(int id = 0)
        {
            int servicePercent = 0;
            int vatpercent = 0;
            decimal subtotal = 0;
            decimal service = 0;
            decimal vat = 0;
            decimal deliverycharge = 0;
            decimal gtotal = 0;
            bool isRemoved = false;
            var cart = new Cart();
            Restaurant restaurant = (Restaurant)Session["Restaurant"];
            if (restaurant.IsServiceChargeApplicable == true)
                servicePercent = Convert.ToInt32(restaurant.ServiceChargePercent);
            if (restaurant.IsVatApplicable == true)
                vatpercent = Convert.ToInt32(restaurant.VATPercent);

            CartDetail od = new CartDetail();
            cart = (Cart)Session["Cart"];
            List<CartDetail> listorderdetail = cart.cartDetail;
            CartSummary cartsummary = cart.cartSummary;
            //Order order = cart.Orders;

            foreach (CartDetail c in listorderdetail)
            {
                if (c.FoodItemId == id)
                {
                    listorderdetail.Remove(c);
                    break;
                }
            }
            foreach (var c in listorderdetail)
            {
                subtotal = subtotal + c.Rate * c.Quantity;
            }

            cartsummary.SubTotal = subtotal;
            service = (subtotal) * servicePercent / 100;
            cartsummary.ServiceCharge = service;
            vat = (service+subtotal) * vatpercent / 100;
            cartsummary.VAT = vat;
            cartsummary.GrossTotal = subtotal + service + vat + deliverycharge;
            cart.cartSummary = cartsummary;
            cartsummary.ServiceChargePercent = servicePercent;
            cartsummary.VATPercent = vatpercent;
            cart.cartSummary = cartsummary;
            Session["Cart"] = cart;
            isRemoved = false;
            ViewBag.message = "Removed";
            return RedirectToAction("Index",new { message = ViewData["message"] });
        }
예제 #2
0
        //Get Cart Collection
        public ActionResult AddToCart(int id=0,int quantity=0)
        {
            CartDetail cartdetail = new CartDetail();
            List<CartDetail> cartdetaillist = new List<CartDetail>();
            CartSummary cartsummary = new CartSummary();
            Cart cart=new Cart();
            FoodItem foodItem = db.FoodItems.Single(fi => fi.FoodItemId == id);
            Session["Restaurant"] = db.Restaurants.Single(f => f.RestaurantId == foodItem.RestaurantId);
            cartdetail.FoodItemId = id;
            cartdetail.FoodItem = foodItem.FoodItemName;
            cartdetail.Rate = (decimal)foodItem.FoodItemRate;
            cartdetail.Quantity = quantity;
            cartdetail.Total = (decimal)foodItem.FoodItemRate * quantity;
            bool isAdded = false;
            int servicePercent = 0;
            int vatpercent = 0;
            decimal subtotal=0;
            decimal service = 0;
            decimal vat = 0;
            decimal deliverycharge = 0;
            decimal gtotal = 0;
            Restaurant restaurant=(Restaurant)Session["Restaurant"];
            ViewBag.message = "Added";
            if(restaurant.IsServiceChargeApplicable==true)
            servicePercent=Convert.ToInt32(restaurant.ServiceChargePercent);
            if(restaurant.IsVatApplicable==true)
                vatpercent=Convert.ToInt32(restaurant.VATPercent);
            if (Session["Cart"] != null)
            {
                Restaurant sesrest = ((Cart)Session["Cart"]).restaurantsess;
                if (sesrest != null)
                {
                    if (sesrest.RestaurantId != restaurant.RestaurantId)
                    {
                        //MessageBox.Show("Alert");
                        Session["Cart"] = null;
                        cartdetaillist.Add(cartdetail);
                        cart.cartDetail = cartdetaillist;
                        ViewData["message"] = "RestaurantChanged";
                        //subtotal = cartdetail.Rate * cartdetail.Quantity;
                        //cartsummary.SubTotal = subtotal;
                        //service = (subtotal) * servicePercent / 100;
                        //cartsummary.ServiceCharge = service;
                        //vat = (service + subtotal) * vatpercent / 100;

                        //cartsummary.VAT = vat;
                        //cartsummary.GrossTotal = subtotal + service + vat + deliverycharge;
                        //cart.cartSummary = cartsummary;
                        //cartsummary.VATPercent = vatpercent;
                        //cartsummary.ServiceChargePercent = servicePercent;
                        //cart.cartSummary = cartsummary;

                        cart.restaurantsess = (Restaurant)Session["Restaurant"];
                        Session["Cart"]=cart;
                        isAdded = true;
                    }

                }
                else
                {
                    cart.restaurantsess = restaurant;
                }
                cart = (Cart)Session["Cart"];
                cartdetaillist = cart.cartDetail;
                foreach (var c in cartdetaillist)
                {
                    if(isAdded==false)
                    if (c.FoodItemId == id)
                    {
                        c.Quantity = c.Quantity + quantity;
                        c.Total = c.Rate * c.Quantity;
                        isAdded = true;
                    }

                }
                if (isAdded == false)
                {
                    cartdetaillist.Add(cartdetail);
                 }
                foreach (var c in cartdetaillist)
                {
                    subtotal = subtotal+c.Rate * c.Quantity;
                }

                cartsummary.SubTotal = subtotal;
                service = (subtotal) * servicePercent / 100;
                cartsummary.ServiceCharge = service;
                vat = (service+subtotal) * vatpercent / 100;
                cartsummary.VAT = vat;
                cartsummary.GrossTotal = subtotal + service + vat + deliverycharge;
                cartsummary.ServiceChargePercent = servicePercent;
                cartsummary.VATPercent = vatpercent;
                cart.cartSummary = cartsummary;
            }
            else
            {
                cartdetaillist.Add(cartdetail);
                cart.cartDetail = cartdetaillist;
                subtotal=cartdetail.Rate * cartdetail.Quantity;
                cartsummary.SubTotal = subtotal;
                service = (subtotal) * servicePercent / 100;
                cartsummary.ServiceCharge = service;
                vat = (service + subtotal) * vatpercent / 100;

                cartsummary.VAT = vat;
                cartsummary.GrossTotal = subtotal + service + vat + deliverycharge;
                cart.cartSummary = cartsummary;
                cartsummary.VATPercent = vatpercent;
                cartsummary.ServiceChargePercent = servicePercent;
                cart.cartSummary = cartsummary;
            }
            cart.restaurantsess = restaurant;
            Session["Cart"] = cart;
            return RedirectToAction("Index", new { message = ViewData["message"] });
        }