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 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 void ApplyCoupon_NoSavedCoupon_ShouldHaveNoChangesOnDetailCart() { //Arrange _sessionService.Setup(x => x.GetSession(It.IsAny <String>())).Returns(null); //Act OrderDetailsCart tempDetailsCart = this.cartService.ApplyCoupon(this.detailsCart); //Assert Assert.Equal(tempDetailsCart.OrderHeader.OrderTotal, tempDetailsCart.OrderHeader.OrderTotalOriginal); Assert.Equal(0, tempDetailsCart.OrderHeader.CouponCodeDiscount); }
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)); }
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> Summary() { OrderDetailsCart detailCart = new OrderDetailsCart() { OrderHeader = new OrderHeader(), ChangesMessage = "", listCart = new List <ShoppingCart>() }; detailCart.OrderHeader.TotalPrice = 0; var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var cart = _db.ShoppingCart.Where(c => c.UserId == claim.Value).ToList(); bool changes = false; foreach (var item in cart) { item.ProductSale = await _db.ProductSale.Include(m => m.Product).Where(m => m.Id == item.ProductSaleID).FirstOrDefaultAsync(); if (item.ProductSale.Units == 0) { _db.ShoppingCart.Remove(item); changes = true; continue; } if (item.Count > item.ProductSale.Units) { changes = true; item.Count = item.ProductSale.Units; } detailCart.listCart.Add(item); detailCart.OrderHeader.TotalPrice += (item.ProductSale.Price * item.Count); } await _db.SaveChangesAsync(); HttpContext.Session.SetInt32(SD.ssShoppingCartCount, detailCart.listCart.Count()); detailCart.OrderHeader.OrderTime = DateTime.Now; detailCart.OrderHeader.User = await _db.User.Where(u => u.Id == claim.Value).FirstOrDefaultAsync(); detailCart.OrderHeader.UserId = claim.Value; if (changes) { detailCart.ChangesMessage = "The amount of some products you requested is no longer available. Some changes were applied to your Shopping Cart. We are sorry for the trouble."; } return(View(detailCart)); }
public void PrepareForIndexCart_CartSessionIsNull_ShoulReturnAEmptyListCart() { //Arrange List <MenuItemsAndQuantity> tempListItemAndQuantity = null; _sessionService.Setup(x => x.GetSessionListQuantity()).Returns(tempListItemAndQuantity); //Act OrderDetailsCart tempDetailsCart = this.cartService.PrepareForIndexCart(this.detailsCart); //Assert Assert.Empty(tempDetailsCart.ListCart); }
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> 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 void PrepareForIndexCart_CartSessionIsEmpty_ShoulHaveNoChanges() { //Arrange List <MenuItemsAndQuantity> tempListItemAndQuantity = new List <MenuItemsAndQuantity>(); _sessionService.Setup(x => x.GetSessionListQuantity()).Returns(tempListItemAndQuantity); //Act OrderDetailsCart tempDetailsCart = this.cartService.PrepareForIndexCart(this.detailsCart); //Assert Assert.Empty(tempDetailsCart.ListCart); Assert.Equal(tempDetailsCart.OrderHeader.OrderTotal, this.detailsCart.OrderHeader.OrderTotalOriginal); }
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 async Task <IActionResult> Index() { detailsCart = new OrderDetailsCart() { Orders = new Models.Order() }; detailsCart.Orders.OrderTotal = 0; var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); 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.OrderTotalOriginal = detailsCart.Orders.OrderTotal; 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 void ApplyCoupon_HaveSavedCoupon_ShouldHaveNoChangesOnDetailCart() { //Arrange Coupon tempCoupon = null; _sessionService.Setup(x => x.GetSession(It.IsAny <String>())).Returns(It.IsAny <String>()); _unitOfWork.Setup(x => x.CouponRepository.FirstMatchName(It.IsAny <String>())).Returns(tempCoupon); //Act OrderDetailsCart tempDetailsCart = this.cartService.ApplyCoupon(this.detailsCart); //Assert Assert.Equal(tempDetailsCart.OrderHeader.OrderTotal, tempDetailsCart.OrderHeader.OrderTotalOriginal); Assert.Equal(0, tempDetailsCart.OrderHeader.CouponCodeDiscount); }
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; 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> 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> 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> 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> OnGet() { //Initialize OrderDetailsCart orderDetailsCart = new OrderDetailsCart(); orderDetailsCart.OrderHeader = new OrderHeader(); orderDetailsCart.OrderHeader.OrderTotal = 0; //get user ID ClaimsIdentity claimsIdentity = (ClaimsIdentity)this.User.Identity; Claim claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); string userId = claim.Value; var shoppingCart = _db.ShoppingCart.Where(c => c.ApplicationUserId == userId); if (shoppingCart == null) { return(NotFound()); } double totalPrice = 0; foreach (var shc in shoppingCart) { MenuItem currentMenuItem = await _db.MenuItems .SingleOrDefaultAsync(mi => mi.Id == shc.MenuItemId); shc.MenuItem = currentMenuItem; totalPrice += (shc.MenuItem.Price * shc.Count); //Description up to 100 characters shc.MenuItem.Description = shc.MenuItem.Description.Substring(0, Math.Min(100, shc.MenuItem.Description.Length)) + ". . ."; } //Set values to the OrderDetailsCart this.orderDetailsCart.ShoppingCart = shoppingCart.ToList(); orderDetailsCart.OrderHeader.OrderTotal = totalPrice; orderDetailsCart.OrderHeader.OrderTotal = totalPrice; orderDetailsCart.OrderHeader.UserId = userId; orderDetailsCart.OrderHeader.User = (ApplicationUser)await _db.Users.SingleOrDefaultAsync(u => u.Id == userId); //Timing return(Page()); }
public async Task <IActionResult> Index() { detailCart = new OrderDetailsCart() { OrderHeader = new Models.OrderHeader() }; detailCart.OrderHeader.OrderTotal = 0; var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var cart = _db.ShoppingCart.Where(c => c.ApplicationUserId == claim.Value); if (cart != null) { detailCart.ListCart = cart.ToList(); } foreach (var list in detailCart.ListCart) { list.MenuItem = await _db.MenuItem.FirstOrDefaultAsync(m => m.Id == list.MenuItemId); detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotal + (list.MenuItem.Price * list.Count); list.MenuItem.Description = SD.ConvertToRawHtml(list.MenuItem.Description); //in case we dont want to display the entire description.Lets just say that we display the first 100 characters if (list.MenuItem.Description.Length > 100) { list.MenuItem.Description = list.MenuItem.Description.Substring(0, 99) + "..."; } } detailCart.OrderHeader.OrderTotalOriginal = detailCart.OrderHeader.OrderTotal; if (HttpContext.Session.GetString(SD.ssCouponCode) != null) { //means that there is a coupon code detailCart.OrderHeader.CouponCode = HttpContext.Session.GetString(SD.ssCouponCode); var couponFromDb = await _db.Coupon .Where(c => c.Name.ToLower() == detailCart.OrderHeader.CouponCode.ToLower()).FirstOrDefaultAsync(); detailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, detailCart.OrderHeader.OrderTotalOriginal); } return(View(detailCart)); }
public async Task <IActionResult> Summary() { 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); ApplicationUser applicationUser = await _db.ApplicationUser.Where(x => x.Id == claim.Value).FirstOrDefaultAsync(); 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); } detailCart.OrderHeader.OrderTotalOriginal = detailCart.OrderHeader.OrderTotal; detailCart.OrderHeader.PickupName = applicationUser.Name; detailCart.OrderHeader.PhoneNumber = applicationUser.PhoneNumber; detailCart.OrderHeader.PickupTime = DateTime.Now; //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> Index() { CartDetails = new OrderDetailsCart() { OrderHeader = new Models.OrderHeader() }; CartDetails.OrderHeader.OrderTotal = 0; var ClaimIdenttity = (ClaimsIdentity)User.Identity; var Claim = ClaimIdenttity.FindFirst(ClaimTypes.NameIdentifier); var cart = await _db.ShoppingCart.Where(c => c.ApplicationUserId == Claim.Value).ToListAsync(); if (cart != null) { CartDetails.ListCart = cart; } foreach (var item in CartDetails.ListCart) { //MenuItem Details from DB item.MenuItem = await _db.MenuItem.Where(x => x.Id == item.MenuItemId).FirstOrDefaultAsync(); //Calculating OrderTotal CartDetails.OrderHeader.OrderTotal += (item.MenuItem.Price * item.Count); item.MenuItem.Description = StaticDetails.ConvertToRawHtml(item.MenuItem.Description); //Only shows 100 character Descriptiom if (item.MenuItem.Description.Count() > 100) { item.MenuItem.Description = item.MenuItem.Description.Substring(0, 99) + "..."; } } //Storing Original Order Total Before Applying coupon CartDetails.OrderHeader.OrderTotalOriginal = CartDetails.OrderHeader.OrderTotal; if (HttpContext.Session.GetString(StaticDetails.CouponCodeSession) != null) { CartDetails.OrderHeader.CouponCode = HttpContext.Session.GetString(StaticDetails.CouponCodeSession); var coupon = await _db.Coupon.Where(c => c.Name.ToUpper() == CartDetails.OrderHeader.CouponCode.ToUpper()).FirstOrDefaultAsync(); CartDetails.OrderHeader.OrderTotal = StaticDetails.DiscountedPrice(coupon, CartDetails.OrderHeader.OrderTotalOriginal); } return(View(CartDetails)); }
public async Task <IActionResult> OrderSummery() { CartDetails = new OrderDetailsCart() { OrderHeader = new Models.OrderHeader() }; CartDetails.OrderHeader.OrderTotal = 0; var ClaimIdenttity = (ClaimsIdentity)User.Identity; var Claim = ClaimIdenttity.FindFirst(ClaimTypes.NameIdentifier); ApplicationUser applicationUser = await _db.ApplicationUser.Where(u => u.Id == Claim.Value).FirstOrDefaultAsync(); var cart = await _db.ShoppingCart.Where(c => c.ApplicationUserId == Claim.Value).ToListAsync(); if (cart != null) { CartDetails.ListCart = cart; } foreach (var item in CartDetails.ListCart) { //MenuItem Details from DB item.MenuItem = await _db.MenuItem.Where(x => x.Id == item.MenuItemId).FirstOrDefaultAsync(); //Calculating OrderTotal CartDetails.OrderHeader.OrderTotal += (item.MenuItem.Price * item.Count); } //Storing Original Order Total Before Applying coupon CartDetails.OrderHeader.OrderTotalOriginal = CartDetails.OrderHeader.OrderTotal; CartDetails.OrderHeader.PickUpName = applicationUser.Name; CartDetails.OrderHeader.PhoneNumber = applicationUser.PhoneNumber; CartDetails.OrderHeader.PickUpTime = DateTime.Now; //retrive coupon form session if (HttpContext.Session.GetString(StaticDetails.CouponCodeSession) != null) { CartDetails.OrderHeader.CouponCode = HttpContext.Session.GetString(StaticDetails.CouponCodeSession); var coupon = await _db.Coupon.Where(c => c.Name.ToUpper() == CartDetails.OrderHeader.CouponCode.ToUpper()).FirstOrDefaultAsync(); CartDetails.OrderHeader.OrderTotal = StaticDetails.DiscountedPrice(coupon, CartDetails.OrderHeader.OrderTotalOriginal); } return(View(CartDetails)); }
public async Task <IActionResult> Index() { this.DetailCart = new OrderDetailsCart { OrderHeader = new OrderHeader() }; this.DetailCart.OrderHeader.OrderTotal = 0; var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); this.DetailCart.ListCart = await this.db.ShoppingCart .Where(c => c.ApplicationUserId == claim.Value) .ToListAsync() ?? new List <ShoppingCart>(); foreach (var list in this.DetailCart.ListCart) { list.MenuItem = await this.db.MenuItem.FirstOrDefaultAsync(m => m.Id == list.MenuItemId); this.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)}..."; } } this.DetailCart.OrderHeader.OrderTotalOriginal = this.DetailCart.OrderHeader.OrderTotal; var couponCode = this.HttpContext.Session.GetString(SD.ssCouponCode); if (!string.IsNullOrWhiteSpace(couponCode)) { this.DetailCart.OrderHeader.CouponCode = couponCode; var couponFromDb = await this.db.Coupon .FirstOrDefaultAsync(c => c.Name.ToUpper() == this.DetailCart.OrderHeader.CouponCode.ToUpper()); this.DetailCart.OrderHeader.OrderTotal = SD.DiscountedPrice(couponFromDb, this.DetailCart.OrderHeader.OrderTotalOriginal); } return(this.View(this.DetailCart)); }
public async Task <IActionResult> Summary() { detailCart = new OrderDetailsCart() { OrderHeader = new Models.OrderHeader() }; detailCart.OrderHeader.OrderTotal = 0; // current logged in user var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ApplicationUser applicationUser = await _db.ApplicationUsers.Where(c => c.Id == claim.Value).FirstOrDefaultAsync(); // get all carts of the current user that added var carts = await _db.ShoppingCarts.Where(c => c.ApplicationUserID == claim.Value).ToListAsync(); if (carts != null) { detailCart.ListCart = carts; } foreach (var cart in detailCart.ListCart) { cart.MenuItem = await _db.MenuItems.FirstOrDefaultAsync(m => m.Id == cart.MenuItemId); detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotal + (cart.MenuItem.Price * cart.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) { 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); } return(View(detailCart)); }
public async Task <IActionResult> Index() { detailCart = new OrderDetailsCart() { OrderHeader = new Models.OrderHeader() }; detailCart.OrderHeader.OrderTotal = 0; // current logged in user var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); // get all carts of the current user that added var carts = await _db.ShoppingCarts.Where(c => c.ApplicationUserID == claim.Value).ToListAsync(); if (carts != null) { detailCart.ListCart = carts; } foreach (var cart in detailCart.ListCart) { cart.MenuItem = await _db.MenuItems.FirstOrDefaultAsync(m => m.Id == cart.MenuItemId); detailCart.OrderHeader.OrderTotal = detailCart.OrderHeader.OrderTotal + (cart.MenuItem.Price * cart.Count); cart.MenuItem.Description = SD.ConvertToRawHtml(cart.MenuItem.Description); if (cart.MenuItem.Description.Length > 100) { cart.MenuItem.Description = cart.MenuItem.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.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() { orderDetailCart = new OrderDetailsCart() { OrderHeader = new Models.OrderHeader(), ShippingMethod = await _db.ShippingMethod.ToListAsync() }; orderDetailCart.OrderHeader.OrderTotal = 0; var claimsIdentity = (ClaimsIdentity)User.Identity;; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); User user = await _db.User.Where(v => v.Id == claim.Value).FirstOrDefaultAsync(); var cart = _db.ShoppingCart.Where(x => x.UserId == claim.Value); if (cart != null) { orderDetailCart.ListCart = cart.ToList(); } foreach (var list in orderDetailCart.ListCart) { list.Product = await _db.Product.FirstOrDefaultAsync(x => x.Id == list.ProductId); orderDetailCart.OrderHeader.OrderTotal = orderDetailCart.OrderHeader.OrderTotal + (list.Product.Price * list.Count); } orderDetailCart.OrderHeader.OrderTotalOriginal = orderDetailCart.OrderHeader.OrderTotal; orderDetailCart.OrderHeader.PickupName = user.Name; orderDetailCart.OrderHeader.StreetAddress = user.StreetAddress; orderDetailCart.OrderHeader.PostalCode = user.PostalCode; orderDetailCart.OrderHeader.State = user.State; orderDetailCart.OrderHeader.City = user.City; orderDetailCart.OrderHeader.PhoneNumber = user.PhoneNumber; ViewData["ShippingMethodId"] = new SelectList(_db.ShippingMethod, "Id", "Name"); if (HttpContext.Session.GetString(StaticDefault.ssCouponCode) != null) { orderDetailCart.OrderHeader.CouponCode = HttpContext.Session.GetString(StaticDefault.ssCouponCode); var couponDb = await _db.Coupon.Where(x => x.Name.ToUpper() == orderDetailCart.OrderHeader.CouponCode.ToUpper()).FirstOrDefaultAsync(); orderDetailCart.OrderHeader.OrderTotal = StaticDefault.DiscountedPrice(couponDb, orderDetailCart.OrderHeader.OrderTotalOriginal); } return(View(orderDetailCart)); }
public async Task <IActionResult> PaymentPay(string stripeToken) { orderDetailCart = new OrderDetailsCart() { OrderHeader = new Models.OrderHeader(), ShippingMethod = await _db.ShippingMethod.ToListAsync() }; var claimsIdentity = (ClaimsIdentity)User.Identity;; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var Transaction = await _db.OrderHeader.Where(x => x.UserId == claim.Value).LastOrDefaultAsync(); var options = new ChargeCreateOptions { Amount = Convert.ToInt32(Transaction.OrderTotal * 100), Currency = "usd", Description = "Order Id" + Transaction.Id, Source = stripeToken }; var service = new ChargeService(); Charge charge = service.Create(options); if (charge.BalanceTransactionId == null) { Transaction.PaymentStatus = StaticDefault.PaymentStatusRejected; } else { Transaction.TransactionId = charge.BalanceTransactionId; } if (charge.Status.ToLower() == "succeeded") { Transaction.PaymentStatus = StaticDefault.PaymentStatusApproved; Transaction.Status = StaticDefault.StatusSubmitted; } else { Transaction.PaymentStatus = StaticDefault.PaymentStatusRejected; } await _db.SaveChangesAsync(); return(RedirectToAction("Confirm", "Order", new { id = Transaction.Id })); }