Ejemplo n.º 1
0
        // GET: Item
        public ActionResult Index(string option, string search, int?pageNumber, string sort)
        {
            //Search by name, description and category
            List <Item> itemList = (db.Items.Where(x => x.iName.Contains(search) || x.iDescription.Contains(search) || x.iCategory.Contains(search) || search == null).OrderBy(x => x.iName).ThenBy(x => x.iCategory).ToList());

            if (System.Web.HttpContext.Current.User.Identity.Name != null)
            {
                updateSession();
                List <bool> itemListCheck = null;
                //Using iterator to check for every item if its available or not
                //Get all the item details and store it in the list;
                if (Convert.ToInt32(Session["currentCart"]) > 0)
                {
                    int currentCartID = Convert.ToInt32(Session["currentCart"]);
                    itemListCheck = new List <bool>();

                    IIterator <Item> iter = new IteratorGeneric <Item>(itemList);

                    while (!iter.IsDone())
                    {
                        int?newItemID = iter.current().itemID;
                        if (newItemID != null)
                        {
                            CartItem item = db.CartItems.SingleOrDefault(x => x.itemID == newItemID && x.cartID == currentCartID);
                            if (item == null)
                            {
                                itemListCheck.Add(false);
                            }
                            else
                            {
                                itemListCheck.Add(true);
                            }

                            iter.Next();
                        }
                    }

                    ViewBag.check = itemListCheck;
                }
            }

            return(View(itemList.ToPagedList(pageNumber ?? 1, 3)));
            //return View(itemGateway.SelectAll());
        }
Ejemplo n.º 2
0
        public ActionResult OrderDetails(int?existingCartID)
        {
            updateSession();
            ViewBag.ID = existingCartID;

            //Get all the cart items
            List <CartItem> cartItemList = db.CartItems.Where(x => x.cartID == existingCartID).ToList();

            List <Item> itemList           = new List <Item>();
            List <bool> checkItemAvailable = new List <bool>();

            //Get all the item details and store it in the list;
            IIterator <CartItem> iter = new IteratorGeneric <CartItem>(cartItemList);

            while (!iter.IsDone())
            {
                int?newItemID = iter.current().itemID;
                if (newItemID != null)
                {
                    Item item = db.Items.SingleOrDefault(x => x.itemID == newItemID);
                    itemList.Add(item);

                    iter.Next();
                }
            }

            //Create a new model to contain all the data..
            List <CartViewModels> viewModel = new List <CartViewModels>();

            var cartData      = new CartViewModels();
            var cartDataCarts = new Cart();

            cartDataCarts      = db.Carts.SingleOrDefault(x => x.cartID == existingCartID);
            cartData.cartItems = cartItemList;
            cartData.items     = itemList;
            cartData.carts     = cartDataCarts;

            viewModel.Add(cartData);

            return(View(viewModel));
        }
