public async Task <OrderDetailsCart> GetOrderDetailsCart(Claim claim, IMenuItemRepository menuItem, string code,
                                                                 ICouponRepository couponRepository)
        {
            OrderDetailsCart order = new OrderDetailsCart
            {
                OrderHeader   = new OrderHeader(),
                ShoppingCarts = await GetShoppingCartFoUser(claim.Value)
            };

            order.OrderHeader.OrderTotal = 0;
            foreach (var VARIABLE in order.ShoppingCarts)
            {
                VARIABLE.MenuItem = await menuItem.GetItemAsync(VARIABLE.MenuItemId);

                order.OrderHeader.OrderTotal =
                    order.OrderHeader.OrderTotal + (VARIABLE.MenuItem.Price * VARIABLE.Count);
                VARIABLE.MenuItem.Description = SD.ConvertToRawHtml(VARIABLE.MenuItem.Description);
                if (VARIABLE.MenuItem.Description.Length > 100)
                {
                    VARIABLE.MenuItem.Description = VARIABLE.MenuItem.Description.Substring(0, 99) + "...";
                }
            }

            order.OrderHeader.OrderTotalOriginal = order.OrderHeader.OrderTotal;
            if (code != null)
            {
                order.OrderHeader.CouponCode = code;
                var couponFromDb =
                    await couponRepository.AllItems.Where(z =>
                                                          z.Name.ToLower() == order.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync();

                order.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, order.OrderHeader.OrderTotalOriginal);
            }
            return(order);
        }
Beispiel #2
0
        public IActionResult Index()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            ShoppingCartVM = new ShoppingCartVM()
            {
                OrderHeader = new OrderHeader(),
                ListCart    = _unitOfWork.ShoppingCart.GetAll(c => c.ApplicationUserId == claim.Value, includeProperties: "Product")
            };
            ShoppingCartVM.OrderHeader.OrderTotal      = 0;
            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser
                                                         .GetFirstOrDefault(c => c.Id == claim.Value, includeProperties: "Company");

            foreach (var cart in ShoppingCartVM.ListCart)
            {
                cart.Price = cart.Product.Price;  //Price is not mapped so we need caculator it
                ShoppingCartVM.OrderHeader.OrderTotal += (cart.Price * cart.Count);

                cart.Product.Description = SD.ConvertToRawHtml(cart.Product.Description);

                //Only show maxLengthDes of Description
                int maxLengthDes = 100;
                if (cart.Product.Description.Length > maxLengthDes)
                {
                    cart.Product.Description = cart.Product.Description.Substring(0, maxLengthDes - 1) + "...";
                }
            }

            return(View(ShoppingCartVM));
        }
        public IActionResult Index()
        {
            //get login user
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            //set instance
            ShoppingCartVM = new ShoppingCartVM()
            {
                OrderHeader = new Models.OrderHeader(),
                ListCart    = _unitOfWork.ShoppingCart.GetAll(x => x.ApplicationUserId == claim.Value
                                                              , includeProperties: "Product")
            };

            //manipulate data
            foreach (var list in ShoppingCartVM.ListCart)
            {
                list.Price = SD.GetPriceBasedOnQuantity(list.Count, list.Product.Price,
                                                        list.Product.Price50, list.Product.Price100);

                ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count);

                list.Product.Description = SD.ConvertToRawHtml(list.Product.Description);
                if (list.Product.Description.Length > 100)
                {
                    list.Product.Description = String.Format($"{list.Product.Description.Substring(0, 99)}...");
                }
            }

            return(View(ShoppingCartVM));
        }
        public IActionResult Index()
        {
            cartVM = new ShoppingCartVM
            {
                OrderHeader = new OrderHeader()
            };

            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            if (claim != null)
            {
                cartVM.ListCart = _unitOfWork.ShoppingCart.GetAll(i => i.ApplicationUserId == claim.Value, includeProperties: "Product");
                cartVM.OrderHeader.OrderTotal      = 0;
                cartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser.GetFirstOrDefault(i => i.Id == claim.Value, includeProperties: "Company");

                foreach (var item in cartVM.ListCart)
                {
                    item.Price = SD.GetPriceBasedOnQuantity(item.Count, item.Product.Price, item.Product.Price50, item.Product.Price100);
                    cartVM.OrderHeader.OrderTotal += (item.Price * item.Count);
                    item.Product.Description       = SD.ConvertToRawHtml(item.Product.Description);
                    if (item.Product.Description.Length > 100)
                    {
                        item.Product.Description = item.Product.Description.Substring(0, 99) + "...";
                    }
                }
            }

            return(View(cartVM));
        }
