Beispiel #1
0
        public async Task <IActionResult> Index()
        {
            if (ModelState.IsValid)
            {
                customerDetailCart = new CustomerOrderDetailsCart()
                {
                    CustomerOrderHeader = new Models.CustomerOrderHeader()
                };

                customerDetailCart.CustomerOrderHeader.OrderTotal = 0;

                var claimsIdentity = (ClaimsIdentity)User.Identity;
                var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
                if (claim == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                var cart = _db.CustomerShoppingCart.Where(c => c.ApplicationUserId == claim.Value);
                if (cart != null)
                {
                    customerDetailCart.listCart = cart.ToList();
                }

                foreach (var list in customerDetailCart.listCart)
                {
                    list.Medicine = await _db.Medicine.FirstOrDefaultAsync(m => m.Id == list.MedicineId);

                    customerDetailCart.CustomerOrderHeader.OrderTotal = customerDetailCart.CustomerOrderHeader.OrderTotal + (list.Medicine.Price * list.Count);
                    list.Medicine.Description = SD.ConvertToRawHtml(list.Medicine.Description);
                    if (list.Medicine.Description.Length > 100)
                    {
                        list.Medicine.Description = list.Medicine.Description.Substring(0, 99) + "...";
                    }
                }
                customerDetailCart.CustomerOrderHeader.OrderTotalOriginal = customerDetailCart.CustomerOrderHeader.OrderTotal;

                if (HttpContext.Session.GetString(SD.ssDiscountCodeString) != null)
                {
                    customerDetailCart.CustomerOrderHeader.DiscountCodeString = HttpContext.Session.GetString(SD.ssDiscountCodeString);
                    var discountCodeFromDb = await _db.DiscountCode.Where(c => c.Name.ToLower() == customerDetailCart.CustomerOrderHeader.DiscountCodeString.ToLower()).FirstOrDefaultAsync();

                    customerDetailCart.CustomerOrderHeader.OrderTotal = SD.DiscountedPrice(discountCodeFromDb, customerDetailCart.CustomerOrderHeader.OrderTotalOriginal);
                }


                return(View(customerDetailCart));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Checkout()
        {
            customerDetailCart = new CustomerOrderDetailsCart()
            {
                CustomerOrderHeader = new Models.CustomerOrderHeader()
            };

            customerDetailCart.CustomerOrderHeader.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.CustomerShoppingCart.Where(c => c.ApplicationUserId == claim.Value);

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

            foreach (var list in customerDetailCart.listCart)
            {
                list.Medicine = await _db.Medicine.FirstOrDefaultAsync(m => m.Id == list.MedicineId);

                customerDetailCart.CustomerOrderHeader.OrderTotal = customerDetailCart.CustomerOrderHeader.OrderTotal + (list.Medicine.Price * list.Count);
            }
            customerDetailCart.CustomerOrderHeader.OrderTotalOriginal = customerDetailCart.CustomerOrderHeader.OrderTotal;
            customerDetailCart.CustomerOrderHeader.PickupName         = ApplicationUser.Name;
            customerDetailCart.CustomerOrderHeader.PhoneNumber        = ApplicationUser.PhoneNumber;
            customerDetailCart.CustomerOrderHeader.PickUpTime         = DateTime.Now;


            if (HttpContext.Session.GetString(SD.ssDiscountCodeString) != null)
            {
                customerDetailCart.CustomerOrderHeader.DiscountCodeString = HttpContext.Session.GetString(SD.ssDiscountCodeString);
                var discountCodeFromDb = await _db.DiscountCode.Where(c => c.Name.ToLower() == customerDetailCart.CustomerOrderHeader.DiscountCodeString.ToLower()).FirstOrDefaultAsync();

                customerDetailCart.CustomerOrderHeader.OrderTotal = SD.DiscountedPrice(discountCodeFromDb, customerDetailCart.CustomerOrderHeader.OrderTotalOriginal);
            }


            return(View(customerDetailCart));
        }