public IActionResult Minus(int cartId)
        {
            //retrieve cart
            var cart = _unitOfWork.ShoppingCart
                       .GetFirstOrDefault(x => x.Id == cartId, includeProperties: "Product");

            //if cart was last item, then we need to remove them at db
            if (cart.Count == 1)
            {
                var count = _unitOfWork.ShoppingCart.GetAll
                                (x => x.ApplicationUserId == cart.ApplicationUserId).ToList().Count;

                _unitOfWork.ShoppingCart.Remove(cart);
                _unitOfWork.Save();

                HttpContext.Session.SetObj(SD.ssShoppingCart, count - 1);
            }
            else
            {
                cart.Count -= 1;

                //update price if there archive some of amount
                cart.Price = SD.GetPriceBasedOnQuantity
                                 (cart.Count, cart.Product.Price, cart.Product.Price50, cart.Product.Price100);

                _unitOfWork.Save();
            }

            return(RedirectToAction(nameof(Index)));
        }
Exemple #2
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(c => c.ApplicationUserId == claim.Value,
                                                              IncludeProperties: "Product")
            };

            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);
            }

            //We are poplulating our order header property from our application user
            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));
        }
        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")
            };
            ShoppingCartVM.OrderHeader.OrderTotal      = 0;
            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser
                                                         .GetFirstOrDefault(u => u.Id == claim.Value,
                                                                            includeProperties: "Company");

            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));
        }
Exemple #4
0
        public IActionResult Minus(int cartId)
        {
            // get from db
            var cart = _unitOfWork.ShoppingCart.GetFirstOrDefault(c => c.Id == cartId,
                                                                  includeProperties: "Product");

            // if it is the last one item remove it from Cart
            if (cart.Count == 1)
            {
                // get total count
                var cnt = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId == cart.ApplicationUserId).ToList().Count;
                // remove from cart
                _unitOfWork.ShoppingCart.Remove(cart);
                _unitOfWork.Save();

                // remove from Session
                HttpContext.Session.SetInt32(SD.ssShoppingCart, cnt - 1);
            }
            else
            {
                // decrement every time
                cart.Count -= 1;

                // change Price based on new quantity
                cart.Price = SD.GetPriceBasedOnQuantity(cart.Count, cart.Product.Price,
                                                        cart.Product.Price50, cart.Product.Price100);
                _unitOfWork.Save();
            }

            return(RedirectToAction(nameof(Index)));
        }
Exemple #5
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));
        }
        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 Minus(int cartId)
        {
            var cart = _unitOfWork.ShoppingCart.GetFirstOrDefault
                           (c => c.Id == cartId, includeProperties: "Product");

            if (cart.Count == 1)
            {
                var cnt = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId ==
                                                          cart.ApplicationUserId).ToList().Count;

                _unitOfWork.ShoppingCart.Remove(cart);
                _unitOfWork.Save();

                HttpContext.Session.SetInt32(SD.ssShoppingCart, cnt - 1);
            }
            else
            {
                cart.Count -= 1;
                cart.Price  = SD.GetPriceBasedOnQuantity(cart.Count, cart.Product.Price,
                                                         cart.Product.Price50, cart.Product.Price100);
                _unitOfWork.Save();
            }

            return(RedirectToAction(nameof(Index)));
        }
        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)
            {
                list.Price = SD.GetPriceBasedOnQuantity(list.Count, list.Product.Price,
                                                        list.Product.Price50, list.Product.Price100);
                ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count);
            }
            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));
        }
Exemple #9
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));
        }
        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));
        }