Beispiel #5
0
        public OrderDetailsCart PrepareForIndexCart(OrderDetailsCart detailCart)
        {
            var cart = _sessionService.GetSessionListQuantity();

            if (cart != null)
            {
                detailCart.ListCart = cart.ToList();

                foreach (var eachItem in detailCart.ListCart)
                {
                    eachItem.Item = _unitOfWork.MenuItemRepository.ReadOne(eachItem.Item.Id);
                    detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotal + (eachItem.Item.Price * eachItem.Quantity);

                    eachItem.Item.Description = SD.ConvertToRawHtml(eachItem.Item.Description);

                    if (eachItem.Item.Description.Length > 100)
                    {
                        eachItem.Item.Description = eachItem.Item.Description.Substring(0, 99) + "...";
                    }
                }

                detailCart.OrderHeader.OrderTotalOriginal = detailCart.OrderHeader.OrderTotal;
                detailCart = this.CheckCouponBeforeSumary(detailCart);
            }
            else
            {
                detailCart.ListCart = new List <MenuItemsAndQuantity>();
            }
            return(detailCart);
        }
Beispiel #6
0
        public IActionResult Index()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            ShoppingCartVM = new ShoppingCartVM()
            {
                OrderHeader = new OrderHeader(),
                ListCart    = _unitOfWork.ShoppingCart.GetAll(c => c.ApplicationUserId == claim.Value, IncludeProperties: "Product"),
            };
            ShoppingCartVM.OrderHeader.OrderTotal      = 0; //We will set it to 0 we will calculate it later in the view so we can display the total at the end
            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser
                                                         .FirstOrDefault(c => c.Id == claim.Value,
                                                                         IncludeProperties: "Company");

            //We have to iterate through out list cart to get the total based on the quantity seleted
            foreach (var list in ShoppingCartVM.ListCart)
            {
                list.Price = SD.GetPriceBasedOnQuantity(list.Count, list.Product.Price,
                                                        list.Product.Price50, list.Product.Price100);
                ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count);
                list.Product.Description = SD.ConvertToRawHtml(list.Product.Description);
                if (list.Product.Description.Length > 100)
                {
                    list.Product.Description = list.Product.Description.Substring(0, 99) + "...";
                }
            }

            return(View(ShoppingCartVM));
        }
Beispiel #7
0
        public IActionResult Summary()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            ShoppingCartVM = new ShoppingCartVM()
            {
                OrderHeader = new OrderHeader(),
                ListCart    = _unitOfWork.ShoppingCart.GetAll(x => x.ApplicationUserId == claim.Value, includeProperties: "Product")
            };

            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser.GetFirstOrDefault(x => x.Id == claim.Value,
                                                                                                       includeProperties: "Company");

            foreach (var item in ShoppingCartVM.ListCart)
            {
                item.Price = SD.GetPriceBasedOnQuantity(item.Count, item.Product.Price, item.Product.Price50, item.Product.Price100);
                ShoppingCartVM.OrderHeader.OrderTotal += (item.Price * item.Count);
                item.Product.Description = SD.ConvertToRawHtml(item.Product.Description);
            }
            ShoppingCartVM.OrderHeader.Name          = ShoppingCartVM.OrderHeader.ApplicationUser.Name;
            ShoppingCartVM.OrderHeader.PhoneNumber   = ShoppingCartVM.OrderHeader.ApplicationUser.PhoneNumber;
            ShoppingCartVM.OrderHeader.City          = ShoppingCartVM.OrderHeader.ApplicationUser.City;
            ShoppingCartVM.OrderHeader.State         = ShoppingCartVM.OrderHeader.ApplicationUser.State;
            ShoppingCartVM.OrderHeader.StreetAddress = ShoppingCartVM.OrderHeader.ApplicationUser.StreetAddress;
            ShoppingCartVM.OrderHeader.PostalCode    = ShoppingCartVM.OrderHeader.ApplicationUser.PostalCode;
            return(View(ShoppingCartVM));
        }
