public OrderDetailsCart ApplyCoupon(OrderDetailsCart detailCart) { string sessionCoupon = (string)_sessionService.GetSession(SD.ssCouponCode); if (sessionCoupon != null) { detailCart.OrderHeader.CouponCode = sessionCoupon; var couponFromDb = _unitOfWork.CouponRepository.FirstMatchName(detailCart.OrderHeader.CouponCode.ToLower()); if (couponFromDb != null) { detailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailCart.OrderHeader.OrderTotalOriginal); } else { detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotalOriginal; } } else { detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotalOriginal; } detailCart.OrderHeader.CouponCodeDiscount = detailCart.OrderHeader.OrderTotalOriginal - detailCart.OrderHeader.OrderTotal; _sessionService.ClearCoupon(); return(detailCart); }
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); }
public async Task <IActionResult> Summary() { DetailsCart = new OrderDetailsCart() { OrderHeaders = new Models.OrderHeader() }; DetailsCart.OrderHeaders.OrderTotal = 0; var UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; ApplicationUser user = await db.ApplicationUser.FirstOrDefaultAsync(x => x.Id == UserId); var cart = db.ShoppingCart.Where(x => x.ApplicationUserId == UserId); if (cart != null) { DetailsCart.ShoppingCarts = cart.ToList(); } foreach (var list in DetailsCart.ShoppingCarts) { list.MenuItem = await db.MenuItem.FirstOrDefaultAsync(x => x.Id == list.ItemId); DetailsCart.OrderHeaders.OrderTotal += (list.MenuItem.Price * list.Count); } DetailsCart.OrderHeaders.PickupName = user.Name; DetailsCart.OrderHeaders.PhoneNumber = user.PhoneNumber; DetailsCart.OrderHeaders.PickupTime = DateTime.Now; DetailsCart.OrderHeaders.OrderTotalOriginal = DetailsCart.OrderHeaders.OrderTotal; if (HttpContext.Session.GetString(SD.ssCouponCode) != null) { DetailsCart.OrderHeaders.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode); var couponFromDb = await db.Coupon.FirstOrDefaultAsync(c => c.Name.ToLower() == DetailsCart.OrderHeaders.CouponCode.ToLower()); DetailsCart.OrderHeaders.OrderTotal = SD.DiscountedPrice(couponFromDb, DetailsCart.OrderHeaders.OrderTotalOriginal); } return(View(DetailsCart)); }
public void DiscountedPrice_BigMinimumAmount_ReturnTrue() { List <MenuItemsAndQuantity> lstCart = new List <MenuItemsAndQuantity>(); Coupon coupon = new Coupon { Id = 1, Name = "15OFF", CouponType = "0", Discount = 15, MinimumAmount = 500, IsActive = true }; lstCart.Add(new MenuItemsAndQuantity() { Item = item1, Quantity = 3 }); lstCart.Add(new MenuItemsAndQuantity() { Item = item2, Quantity = 2 }); double total = 0; foreach (var item in lstCart) { total += (item.Item.Price * item.Quantity); } Assert.True(SD.DiscountedPrice(coupon, total) == total); }
public async Task <IActionResult> Summary(int id) { detailsCart = new OrderCartDetails { OrderHeader = new Models.OrderHeader() }; detailsCart.OrderHeader.OrderTotal = 0; var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ApplicationUser applicationuser = await _db.ApplicationUser.Where(c => c.Id == claim.Value).FirstOrDefaultAsync(); var cart = _db.ShopingCart.Where(C => C.ApplicationUserId == claim.Value); if (cart != null) { detailsCart.ListCart = cart.ToList();; } foreach (var list in detailsCart.ListCart) { list.MenuItem = await _db.MenuItem.FirstOrDefaultAsync(c => c.Id == list.MenuItemId); detailsCart.OrderHeader.OrderTotal = detailsCart.OrderHeader.OrderTotal + (list.MenuItem.Price * list.Count); } detailsCart.OrderHeader.OrderTotalOrginal = detailsCart.OrderHeader.OrderTotal; detailsCart.OrderHeader.PickUpName = applicationuser.Name; detailsCart.OrderHeader.PhoneNumber = applicationuser.PhoneNumber; detailsCart.OrderHeader.PickUpTime = DateTime.Now; if (HttpContext.Session.GetString(SD.ssCouponCode) != null) { detailsCart.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode); var couponFromDb = _db.Coupon.Where(c => c.Name.ToLower() == detailsCart.OrderHeader.CouponCode.ToLower()).FirstOrDefault(); detailsCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailsCart.OrderHeader.OrderTotalOrginal); } return(View(detailsCart)); }
public async Task <IActionResult> SummaryPost() { var claimsIdenity = (ClaimsIdentity)User.Identity; var claim = claimsIdenity.FindFirst(ClaimTypes.NameIdentifier); detailCart.listCart = await _db.ShoppingCart.Where(c => c.ApplicationUserId == claim.Value).ToListAsync(); detailCart.OrderHeader.PaymentStatus = SD.PaymentStatusPending; // Order total = 0 detailCart.OrderHeader.OrderDate = DateTime.Now; // Order total = 0 detailCart.OrderHeader.UserId = claim.Value; // Order total = 0 detailCart.OrderHeader.Status = SD.PaymentStatusPending; // Order total = 0 detailCart.OrderHeader.PickUpTime = Convert.ToDateTime(detailCart.OrderHeader.PickUpDate.ToShortDateString() + " " + detailCart.OrderHeader.PickUpTime.ToShortTimeString()); // Order total = 0 List <OrderDetails> orderDetailsList = new List <OrderDetails>(); _db.OrderHeader.Add(detailCart.OrderHeader); await _db.SaveChangesAsync(); detailCart.OrderHeader.OrderTotalOriginal = 0; foreach (var item in detailCart.listCart) //Liczenie ceny dla każdego z produktów { item.MenuItem = await _db.MenuItem.FirstOrDefaultAsync(m => m.Id == item.MenuItemId); OrderDetails orderDetails = new OrderDetails { MenuItemId = item.MenuItem.Id, OrderId = detailCart.OrderHeader.Id, Description = item.MenuItem.Description, Name = item.MenuItem.Name, Price = item.MenuItem.Price, Count = item.Count }; detailCart.OrderHeader.OrderTotalOriginal += orderDetails.Count * orderDetails.Price; _db.OrderDetails.Add(orderDetails); //Dodanie dopiero po SaveChanges!!!! } if (HttpContext.Session.GetString(SD.ssCouponCode) != null) //If coupon has been used { 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); } else { detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotalOriginal; //No coupon used. } detailCart.OrderHeader.CouponCodeDiscount = detailCart.OrderHeader.OrderTotalOriginal - detailCart.OrderHeader.OrderTotal; //Remove session attributes //Remove items from shopping cart _db.ShoppingCart.RemoveRange(detailCart.listCart); HttpContext.Session.SetInt32(SD.ssShoppingCartCount, 0); await _db.SaveChangesAsync(); //return RedirectToAction("Index", "Home"); return(RedirectToAction("Confirm", "Order", new { id = detailCart.OrderHeader.Id })); }
public async Task <IActionResult> Index() { detailsCard = new OrderDetailsCard() { OrderHeader = new Models.OrderHeader() }; detailsCard.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) { detailsCard.listCart = cart.ToList(); } foreach (var list in detailsCard.listCart) { list.Flower = await _db.Flower.FirstOrDefaultAsync(m => m.Id == list.FlowerId); detailsCard.OrderHeader.OrderTotal = detailsCard.OrderHeader.OrderTotal + (list.Flower.Price * list.Count); } detailsCard.OrderHeader.OrderTotalOriginal = detailsCard.OrderHeader.OrderTotal; if (HttpContext.Session.GetString(SD.ssCouponCode) != null) { detailsCard.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode); var couponFromDb = await _db.Coupon.Where(c => c.Name.ToLower() == detailsCard.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync(); detailsCard.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailsCard.OrderHeader.OrderTotalOriginal); } return(View(detailsCard)); }
public async Task <IActionResult> Summary() { detailsCart = new OrderDetailsCart() { Orders = new Models.Order() }; detailsCart.Orders.OrderTotal = 0; var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ApplicationUser applicationUser = await _db.ApplicationUsers.Where(c => c.Id == claim.Value).FirstOrDefaultAsync(); var cart = _db.ShoppingCarts.Where(c => c.ApplicationUserId == claim.Value); if (cart != null) { detailsCart.lstCarts = cart.ToList(); } foreach (var list in detailsCart.lstCarts) { list.Product = await _db.Products.FirstOrDefaultAsync(p => p.Id == list.ProductId); detailsCart.Orders.OrderTotal = detailsCart.Orders.OrderTotal + (list.Product.Price * list.Count); } detailsCart.Orders.OrderTotal = Math.Round(detailsCart.Orders.OrderTotal, 2); detailsCart.Orders.OrderTotalOriginal = detailsCart.Orders.OrderTotal; detailsCart.Orders.OrderName = applicationUser.FullName; detailsCart.Orders.PhoneNumber = applicationUser.PhoneNumber; detailsCart.Orders.OrderDate = DateTime.Now; detailsCart.Orders.ShipAddress = applicationUser.Address; detailsCart.Orders.ShipCity = applicationUser.City; detailsCart.Orders.ShipCountry = applicationUser.Country; detailsCart.Orders.ShipEmail = applicationUser.Email; if (claim != null) { var cnt = 0; var lstCnt = _db.ShoppingCarts.Where(u => u.ApplicationUserId == claim.Value).ToList(); foreach (var c in lstCnt) { cnt += c.Count; } HttpContext.Session.SetInt32(SD.ssShoppingCartCount, cnt); } if (HttpContext.Session.GetString(SD.ssCouponCode) != null) { detailsCart.Orders.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode); var couponFromDb = await _db.Coupons.Where(c => c.Name.ToLower() == detailsCart.Orders.CouponCode.ToLower()).FirstOrDefaultAsync(); detailsCart.Orders.OrderTotal = SD.DiscountedPrice(couponFromDb, detailsCart.Orders.OrderTotalOriginal); } return(View(detailsCart)); }
public async Task <IActionResult> SummaryPost(string stripeToken) { var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); detailCart.listCart = await _db.ShoppingCarts.Where(c => c.ApplicationUserId == claim.Value).ToListAsync(); detailCart.OrderHeader.PaymentStatus = SD.PaymentStatusPending; detailCart.OrderHeader.OrderDate = DateTime.Now; detailCart.OrderHeader.UserId = claim.Value; detailCart.OrderHeader.Status = SD.PaymentStatusPending; detailCart.OrderHeader.PickUpTime = Convert.ToDateTime(detailCart.OrderHeader.PickUpDate.ToShortDateString() + " " + detailCart.OrderHeader.PickUpTime.ToShortTimeString()); List <OrderDetail> orderDetailsList = new List <OrderDetail>(); _db.OrderHeaders.Add(detailCart.OrderHeader); await _db.SaveChangesAsync(); detailCart.OrderHeader.OrderTotalOriginal = 0; foreach (var item in detailCart.listCart) { item.MenuItem = await _db.MenuItems.FirstOrDefaultAsync(m => m.Id == item.MenuItemId); OrderDetail orderDetails = new OrderDetail { MenuItemId = item.MenuItemId, OrderId = detailCart.OrderHeader.Id, Description = item.MenuItem.Description, Name = item.MenuItem.Name, Price = item.MenuItem.Price, Count = item.Count }; detailCart.OrderHeader.OrderTotalOriginal += orderDetails.Count * orderDetails.Price; _db.OrderDetails.Add(orderDetails); } if (HttpContext.Session.GetString(SD.ssCouponCode) != null) { detailCart.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode); var couponFromDb = await _db.Coupons.Where(c => c.Name.ToLower() == detailCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync(); detailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailCart.OrderHeader.OrderTotalOriginal); } else { detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotalOriginal; } detailCart.OrderHeader.CouponCodeDiscount = detailCart.OrderHeader.OrderTotalOriginal - detailCart.OrderHeader.OrderTotal; _db.ShoppingCarts.RemoveRange(detailCart.listCart); HttpContext.Session.SetInt32(SD.ssShoppingCartCount, 0); await _db.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> Summary() { detailCart = new OrderDetailsCart() { OrderHeader = new Models.OrderHeader() }; detailCart.OrderHeader.OrderTotal = 0; // retrieve id from logged in user var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); // get customer who placed the order // compare cusmers id with claim id ApplicationUser applicationUser = await _db.ApplicationUser.Where(c => c.Id == claim.Value) .FirstOrDefaultAsync(); // 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); } // get total price of order detailCart.OrderHeader.OrderTotalOriginal = detailCart.OrderHeader.OrderTotal; // get customers Name, PhoneNumber and PickUpTime from above applicationUser object detailCart.OrderHeader.PickupName = applicationUser.Name; detailCart.OrderHeader.PhoneNumber = applicationUser.PhoneNumber; // we will modify this with JS in view ( .PickUpTime = DateTime.Now ) detailCart.OrderHeader.PickUpTime = DateTime.Now; // 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)); }
public async Task <IActionResult> Summary() { 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); ApplicationUser applicationUser = await _db.ApplicationUser.Where(c => c.Id == claim.Value).FirstOrDefaultAsync(); //---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); } detailCart.OrderHeader.OrderTotalOriginal = detailCart.OrderHeader.OrderTotal; //---Display more info for the summary details detailCart.OrderHeader.PickupName = applicationUser.Name; detailCart.OrderHeader.PhoneNumber = applicationUser.PhoneNumber; detailCart.OrderHeader.PickupTime = DateTime.Now; //---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)); }
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")); } }
public OrderDetailsCart CheckCouponBeforeSumary(OrderDetailsCart detailCart) { string sessionCoupon = (string)_sessionService.GetSession(SD.ssCouponCode); if (sessionCoupon != null) { detailCart.OrderHeader.CouponCode = sessionCoupon; Coupon couponFromDb = _unitOfWork.CouponRepository.FirstMatchName(detailCart.OrderHeader.CouponCode.ToLower()); detailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailCart.OrderHeader.OrderTotalOriginal); } return(detailCart); }
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)); }
public async Task <IActionResult> AddCoupon() { if (detailCart.OrderHeader.CouponCode == null) { detailCart.OrderHeader.CouponCode = ""; var couponFromDb = await _db.Coupon.Where(c => c.Name.ToLower() == detailCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync(); detailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailCart.OrderHeader.OrderTotalOriginal); } HttpContext.Session.SetString(SD.ssCouponCode, detailCart.OrderHeader.CouponCode); return(RedirectToAction(nameof(Index))); }
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)); }
public async Task <IActionResult> AddAddressToOrder(int cartId) { var detailCart = new Models.ViewModels.OrderDetailsCart() { OrderHeader = new Models.OrderHeader() }; detailCart.OrderHeader.OrderTotal = 0; var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); //retrieve the user object in application user ApplicationUser applicationUser = await _db.ApplicationUser.Where(u => u.Id == claim.Value).FirstOrDefaultAsync(); var cart = _db.ShoppingCart.Where(u => u.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); } detailCart.OrderHeader.OrderTotalOriginal = detailCart.OrderHeader.OrderTotal; detailCart.OrderHeader.FirstName = applicationUser.FirstName; detailCart.OrderHeader.LastName = applicationUser.LastName; detailCart.OrderHeader.PhoneNumber = applicationUser.PhoneNumber; detailCart.OrderHeader.DeliveryStreet = applicationUser.StreetAddress; detailCart.OrderHeader.DeliveryStreetNumber = applicationUser.StreetNumber; detailCart.OrderHeader.DeliveryCountry = applicationUser.Country; detailCart.OrderHeader.DeliveryCity = applicationUser.City; detailCart.OrderHeader.DeliveryPostalCode = applicationUser.PostalCode; 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)); }
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> Summary() { 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); ApplicationUser applicationUser = await _db.ApplicationUser.Where(u => u.Id == claim.Value).FirstOrDefaultAsync(); // 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); } // set order total original - both will be the same before coupons/discount is added cartVM.OrderHeader.OrderTotalOriginal = cartVM.OrderHeader.OrderTotal; cartVM.OrderHeader.PickupName = applicationUser.Name; cartVM.OrderHeader.PhoneNumber = applicationUser.PhoneNumber; cartVM.OrderHeader.PickupTime = DateTime.Now; // 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() { //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)); }
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)); }
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)); }
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); var applicationUser = await _context.ApplicationUsers.Where(u => u.Id == claim.Value).FirstOrDefaultAsync(); 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; } 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) { 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)); }
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 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.Item = await _db.Item.FirstOrDefaultAsync(m => m.Id == list.ItemId); detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotal + (list.Count * list.Item.Price); if (list.Item.Description != null) { list.Item.Description = SD.ConvertToRawHtml(list.Item.Description); } else { list.Item.Description = "No Description Added"; } if (list.Item.Description.Length > 100) { list.Item.Description = list.Item.Description.Substring(0, 99) + "..."; } } 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.ToLower() == detailCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync(); detailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailCart.OrderHeader.OrderTotalOriginal); } return(View(detailCart)); }
public async Task <IActionResult> Summary() { 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); ApplicationUser applicationUser = await _db.ApplicationUser.Where(c => c.Id == claim.Value).FirstOrDefaultAsync(); //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); } //before they use the coupon we make sure the total is the same detailCart.OrderHeader.OrderTotalOriginal = detailCart.OrderHeader.OrderTotal; detailCart.OrderHeader.PickupName = applicationUser.Name; detailCart.OrderHeader.PhoneNumber = applicationUser.PhoneNumber; detailCart.OrderHeader.PickUpTime = DateTime.Now; //if there is a 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 == detailCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync(); detailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailCart.OrderHeader.OrderTotalOriginal); } return(View(detailCart)); }
public async Task <IActionResult> OrderSummary() { DetailCart = new OrderDetailsCart { OrderHeader = new Models.OrderHeader() }; DetailCart.OrderHeader.OrderTotal = 0; var userId = (this.User.Identity as ClaimsIdentity).FindFirst(ClaimTypes.NameIdentifier).Value; var appUser = await db.AppUsers.SingleOrDefaultAsync(m => m.Id == 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); } DetailCart.OrderHeader.OrderTotalOriginal = DetailCart.OrderHeader.OrderTotal; DetailCart.OrderHeader.PickerName = appUser.Name; DetailCart.OrderHeader.PickerPhoneNumber = appUser.PhoneNumber; DetailCart.OrderHeader.PickUpTime = DateTime.Now; 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; } DetailCart.OrderHeader.AppUserId = userId; DetailCart.OrderHeader.Comments = string.Empty; return(View(DetailCart)); }
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)); }
public async Task <IActionResult> Index() { detailCart = new OrderDetailsCart() { OrderHeader = new Models.OrderHeader() }; detailCart.OrderHeader.OrderTotal = 0; //get login user id var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var cart = _db.ShoppingCart.Where(x => x.ApplicationUserId == claim.Value); if (cart != null) { detailCart.listCart = cart.ToList(); } foreach (var item in detailCart.listCart) { item.MenuItem = await _db.MenuItem.FirstOrDefaultAsync(x => x.Id == item.MenuItemId); detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotal + (item.MenuItem.Price * item.Count); item.MenuItem.Description = SD.ConvertToRawHtml(item.MenuItem.Description); //convert raw html to menu item if (item.MenuItem.Description.Length > 100) { item.MenuItem.Description = item.MenuItem.Description.Substring(0, 99) + "..."; //hanya menampilkan description 100 karakter } } detailCart.OrderHeader.OrderTotalOriginal = detailCart.OrderHeader.OrderTotal; //check session coupon code if (HttpContext.Session.GetString(SD.ssCouponCode) != null) { //get coupon code dari session detailCart.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode); //check coupon code pada db var couponFromDb = await _db.Coupon.Where(x => x.Name.ToLower() == detailCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync(); //implement coupon code pada OrderTotal detailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailCart.OrderHeader.OrderTotalOriginal); } return(View(detailCart)); }
public async Task <IActionResult> Summary() { DetailsCart = new OrdersDetailsCartViewModel() { OrderHeader = new Models.OrderHeader() }; DetailsCart.OrderHeader.OrderTotal = 0; DetailsCart.OrderHeader.OrderTotalOriginal = 0; var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var cart = _db.ShoppingCart.Where(c => c.ApplicationUserId == claim.Value); ApplicationUser applicationUser = await _db.ApplicationUser.Where(c => c.Id == claim.Value).FirstOrDefaultAsync(); if (cart != null) { DetailsCart.ListCart = cart.ToList(); } foreach (var item in DetailsCart.ListCart) { item.MenuItem = await _db.MenuItem.FirstOrDefaultAsync(m => m.Id == item.MenuItemId); DetailsCart.OrderHeader.OrderTotal += item.Count * item.MenuItem.Price; } DetailsCart.OrderHeader.OrderTotal = Math.Round(DetailsCart.OrderHeader.OrderTotal, 2); DetailsCart.OrderHeader.OrderTotalOriginal = DetailsCart.OrderHeader.OrderTotal; DetailsCart.OrderHeader.PickUpName = applicationUser.Name; DetailsCart.OrderHeader.PhoneNumber = applicationUser.PhoneNumber; DetailsCart.OrderHeader.PickupDate = DateTime.Now; DetailsCart.OrderHeader.PickupTime = DateTime.Now; if (HttpContext.Session.GetString(SD.ssCouponCode) != null) { DetailsCart.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode); var couponFromDb = await _db.Coupon.FirstOrDefaultAsync(c => c.Name.ToLower().Trim() == DetailsCart.OrderHeader.CouponCode.ToLower().Trim()); DetailsCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, DetailsCart.OrderHeader.OrderTotalOriginal); } return(View(DetailsCart)); }