Exemple #11
0
        public IActionResult Minus(int cartId)
        {
            //retrieve from shopping cart
            var cart = _unitOfWork.ShoppingCart.GetFirstOrDefault
                           (c => c.Id == cartId, includeProperties: "Product");

            //check if cart number is 1 then we delete one as well as remove it
            //from Session and the Shopping Cart model since it's the last item in Shopping cart
            if (cart.Count == 1)
            {
                var cnt = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId == cart.ApplicationUserId)
                          .ToList().Count();
                _unitOfWork.ShoppingCart.Remove(cart);
                _unitOfWork.Save();
                HttpContext.Session.SetInt32(SD.ssShoppingCart, cnt - 1);
            }
            else
            {
                cart.Count -= 1;
                //update item
                cart.Price = SD.GetPriceBasedOnQuantity
                                 (cart.Count, cart.Product.Price, cart.Product.Price50, cart.Product.Price100);
                _unitOfWork.Save();
            }
            return(RedirectToAction(nameof(Index)));
        }
        public IActionResult Summary()
        {
            cartVM = new ShoppingCartVM
            {
                OrderHeader = new OrderHeader()
            };

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

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

                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);
                }

                cartVM.OrderHeader.Name          = cartVM.OrderHeader.ApplicationUser.Name;
                cartVM.OrderHeader.PhoneNumber   = cartVM.OrderHeader.ApplicationUser.PhoneNumber;
                cartVM.OrderHeader.StreetAddress = cartVM.OrderHeader.ApplicationUser.StreetAddress;
                cartVM.OrderHeader.City          = cartVM.OrderHeader.ApplicationUser.City;
                cartVM.OrderHeader.State         = cartVM.OrderHeader.ApplicationUser.State;
                cartVM.OrderHeader.PostalCode    = cartVM.OrderHeader.ApplicationUser.PostalCode;
            }

            return(View(cartVM));
        }
Exemple #13
0
 private double SetPrice(ShoppingCart cart)
 {
     return(SD.GetPriceBasedOnQuantity(cart.Count,
                                       cart.Product.Price,
                                       cart.Product.Price50,
                                       cart.Product.Price100));
 }
Exemple #14
0
        public IActionResult Minus(int cartId)
        {
            // get shopping cart
            var cart = _unitOfWork.ShoppingCart
                       .GetFirstOrDefault(c => c.Id == cartId, includeProperties: "Product");

            // if cart quantity is 1, then we have to remove it from the shopping cart
            if (cart.Count == 1)
            {
                // get shopping cart length
                var cnt = _unitOfWork.ShoppingCart
                          .GetAll(u => u.ApplicationUserId == cart.ApplicationUserId)
                          .ToList().Count();

                // remove cart record from shopping cart
                _unitOfWork.ShoppingCart.Remove(cart);
                _unitOfWork.Save();

                // update session
                HttpContext.Session.SetInt32(SD.ssShoppingCart, cnt - 1);
            }
            else
            {
                // decrement quantity
                cart.Count -= 1;
                // update pricing
                cart.Price = SD.GetPriceBasedOnQuantity(cart.Count, cart.Product.Price,
                                                        cart.Product.Price50, cart.Product.Price100);

                _unitOfWork.Save();
            }

            return(RedirectToAction(nameof(Index)));
        }
Exemple #15
0
        public IActionResult Index()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            //retrieving shopping cart from database
            ShoppingCartVM = new ShoppingCartVM()
            {
                OrderHeader = new Models.OrderHeader(),
                ListCart    = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId == claim.Value, includePoreperties: "Product"),
            };
            //get applicationuser with company
            ShoppingCartVM.OrderHeader.OrderTotal      = 0;
            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser.GetFirstOrDefault(u => u.Id == claim.Value, includePoreperties: "Company");

            //iterating through all of the items to calculate the price based on the 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));
        }
 public IActionResult Plus(int cartId)
 {
     var cart = _unitOfWork.ShoppingCart.GetFirstOrDefault(c => c.Id == cartId, includeProperties: "Product");
     cart.Count += 1;
     cart.Price = SD.GetPriceBasedOnQuantity(cart.Count, cart.Product.Price, cart.Product.Price50, cart.Product.Price100);
     _unitOfWork.Save();
     return RedirectToAction(nameof(Index));
 }