Beispiel #8
0
        public IActionResult Index()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            shoppingCartVM = new ShoppingCartVM()
            {
                orderHeader   = new OrderHeader(),
                shoppingCarts = _unitOfWork.ShoppingCart.GetAll(s => s.ApplicationUserId == claim.Value, includeProperties: "Product")
            };

            shoppingCartVM.orderHeader.OrderTotal        = 0;
            shoppingCartVM.orderHeader.ApplicationUserId = claim.Value;
            shoppingCartVM.orderHeader.ApplicationUser   = _unitOfWork.ApplicationUser.GetFirstOrDefault(u => u.Id == claim.Value, includeProperties: "Company");


            foreach (ShoppingCart cart in shoppingCartVM.shoppingCarts)
            {
                cart.Price = SD.GetPriceDependingOnQuantity(cart.Count, cart.Product.Price, cart.Product.Price50, cart.Product.Price100);
                shoppingCartVM.orderHeader.OrderTotal += (cart.Price * cart.Count);
                cart.Product.Description = SD.ConvertToRawHtml(cart.Product.Description ?? "");
                if (cart.Product.Description.Length > 100)
                {
                    cart.Product.Description = cart.Product.Description.Substring(0, 99) + "...";
                }
            }



            return(View(shoppingCartVM));
        }
Beispiel #9
0
        public IActionResult Summary()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            ShoppingCartVM = new ShoppingCartVM()
            {
                OrderHeader = new Models.OrderHeader(),
                ListCart    = _unitOfWork.ShoppingCart.GetAll(c => c.ApplicationUserId == claim.Value,
                                                              includeProperties: "Product")
            };

            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser
                                                         .GetFirstOrDefault(c => c.Id == claim.Value,
                                                                            includeProperties: "Company");
            foreach (var list in ShoppingCartVM.ListCart)
            {
                // Get Price based on quantity of selected product
                list.Price = SD.GetPriceBasedOnQuantity(list.Count, list.Product.Price,
                                                        list.Product.Price50, list.Product.Price100);
                // Set OrderTotal
                ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count);
                // Convert Description as RawHTML
                list.Product.Description = SD.ConvertToRawHtml(list.Product.Description);
            }

            ShoppingCartVM.OrderHeader.Name          = ShoppingCartVM.OrderHeader.ApplicationUser.Name;
            ShoppingCartVM.OrderHeader.PhoneNumber   = ShoppingCartVM.OrderHeader.ApplicationUser.PhoneNumber;
            ShoppingCartVM.OrderHeader.StreetAddress = ShoppingCartVM.OrderHeader.ApplicationUser.StreetAddress;
            ShoppingCartVM.OrderHeader.City          = ShoppingCartVM.OrderHeader.ApplicationUser.City;
            ShoppingCartVM.OrderHeader.State         = ShoppingCartVM.OrderHeader.ApplicationUser.State;
            ShoppingCartVM.OrderHeader.PostalCode    = ShoppingCartVM.OrderHeader.ApplicationUser.PostalCode;

            return(View(ShoppingCartVM));
        }