Ejemplo n.º 3
0
        public ActionResult Index()
        {
            updateSession();

            createNewCart();

            //Get a MAIN single cart ID
            //Get all the cart items
            int             currentCartID = Convert.ToInt32(Session["currentCart"]);
            List <CartItem> cartItemList  = db.CartItems.Where(x => x.cartID == currentCartID).ToList();

            List <Item> itemList           = new List <Item>();
            List <bool> checkItemAvailable = new List <bool>();

            //Get all the item details and store it in the list;
            List <bool>          itemListCheck = new List <bool>();
            IIterator <CartItem> iter          = new IteratorGeneric <CartItem>(cartItemList);

            while (!iter.IsDone())
            {
                int?newItemID = iter.current().itemID;
                if (newItemID != null)
                {
                    Item item = db.Items.SingleOrDefault(x => x.itemID == newItemID);
                    if (item.iQuantity < iter.current().quantity)
                    {
                        itemListCheck.Add(false);
                    }
                    else
                    {
                        itemListCheck.Add(true);
                    }
                    itemList.Add(item);

                    iter.Next();
                }
            }

            //Create a new model to contain all the data..
            List <CartViewModels> viewModel = new List <CartViewModels>();

            var updateUsers = db.Users.Single(x => x.Username == System.Web.HttpContext.Current.User.Identity.Name);

            var cartData      = new CartViewModels();
            var cartDataCarts = new Cart();

            cartDataCarts      = db.Carts.SingleOrDefault(x => x.cartID == currentCartID);
            cartData.cartItems = cartItemList;
            cartData.items     = itemList;

            double discountPercent = 0;
            double deliveryCharge  = 20;

            if (System.Web.HttpContext.Current.User.IsInRole("PremiumUser"))
            {
                discountPercent = 20;
                deliveryCharge  = 0;
            }
            else if (System.Web.HttpContext.Current.User.IsInRole("BasicUser"))
            {
                discountPercent = 10;
            }

            //Set default carts values
            cartDataCarts.gst             = 7;
            cartDataCarts.discountPercent = discountPercent;
            cartDataCarts.subTotal        = Convert.ToDouble(db.CartItems.AsEnumerable().Where(x => x.cartID == currentCartID).Sum(x => x.price));
            cartDataCarts.discountAmount  = cartDataCarts.subTotal * cartDataCarts.discountPercent / 100.0;
            cartDataCarts.deliveryCharge  = deliveryCharge;
            cartDataCarts.totalPrice      = (cartDataCarts.subTotal + deliveryCharge - cartDataCarts.discountAmount) * (1 + (cartDataCarts.gst / 100.0));

            cartData.carts = cartDataCarts;

            viewModel.Add(cartData);
            ViewBag.check = itemListCheck;
            return(View(viewModel));
        }
Ejemplo n.º 4
0
        public ActionResult OrderSummary()
        {
            updateSession();

            //Get a MAIN single cart ID
            //Get all the cart items
            int             currentCartID = Convert.ToInt32(Session["currentCart"]);
            List <CartItem> cartItemList  = db.CartItems.Where(x => x.cartID == currentCartID).ToList();

            List <Item> itemList = new List <Item>();

            //Get all the item details and store it in the list;
            IIterator <CartItem> iter = new IteratorGeneric <CartItem>(cartItemList);

            while (!iter.IsDone())
            {
                int?newItemID = iter.current().itemID;
                if (newItemID != null)
                {
                    Item newItem = db.Items.SingleOrDefault(x => x.itemID == newItemID);
                    itemList.Add(newItem);

                    //Minus Item Quantity
                    newItem.iQuantity -= 1;
                    itemGateway.Update(newItem);

                    iter.Next();
                }
            }

            //Create a new model to contain all the data..

            List <CartViewModels> viewModel = new List <CartViewModels>();

            var cartData = new CartViewModels();

            cartData.carts     = db.Carts.SingleOrDefault(x => x.cartID == currentCartID);
            cartData.cartItems = cartItemList;
            cartData.items     = itemList;

            double discountPercent = 0;
            double deliveryCharge  = 20;

            if (System.Web.HttpContext.Current.User.IsInRole("PremiumUser"))
            {
                discountPercent = 20;
                deliveryCharge  = 0;
            }
            else if (System.Web.HttpContext.Current.User.IsInRole("BasicUser"))
            {
                discountPercent = 10;
            }

            //Set default carts values
            cartData.carts.gst             = 7;
            cartData.carts.discountPercent = discountPercent;
            cartData.carts.subTotal        = Convert.ToDouble(db.CartItems.AsEnumerable().Where(x => x.cartID == currentCartID).Sum(x => x.price));
            cartData.carts.discountAmount  = cartData.carts.subTotal * cartData.carts.discountPercent / 100.0;
            cartData.carts.deliveryCharge  = deliveryCharge;
            cartData.carts.totalPrice      = (cartData.carts.subTotal + deliveryCharge - cartData.carts.discountAmount) * (1 + (cartData.carts.gst / 100.0));
            cartData.carts.dateOfPurchase  = DateTime.Now;

            //Update carts value to existing cart
            cartGateway.Update(cartData.carts);

            //Clear current user shopping cart
            Session["currentCart"] = 0;
            var updateUser = db.Users.Single(x => x.Username == System.Web.HttpContext.Current.User.Identity.Name);

            updateUser.currentCart = 0;
            userGateway.Update(updateUser);


            createNewCart();


            viewModel.Add(cartData);
            return(View());
        }