Beispiel #1
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")
            };
            ShoppingCartVM.OrderHeader.OrderTotal      = 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.OrderTotal += (list.Price * list.Count);
                list.Product.Description = StaticDetail.ConvertToRawHtml(list.Product.Description);
                if (list.Product.Description.Length > 100)
                {
                    list.Product.Description = list.Product.Description.Substring(0, 99) + "...";
                }
            }


            return(View(ShoppingCartVM));
        }
        public async Task <IActionResult> Index()
        {
            cartDetails = new OrderDetailsCart()
            {
                Order = new Models.Order()
            };

            cartDetails.Order.OrderTotal = 0;

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

            var cart = db.Cart.Where(c => c.UserId == claim.Value);

            if (cart != null)
            {
                cartDetails.listCart = cart.ToList();
            }
            foreach (var list in cartDetails.listCart)
            {
                list.Service = await db.Service.FirstOrDefaultAsync(m => m.Id == list.ServiceId);

                cartDetails.Order.OrderTotal = cartDetails.Order.OrderTotal + (list.Service.Price * list.Count);
                list.Service.Description     = StaticDetail.ConvertToRawHtml(list.Service.Description);
                if (list.Service.Description.Length > 100)
                {
                    list.Service.Description = list.Service.Description.Substring(0, 99) + "...";
                }
            }
            cartDetails.Order.OrderTotalOriginal = cartDetails.Order.OrderTotal;

            if (HttpContext.Session.GetString(StaticDetail.ssCouponCode) != null)
            {
                cartDetails.Order.CouponCode = HttpContext.Session.GetString(StaticDetail.ssCouponCode);
                var couponFromDb = await
                                   db.Coupon
                                   .Where(c => c.Name.ToLower() ==
                                          cartDetails.Order.CouponCode.ToLower()).FirstOrDefaultAsync();

                if (couponFromDb != null)
                {
                    cartDetails.Order.OrderTotal =
                        StaticDetail.DiscountedPrice(couponFromDb, cartDetails.Order.OrderTotalOriginal);
                }
                else
                {
                    HttpContext.Session.SetString(StaticDetail.ssCouponCode, string.Empty);
                }
            }

            return(View(cartDetails));
        }
Beispiel #3
0
        public async Task <IActionResult> Index()
        {
            detailCart = new OrderDetailsCart()
            {
                OrderHeader = new Models.OrderHeader(),
            };

            detailCart.OrderHeader.OrderTotal = 0m;

            var claimsIdentity = (ClaimsIdentity)User.Identity;

            var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

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

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

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

                detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotal + ((decimal)list.MenuItem.Price * list.Count);
                list.MenuItem.Description         = StaticDetail.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(StaticDetail.ssCouponCode) != null)
            {
                detailCart.OrderHeader.CouponCode = HttpContext.Session.GetString(StaticDetail.ssCouponCode);
                var couponFromDb = await this.db.Coupons.Where(c => c.Name.ToLower() == detailCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync();

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

            return(View(detailCart));
        }
Beispiel #4
0
        public async Task <IActionResult> Index()
        {
            // retreive user
            var claimIdentity    = (ClaimsIdentity)this.User.Identity;
            var currentUser      = claimIdentity.FindFirst(ClaimTypes.NameIdentifier);
            var shoppingCartData = _db.ShoppingCart.Where(s => s.ApplicationUserId == currentUser.Value);

            orderDetailsCartViewModel = new OrderDetailsCartViewModel()
            {
                OrderHeader = new Models.OrderHeader()
            };
            orderDetailsCartViewModel.OrderHeader.OrderTotalOriginal = 0;
            if (shoppingCartData != null)
            {
                orderDetailsCartViewModel.ListShoppingCarts = shoppingCartData.ToList();
            }
            //ConvertToRawHtml versus @Html.Raw(item.Description)
            foreach (var orderItem in orderDetailsCartViewModel.ListShoppingCarts)
            {
                orderItem.MenuItem = await _db.MenuItem.FirstOrDefaultAsync(s => s.Id == orderItem.MenuItemId);

                orderDetailsCartViewModel.OrderHeader.OrderTotalOriginal += (orderItem.MenuItem.Price * orderItem.Count);
                orderItem.MenuItem.Description = StaticDetail.ConvertToRawHtml(orderItem.MenuItem.Description);
                if (orderItem.MenuItem.Description.Length > 100)
                {
                    orderItem.MenuItem.Description = orderItem.MenuItem.Description.Substring(0, 99) + "...";
                }
            }
            orderDetailsCartViewModel.OrderHeader.OrderTotalDiscount = orderDetailsCartViewModel.OrderHeader.OrderTotalOriginal;
            if (HttpContext.Session.GetString(StaticDetail.ssCoupon) != null)
            {
                orderDetailsCartViewModel.OrderHeader.CouponCode = HttpContext.Session.GetString(StaticDetail.ssCoupon);
                var couponFromDb = await _db.Coupon.Where(s => s.Name.ToLower() == orderDetailsCartViewModel.OrderHeader.CouponCode.ToLower())
                                   .FirstOrDefaultAsync();

                orderDetailsCartViewModel.OrderHeader.OrderTotalOriginal = StaticDetail.DiscountedPrice(couponFromDb, orderDetailsCartViewModel.OrderHeader.OrderTotalOriginal);
            }
            return(View(orderDetailsCartViewModel));
        }