Beispiel #10
0
        public IActionResult Index()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            //only get shopping cart if user is logged in
            ShoppingCartVM = new ShoppingCartVM()
            {
                //retrieving shopping cart from Db
                OrderHeader = new Models.OrderHeader(),
                //get all the shopping cart based on user Id
                ListCart = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId == claim.Value, includeProperties: "Product")
            };
            //will calculate in the view
            ShoppingCartVM.OrderHeader.OrderTotal = 0;
            //populate Application User inside Order Header with their Company
            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser
                                                         .GetFirstOrDefault(u => u.Id == claim.Value,
                                                                            includeProperties: "Company");
            //iterate through all items in ListCart and print out the total price based on Count
            foreach (var list in ShoppingCartVM.ListCart)
            {
                list.Price = SD.GetPriceBasedOnQuantity(list.Count,
                                                        list.Product.Price,
                                                        list.Product.Price50,
                                                        list.Product.Price100);
                ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count);
                list.Product.Description = SD.ConvertToRawHtml(list.Product.Description);
                if (list.Product.Description.Length > 100)
                {
                    list.Product.Description = list.Product.Description.Substring(0, 99) + "...";
                }
            }
            return(View(ShoppingCartVM));
        }
Beispiel #11
0
        public async Task <IActionResult> Index()
        {
            detailCart = new OrderDetailsCart()
            {
                OrderHeader = new Models.OrderHeader()
            };

            //
            detailCart.OrderHeader.OrderTotal = 0;
            //---User id of logged user
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            //---Retrieve shopping cart info
            //---Get all the items that the user has
            var cart = _db.ShoppingCart.Where(c => c.ApplicationUserId == claim.Value);

            if (cart != null)
            {
                //---populate
                detailCart.listCart = cart.ToList();
            }

            //---Building the shopping cart
            //---Calculate the order total for each element of the cart
            foreach (var list in detailCart.listCart)
            {
                list.MenuItem = await _db.MenuItem.FirstOrDefaultAsync(m => m.Id == list.MenuItemId);

                //---Get the menu item loaded, get the price now
                detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotal + (list.MenuItem.Price * list.Count);
                //---Convert description to RawHTML
                list.MenuItem.Description = SD.ConvertToRawHtml(list.MenuItem.Description);
                //---display 100 chars of description
                if (list.MenuItem.Description.Length > 100)
                {
                    list.MenuItem.Description = list.MenuItem.Description.Substring(0, 99) + "...";
                }
            }
            detailCart.OrderHeader.OrderTotalOriginal = detailCart.OrderHeader.OrderTotal;
            //---Use of coupon code and update the price
            if (HttpContext.Session.GetString(SD.ssCouponCode) != null)
            {
                detailCart.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode);
                var couponFromDb = await _db.Coupon.Where(c => c.Name.ToLower() == detailCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync();

                //---Coupon Applied, updating order total
                detailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailCart.OrderHeader.OrderTotalOriginal);
            }

            return(View(detailCart));
        }