Exemple #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,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));
        }
Exemple #18
0
        public IActionResult Plus(int cartId)
        {
            // get from db
            var cart = _unitOfWork.ShoppingCart.GetFirstOrDefault(c => c.Id == cartId,
                                                                  includeProperties: "Product");

            // increment every time
            cart.Count += 1;

            // change Price based on new quantity
            cart.Price = SD.GetPriceBasedOnQuantity(cart.Count, cart.Product.Price,
                                                    cart.Product.Price50, cart.Product.Price100);
            _unitOfWork.Save();

            return(RedirectToAction(nameof(Index)));
        }
        public IActionResult Plus(int cartId)
        {
            //retrieve cart
            var cart = _unitOfWork.ShoppingCart
                       .GetFirstOrDefault(x => x.Id == cartId, includeProperties: "Product");

            cart.Count += 1;

            //update price if there archive some of amount
            cart.Price = SD.GetPriceBasedOnQuantity
                             (cart.Count, cart.Product.Price, cart.Product.Price50, cart.Product.Price100);

            _unitOfWork.Save();

            return(RedirectToAction(nameof(Index)));
        }
Exemple #20
0
        public IActionResult SummaryPost()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

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

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

            ShoppingCartVM.OrderHeader.PaymentStatus     = SD.PaymentStatusPending;
            ShoppingCartVM.OrderHeader.OrderStatus       = SD.StatusPending;
            ShoppingCartVM.OrderHeader.ApplicationUserId = claim.Value;
            ShoppingCartVM.OrderHeader.OrderDate         = DateTime.Now;

            _unitOfWork.OrderHeader.Add(ShoppingCartVM.OrderHeader);
            _unitOfWork.Save();

            List <OrderDetails> orderDetailsList = new List <OrderDetails>();

            foreach (var item in ShoppingCartVM.ListCart)
            {
                item.Price = SD.GetPriceBasedOnQuantity(item.Count, item.Product.Price,
                                                        item.Product.Price50, item.Product.Price100);
                OrderDetails orderDetails = new OrderDetails()
                {
                    ProductId = item.ProductId,
                    OrderId   = ShoppingCartVM.OrderHeader.Id,
                    Price     = item.Price,
                    Count     = item.Count
                };
                ShoppingCartVM.OrderHeader.OrderTotal += orderDetails.Count * orderDetails.Price;
                _unitOfWork.OrderDetails.Add(orderDetails);
            }

            _unitOfWork.ShoppingCart.RemoveRange(ShoppingCartVM.ListCart);
            _unitOfWork.Save();
            HttpContext.Session.SetInt32(SD.ssShoppingCart, 0);


            _unitOfWork.Save();

            return(RedirectToAction("OrderConfirmation", "Cart", new { id = ShoppingCartVM.OrderHeader.Id }));
        }
Exemple #21
0
        public IActionResult Index()
        {
            // get currently logged in user
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            // init new shopping card viewmodel
            // creating a new order header and populating ListCart with the users shopping cart from the db
            ShoppingCartVM = new ShoppingCartVM()
            {
                OrderHeader = new Models.OrderHeader(),
                ListCart    = _unitOfWork.ShoppingCart
                              .GetAll(u => u.ApplicationUserId == claim.Value, includeProperties: "Product")
            };

            // initial value of properties
            ShoppingCartVM.OrderHeader.OrderTotal      = 0;
            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser
                                                         .GetFirstOrDefault(u => u.Id == claim.Value, includeProperties: "Company");

            // iterate through all of the items inside the ListCart to calculate price
            foreach (var list in ShoppingCartVM.ListCart)
            {
                // get price of the product based on the quantity
                list.Price = SD.GetPriceBasedOnQuantity(list.Count, list.Product.Price,
                                                        list.Product.Price50, list.Product.Price100);

                // set the order total to the recieved price and quantity
                ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count);

                // convert description to Html
                list.Product.Description = SD.ConvertToRawHtml(list.Product.Description);

                // we only want to show 100 characters of the description
                if (list.Product.Description.Length > 100)
                {
                    list.Product.Description = list.Product.Description.Substring(0, 99) + "...";
                }
            }

            return(View(ShoppingCartVM));
        }