Beispiel #12
0
        public async Task <IActionResult> Index()
        {
            cartVM = new OrderDetailsCartViewModel()
            {
                OrderHeader = new Models.OrderHeader()
            };

            cartVM.OrderHeader.OrderTotal = 0;

            // get current user
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            // get users shopping cart
            var cart = _db.ShoppingCart.Where(C => C.ApplicationUserId == claim.Value);

            // cart exists
            if (cart != null)
            {
                cartVM.CartList = cart.ToList();
            }

            // iterate through items in cart, get the order total
            foreach (var item in cartVM.CartList)
            {
                item.MenuItem = await _db.MenuItem.FirstOrDefaultAsync(m => m.Id == item.MenuItemId);

                cartVM.OrderHeader.OrderTotal = cartVM.OrderHeader.OrderTotal + (item.MenuItem.Price * item.Count);
                item.MenuItem.Description     = SD.ConvertToRawHtml(item.MenuItem.Description);

                // reduce description if it exceeds 100 characters
                if (item.MenuItem.Description.Length > 100)
                {
                    item.MenuItem.Description = item.MenuItem.Description.Substring(0, 99) + "...";
                }
            }

            // set order total original - both will be the same before coupons/discount is added
            cartVM.OrderHeader.OrderTotalOriginal = cartVM.OrderHeader.OrderTotal;

            // check for that session and display the price accordingly
            if (HttpContext.Session.GetString(SD.ssCouponCode) != null)
            {
                cartVM.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode);
                var couponFromDb = await _db.Coupon.Where(c => c.Name.ToLower() == cartVM.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync();

                cartVM.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, cartVM.OrderHeader.OrderTotalOriginal);
            }

            return(View(cartVM));
        }
        public async Task <IActionResult> Index()
        {
            detailCart = new OrderDetailsCart()
            {
                OrderHeader = new Models.OrderHeader()
            };

            detailCart.OrderHeader.OrderTotal = 0;

            // get user id of the user who is logged in to retrieve all the shopping card that user has
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            // find out all the items user has added to the shopping card from the db
            var cart = _db.ShoppingCart.Where(c => c.ApplicationUserId == claim.Value);

            if (cart != null)
            {
                detailCart.listCart = cart.ToList();
            }

            // calculate order total iterate through to the list card to find the order total
            foreach (var list in detailCart.listCart)
            {
                list.MenuItem = await _db.MenuItem.FirstOrDefaultAsync(m => m.Id == list.MenuItemId);

                detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotal + (list.MenuItem.Price * list.Count);
                list.MenuItem.Description         = SD.ConvertToRawHtml(list.MenuItem.Description);

                /*
                 *  if the description is longer than 100 characters
                 *  then show only first 99 characters and three dots
                 */
                if (list.MenuItem.Description.Length > 100)
                {
                    list.MenuItem.Description = list.MenuItem.Description.Substring(0, 99) + "...";
                }
            }
            detailCart.OrderHeader.OrderTotalOriginal = detailCart.OrderHeader.OrderTotal;

            // check if the customer has entered coupon code
            if (HttpContext.Session.GetString(SD.ssCouponCode) != null)
            {
                detailCart.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode);
                var couponFromDb = await _db.Coupon.Where(c => c.Name.ToLower() == detailCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync();

                detailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailCart.OrderHeader.OrderTotalOriginal);
            }

            return(View(detailCart));
        }
Beispiel #14
0
        public async Task <IActionResult> Index()
        {
            //initilize the viewModel
            detailCart = new OrderDetailsCart()
            {
                OrderHeader = new OrderHeader()
            };

            detailCart.OrderHeader.OrderTotal = 0;

            //get the user id in order to get their shopping cart
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
            //get the shopping cart by the user id
            var cart = _db.ShoppingCart.Where(c => c.ApplicationUserId == claim.Value);

            if (cart != null)
            {
                detailCart.listCart = cart.ToList();
            }

            //compute the order total
            foreach (var list in detailCart.listCart)
            {
                list.MenuItem = await _db.MenuItem.FirstOrDefaultAsync(m => m.Id == list.MenuItemId);

                detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotal + (list.MenuItem.Price * list.Count);

                list.MenuItem.Description = SD.ConvertToRawHtml(list.MenuItem.Description);
                // i just want the first 100 characters, no html tag
                if (list.MenuItem.Description.Length > 100)
                {
                    list.MenuItem.Description = list.MenuItem.Description.Substring(0, 99) + "...";
                }
            }

            //before they use the coupon we make sure the total is the same
            detailCart.OrderHeader.OrderTotalOriginal = detailCart.OrderHeader.OrderTotal;

            if (HttpContext.Session.GetString(SD.ssCouponCode) != null)
            {
                detailCart.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode);
                var couponFromDb = await _db.Coupon.Where(c => c.Name == detailCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync();

                //calculate the total
                detailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailCart.OrderHeader.OrderTotalOriginal);
            }

            return(View(detailCart));
        }
Beispiel #15
0
        public async Task <IActionResult> Summary()
        {
            detailCart = new OrderDetailsCart()
            {
                OrderHeader = new OrderHeader()
            };
            detailCart.OrderHeader.OrderTotal = 0;

            var             claimsIdentity  = (ClaimsIdentity)User.Identity;
            var             claim           = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
            ApplicationUser applicationUser = await _db.ApplicationUser.Where(c => c.Id == claim.Value).FirstOrDefaultAsync();

            var cart = _db.ShoppingCart.Where(c => c.ApplicationUserId == claim.Value);

            if (cart != null)
            {
                detailCart.listCart = cart.ToList();
            }

            foreach (var list in detailCart.listCart)
            {
                list.MenuItem = await _db.MenuItem.FirstOrDefaultAsync(m => m.Id == list.MenuItemId);

                detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotal + (list.MenuItem.Price * list.Count);
                list.MenuItem.Description         = SD.ConvertToRawHtml(list.MenuItem.Description);

                if (list.MenuItem.Description.Length > 100)
                {
                    list.MenuItem.Description = list.MenuItem.Description.Substring(0, 99) + "...";
                }
            }

            detailCart.OrderHeader.OrderTotalOriginal = detailCart.OrderHeader.OrderTotal;
            detailCart.OrderHeader.PickupName         = applicationUser.Name;
            detailCart.OrderHeader.PhoneNumber        = applicationUser.PhoneNumber;
            detailCart.OrderHeader.PickupTime         = DateTime.Now;


            if (HttpContext.Session.GetString(SD.ssCouponCode) != null)
            {
                detailCart.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode);

                var couponFromDb = await _db.Coupon.Where(s => s.Name.ToLower() == detailCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync();

                detailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailCart.OrderHeader.OrderTotalOriginal);
            }

            return(View(detailCart));
        }
Beispiel #16
0
        public async Task <IActionResult> Index()
        {
            DetailCart = new OrderDetailsCart()
            {
                OrderHeader = new OrderHeader()
            };

            DetailCart.OrderHeader.OrderTotal = 0;

            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            var cart = _context.ShoppingCarts.Include(sc => sc.MenuItem).Where(c => c.ApplicationUserId == claim.Value);

            if (claim != null)
            {
                DetailCart.ListCart = await cart.ToListAsync();
            }

            foreach (var list in DetailCart.ListCart)
            {
                list.MenuItem = await _context.MenuItems.FirstOrDefaultAsync(m => m.Id == list.MenuItem.Id);

                DetailCart.OrderHeader.OrderTotal += list.MenuItem.Price * list.Count;
                list.MenuItem.Description          = SD.ConvertToRawHtml(list.MenuItem.Description);

                if (list.MenuItem.Description.Length > 100)
                {
                    list.MenuItem.Description = $"{list.MenuItem.Description.Substring(0, 99)}...";
                }
            }

            DetailCart.OrderHeader.OrderTotalOriginal = DetailCart.OrderHeader.OrderTotal;

            if (HttpContext.Session.GetString(SD.ssCouponCode) == null)
            {
                return(View(DetailCart));
            }
            {
                DetailCart.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode);
                var couponFromDb = await _context.Coupons
                                   .Where(c => c.Name.ToLower() == DetailCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync();

                DetailCart.OrderHeader.OrderTotal =
                    SD.DiscountedPrice(couponFromDb, DetailCart.OrderHeader.OrderTotalOriginal);
            }

            return(View(DetailCart));
        }