Exemple #22
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)
            {
                list.Price = SD.GetPriceBasedOnQuantity(list.Count, list.Product.Price,
                                                        list.Product.Price50, list.Product.Price100);
                //list.SweetenerId = _context.CustomerPreferences.Where(x => x.ApplicationUserId == list.ApplicationUserId && x.ProductId==list.ProductId).FirstOrDefault().SweetenerId;
                ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count);
            }
            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;

            List <ApplicationUser> applicationUser = _context.ApplicationUsers.ToList();

            applicationUser.Insert(0, new ApplicationUser {
                Id = "0", UserName = "******"
            });
            ViewData["ApplicationUserId"] = new SelectList(applicationUser, "Id", "UserName");

            return(View(ShoppingCartVM));
        }
Exemple #23
0
        public IActionResult Minus(int cartID)
        {
            var cart = _unitOfWork.ShoppingCartRepository.GetFirstOrDefault(c => c.Id == cartID, includeProperties: "Product");

            if (cart.Count == 1)
            {
                var cnt = _unitOfWork.ShoppingCartRepository.GetAll(u => u.ApplicationUserId == cart.ApplicationUserId).ToList().Count;
                _unitOfWork.ShoppingCartRepository.Remove(cart);
                _unitOfWork.Save();
                HttpContext.Session.SetInt32(SD.SessionShoppingCart, cnt - 1);
            }
            else
            {
                cart.Count--;
                cart.Price = SD.GetPriceBasedOnQuantity(cart.Count, cart.Product.Price, cart.Product.Price50, cart.Product.Price100);
                _unitOfWork.Save();
            }
            string redirectUrl = Url.Action("Index");

            return(Json(new { redirectUrl }));
            //            return RedirectToAction(nameof(Index));
        }
Exemple #24
0
        public IActionResult Summary()
        {
            // get currently logged in user
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

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

            // populate the application user inside order header
            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser
                                                         .GetFirstOrDefault(c => c.Id == claim.Value, includeProperties: "Company");

            // iterate through all of the items inside the ListCart to calculate price
            foreach (var list in ShoppingCartVM.ListCart)
            {
                // get price of the product based on the quantity
                list.Price = SD.GetPriceBasedOnQuantity(list.Count, list.Product.Price,
                                                        list.Product.Price50, list.Product.Price100);

                // set the order total to the recieved price and quantity
                ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count);
            }

            // populate the order header property from the application user.
            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.Province      = ShoppingCartVM.OrderHeader.ApplicationUser.Province;
            ShoppingCartVM.OrderHeader.PostalCode    = ShoppingCartVM.OrderHeader.ApplicationUser.PostalCode;

            return(View(ShoppingCartVM));
        }
Exemple #25
0
        public IActionResult Index()
        {
            // get UserId of logged-in user
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            ShoppingCartVM = new ShoppingCartVM()
            {
                OrderHeader = new Models.OrderHeader(),
                // get all items for loggedin user
                ListCart = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId == claim.Value, includeProperties: "Product")
            };

            // calculate orderTotal in View
            ShoppingCartVM.OrderHeader.OrderTotal = 0;
            // get User with Company
            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser.
                                                         GetFirstOrDefault(u => u.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);
                // Shorten Description to 100 chars
                if (list.Product.Description.Length > 100)
                {
                    list.Product.Description = list.Product.Description.Substring(0, 99) + "...";
                }
            }

            return(View(ShoppingCartVM));
        }
        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: "AutoPart")
            };
            ShoppingCartVM.OrderHeader.OrderTotal      = 0;
            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser
                                                         .GetFirstOrDefault(u => u.Id == claim.Value,
                                                                            includeProperties: "Showroom");

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


            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);
            }

            return(View(ShoppingCartVM));
        }
        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: "AutoPart")
            };
            ShoppingCartVM.OrderHeader.OrderTotal      = 0;
            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser
                                                         .GetFirstOrDefault(c => c.Id == claim.Value,
                                                                            includeProperties: "Showroom");

            foreach (var list in ShoppingCartVM.ListCart)
            {
                list.Price = SD.GetPriceBasedOnQuantity(list.Count, list.AutoPart.Price,
                                                        list.AutoPart.Price50, list.AutoPart.Price100);
                ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count);
            }
            ShoppingCartVM.OrderHeader.OrderTotalOriginal = ShoppingCartVM.OrderHeader.OrderTotal;

            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;
            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);
            }
            return(View(ShoppingCartVM));
        }