Beispiel #17
0
        public IActionResult Index()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            ShoppingCartVM = new ShoppingCartVM()
            {
                OrderHeader = new Models.OrderHeader(),
                ListCart    = _unitOfWork.ShoppingCart
                              .GetAll(u => u.ApplicationUserId == claim.Value, includeProperties: "Product").ToList()
            };
            ShoppingCartVM.OrderHeader.OrderTotalOriginal = 0;

            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser
                                                         .GetFirstOrDefault(u => u.Id == claim.Value);

            foreach (var list in ShoppingCartVM.ListCart)
            {
                list.Price = list.Product.Price;
                ShoppingCartVM.OrderHeader.OrderTotalOriginal += (list.Price * list.Count);
                list.Product.Description = SD.ConvertToRawHtml(list.Product.Description);
                if (list.Product.Description.Length > 100)
                {
                    list.Product.Description = list.Product.Description.Substring(0, 99) + "...";
                }
            }
            ShoppingCartVM.OrderHeader.OrderTotal = ShoppingCartVM.OrderHeader.OrderTotalOriginal;


            if (HttpContext.Session.GetString(SD.ssCouponCode) != null)
            {
                ShoppingCartVM.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode);
                var couponFromDb = _unitOfWork.Coupon.GetFirstOrDefault(c => c.Name.ToLower() == ShoppingCartVM.OrderHeader.CouponCode.ToLower());
                ShoppingCartVM.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, ShoppingCartVM.OrderHeader.OrderTotalOriginal);
            }


            //if (CouponString != null)
            //{
            //    ShoppingCartVM.OrderHeader.CouponCode = CouponString;
            //    var couponFromDb = _unitOfWork.Coupon.GetFirstOrDefault(c => c.Name.ToLower() == ShoppingCartVM.OrderHeader.CouponCode.ToLower());
            //    ShoppingCartVM.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, ShoppingCartVM.OrderHeader.OrderTotalOriginal);

            //}


            return(View(ShoppingCartVM));
        }
        public async Task <IActionResult> Index()
        {
            DetailCart = new OrderDetailsCart
            {
                OrderHeader = new Models.OrderHeader()
            };
            DetailCart.OrderHeader.OrderTotal = 0;
            var userId = (this.User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.NameIdentifier).Value;

            DetailCart.OrderHeader.AppUserId = userId;
            var cart = db.ShoppingCarts.Where(c => c.AppUserId == userId);

            if (cart != null)
            {
                DetailCart.ShoppingCarts = cart.ToList();
            }
            foreach (var item in DetailCart.ShoppingCarts)
            {
                item.MenuItem = await db.MenuItems.FirstOrDefaultAsync(c => c.Id == item.MenuItemId);

                DetailCart.OrderHeader.OrderTotal += (item.MenuItem.Price * item.Count);
                item.MenuItem.Description          = SD.ConvertToRawHtml(item.MenuItem.Description);
                if (item.MenuItem.Description.Length > 100)
                {
                    item.MenuItem.Description = item.MenuItem.Description.Substring(0, 99) + "...";
                }
            }
            DetailCart.OrderHeader.OrderTotalOriginal = DetailCart.OrderHeader.OrderTotal;

            if (HttpContext.Session.GetString(SD.CartCoupon) != null)
            {
                DetailCart.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.CartCoupon);
                var coupon = await db.Coupons.SingleOrDefaultAsync(c => c.Name.ToLower() == DetailCart.OrderHeader.CouponCode.ToLower());

                if (coupon == null)
                {
                    ViewBag.InvalidCoupon = "Coupon is expired or Not valid";
                }
                DetailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(coupon, DetailCart.OrderHeader.OrderTotalOriginal);
            }
            var discount = DetailCart.OrderHeader.OrderTotalOriginal - DetailCart.OrderHeader.OrderTotal;

            if (discount > 0)
            {
                ViewBag.CStatus = SD.CouponApplied;
            }
            return(View(DetailCart));
        }
Beispiel #19
0
        public IActionResult Index()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            ShoppingCartVM = new ShoppingCartVM()
            {
                OrderHeader = new Models.OrderHeader(),
                ListCart    = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId == claim.Value, includeProperties: "Product,Sweetness,Sweetener,Topping,IceCubes,MilkTypes,Origins")
            };
            ShoppingCartVM.OrderHeader.OrderTotal      = 0;
            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser
                                                         .GetFirstOrDefault(u => u.Id == claim.Value,
                                                                            includeProperties: "Company");

            var customerPreferences = _context.CustomerPreferences.Where(x => x.ApplicationUserId == claim.Value).ToList();

            foreach (var list in ShoppingCartVM.ListCart)
            {
                list.Price = SD.GetPriceBasedOnQuantity(list.Count, list.Product.Price,
                                                        list.Product.Price50, list.Product.Price100);
                ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count);
                list.Product.Description = SD.ConvertToRawHtml(list.Product.Description);
                if (list.Product.Description.Length > 100)
                {
                    list.Product.Description = list.Product.Description.Substring(0, 99) + "...";
                }

                /*
                 * list.Sweetness = customerPreferences.Where(x => x.ProductId == list.ProductId).FirstOrDefault().Sweetness;
                 * list.SweetnessId = customerPreferences.Where(x => x.ProductId == list.ProductId).FirstOrDefault().SweetnessId;
                 *
                 * list.SweetenerId = customerPreferences.Where(x => x.ProductId == list.ProductId).FirstOrDefault().SweetenerId;
                 * list.Sweetener = customerPreferences.Where(x => x.ProductId == list.ProductId).FirstOrDefault().Sweetener;
                 * list.ToppingId = customerPreferences.Where(x => x.ProductId == list.ProductId).FirstOrDefault().ToppingId;
                 * list.Topping = customerPreferences.Where(x => x.ProductId == list.ProductId).FirstOrDefault().Topping;
                 * list.IceCubeId= customerPreferences.Where(x => x.ProductId == list.ProductId).FirstOrDefault().IceCubeId;
                 * list.IceCubes= customerPreferences.Where(x => x.ProductId == list.ProductId).FirstOrDefault().IceCubes;
                 * list.MilkTypeId = customerPreferences.Where(x => x.ProductId == list.ProductId).FirstOrDefault().MilkTypeId;
                 * list.MilkTypes = customerPreferences.Where(x => x.ProductId == list.ProductId).FirstOrDefault().MilkTypes;
                 * list.OriginId = customerPreferences.Where(x => x.ProductId == list.ProductId).FirstOrDefault().OriginId;
                 * list.Origins = customerPreferences.Where(x => x.ProductId == list.ProductId).FirstOrDefault().Origins;
                 */
            }


            return(View(ShoppingCartVM));
        }
Beispiel #20
0
        private void FormatShoppingCart(ShoppingCartVM shoppingCartVM)
        {
            foreach (var shoppingCart in shoppingCartVM.ListCart)
            {
                shoppingCart.Price = SetPrice(shoppingCart);

                shoppingCartVM.OrderHeader.OrderTotal += (shoppingCart.Price * shoppingCart.Count);

                shoppingCart.Product.Description = SD.ConvertToRawHtml(shoppingCart.Product.Description);

                if (shoppingCart.Product.Description.Length > 100)
                {
                    shoppingCart.Product.Description = shoppingCart.Product.Description.Substring(0, 99) + "...";
                }
            }
        }
Beispiel #21
0
        public async Task <IActionResult> Index()
        {
            detailCart = new OrderDetailsCart()
            {
                OrderHeader = new Models.OrderHeader()
            };
            detailCart.OrderHeader.OrderTotal = 0;

            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            var cart = _db.ShoppingCart.Where(c => c.ApplicationUserId == claim.Value);

            if (cart != null)
            {
                detailCart.ListCart = cart.ToList();
            }

            foreach (var list in detailCart.ListCart)
            {
                list.MenuItem = await _db.MenuItem.FirstOrDefaultAsync(m => m.Id == list.MenuItemId);

                detailCart.OrderHeader.OrderTotal =
                    detailCart.OrderHeader.OrderTotal + (list.MenuItem.Price * list.Count);

                list.MenuItem.Description = SD.ConvertToRawHtml(list.MenuItem.Description);
                //in case we dont want to display the entire description.Lets just say that we display the first 100 characters
                if (list.MenuItem.Description.Length > 100)
                {
                    list.MenuItem.Description = list.MenuItem.Description.Substring(0, 99) + "...";
                }
            }

            detailCart.OrderHeader.OrderTotalOriginal = detailCart.OrderHeader.OrderTotal;

            if (HttpContext.Session.GetString(SD.ssCouponCode) != null)
            {
                //means that there is a coupon code
                detailCart.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode);
                var couponFromDb = await _db.Coupon
                                   .Where(c => c.Name.ToLower() == detailCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync();

                detailCart.OrderHeader.OrderTotal =
                    SD.DiscountedPrice(couponFromDb, detailCart.OrderHeader.OrderTotalOriginal);
            }
            return(View(detailCart));
        }