Exemple #28
0
        public IActionResult Index()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            ShoppingCartVM = new ShoppingCartVM()
            {
                OrderHeader = new Model.OrderHeader(),
                ListCart    = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId == claim.Value, includeProperties: "Product")
            };
            ShoppingCartVM.OrderHeader.OrderTotal      = 0;
            ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser
                                                         .GetFirstOrDefault(u => u.Id == claim.Value,
                                                                            includeProperties: "Company");
            //The code below will be used to calculate the total amount of product
            foreach (var list in ShoppingCartVM.ListCart)
            {
                //Remember the price property is not mapped because you will need to calculate it for each different products.
                list.Price = SD.GetPriceBasedOnQuantity
                             (
                    list.Count,
                    list.Product.Price,
                    list.Product.Price50,
                    list.Product.Price100
                             );
                //ShoppingCartVM.OrderHeader.OrderTotal = (list.Price * list.Count) + ShoppingCartVM.OrderHeader.OrderTotal;
                ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count);
                //The code below is used to show the description of the products
                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));
        }
        public IActionResult SummaryPost(string stripeToken)
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

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

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

            ShoppingCartVM.OrderHeader.PaymentStatus     = SD.PaymentStatusPending;
            ShoppingCartVM.OrderHeader.OrderStatus       = SD.StatusPending;
            ShoppingCartVM.OrderHeader.ApplicationUserId = claim.Value;
            ShoppingCartVM.OrderHeader.OrderDate         = DateTime.Now;

            _unitOfWork.OrderHeader.Add(ShoppingCartVM.OrderHeader);
            _unitOfWork.Save();

            List <OrderDetails> orderDetailsList = new List <OrderDetails>();

            foreach (var item in ShoppingCartVM.ListCart)
            {
                item.Price = SD.GetPriceBasedOnQuantity(item.Count, item.Product.Price,
                                                        item.Product.Price50, item.Product.Price100);
                OrderDetails orderDetails = new OrderDetails()
                {
                    ProductId = item.ProductId,
                    OrderId   = ShoppingCartVM.OrderHeader.Id,
                    Price     = item.Price,
                    Count     = item.Count
                };
                ShoppingCartVM.OrderHeader.OrderTotal += orderDetails.Count * orderDetails.Price;
                _unitOfWork.OrderDetails.Add(orderDetails);
            }

            _unitOfWork.ShoppingCart.RemoveRange(ShoppingCartVM.ListCart);
            _unitOfWork.Save();
            HttpContext.Session.SetInt32(SD.ssShoppingCart, 0);

            if (stripeToken == null)
            {
                //order will be created for delayed payment for authroized company
                ShoppingCartVM.OrderHeader.PaymentDueDate = DateTime.Now.AddDays(30);
                ShoppingCartVM.OrderHeader.PaymentStatus  = SD.PaymentStatusDelayedPayment;
                ShoppingCartVM.OrderHeader.OrderStatus    = SD.StatusApproved;
            }
            else
            {
                //process the payment
                var options = new ChargeCreateOptions
                {
                    Amount      = Convert.ToInt32(ShoppingCartVM.OrderHeader.OrderTotal * 100),
                    Currency    = "usd",
                    Description = "Order ID : " + ShoppingCartVM.OrderHeader.Id,
                    Source      = stripeToken
                };

                var    service = new ChargeService();
                Charge charge  = service.Create(options);

                if (charge.BalanceTransactionId == null)
                {
                    ShoppingCartVM.OrderHeader.PaymentStatus = SD.PaymentStatusRejected;
                }
                else
                {
                    ShoppingCartVM.OrderHeader.TransactionId = charge.BalanceTransactionId;
                }
                if (charge.Status.ToLower() == "succeeded")
                {
                    ShoppingCartVM.OrderHeader.PaymentStatus = SD.PaymentStatusApproved;
                    ShoppingCartVM.OrderHeader.OrderStatus   = SD.StatusApproved;
                    ShoppingCartVM.OrderHeader.PaymentDate   = DateTime.Now;
                }
            }

            _unitOfWork.Save();

            return(RedirectToAction("OrderConfirmation", "Cart", new { id = ShoppingCartVM.OrderHeader.Id }));
        }
        public IActionResult SummaryPost()
        {
            var claimsIdentity = (ClaimsIdentity)User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

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

            ShoppingCartVM.ListCart = _unitOfWork.ShoppingCart
                                      .GetAll(c => c.ApplicationUserId == claim.Value,
                                              includeProperties: "AutoPart");

            ShoppingCartVM.OrderHeader.PaymentStatus     = SD.PaymentStatusPending;
            ShoppingCartVM.OrderHeader.OrderStatus       = SD.StatusPending;
            ShoppingCartVM.OrderHeader.ApplicationUserId = claim.Value;
            ShoppingCartVM.OrderHeader.OrderDate         = DateTime.Now;
            ShoppingCartVM.OrderHeader.ShippingDate      = DateTime.Now.AddDays(7);
            _unitOfWork.OrderHeader.Add(ShoppingCartVM.OrderHeader);
            _unitOfWork.Save();
            ShoppingCartVM.OrderHeader.OrderTotalOriginal = 0;

            foreach (var item in ShoppingCartVM.ListCart)
            {
                item.Price = SD.GetPriceBasedOnQuantity(item.Count, item.AutoPart.Price,
                                                        item.AutoPart.Price50, item.AutoPart.Price100);
                OrderDetails orderDetails = new OrderDetails()
                {
                    AutoPartId = item.AutoPartId,
                    OrderId    = ShoppingCartVM.OrderHeader.Id,
                    Price      = item.Price,
                    Count      = item.Count
                };
                ShoppingCartVM.OrderHeader.OrderTotalOriginal += orderDetails.Count * orderDetails.Price;
                _unitOfWork.OrderDetails.Add(orderDetails);
            }

            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);
            }
            else
            {
                ShoppingCartVM.OrderHeader.OrderTotal = ShoppingCartVM.OrderHeader.OrderTotalOriginal;
            }
            ShoppingCartVM.OrderHeader.CouponCodeDiscount = ShoppingCartVM.OrderHeader.OrderTotalOriginal - ShoppingCartVM.OrderHeader.OrderTotal;

            _unitOfWork.ShoppingCart.RemoveRange(ShoppingCartVM.ListCart);
            _unitOfWork.Save();
            HttpContext.Session.SetInt32(SD.ssShoppingCart, 0);



            //process the payment



            ShoppingCartVM.OrderHeader.PaymentStatus = SD.PaymentStatusRejected;



            ShoppingCartVM.OrderHeader.PaymentStatus = SD.PaymentStatusApproved;
            ShoppingCartVM.OrderHeader.OrderStatus   = SD.StatusApproved;
            ShoppingCartVM.OrderHeader.PaymentDate   = DateTime.Now;


            _unitOfWork.Save();

            return(RedirectToAction("OrderConfirmation", "Cart", new { id = ShoppingCartVM.OrderHeader.Id }));
        }