public IActionResult Index() { var claimsIdentity = (ClaimsIdentity)User.Identity; var claims = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ShoppingCartVM = new ShoppingCartVM() { OrderHeader = new OrderHeader(), CartList = unitOfWork.ShoppingCart.GetAll(u => u.ApplicatinUserId == claims.Value, includeProperties: "Product") }; ShoppingCartVM.OrderHeader.OrderTotal = 0; ShoppingCartVM.OrderHeader.ApplicationUser = unitOfWork.ApplicationUser.GetFirstOrDefault(u => u.Id == claims.Value, includeProperties: "Organization"); foreach (var item in ShoppingCartVM.CartList) { item.Price = StaticDetails.CalculateBooksPrice(item.Count, item.Product.Price, item.Product.Price50, item.Product.Price100); ShoppingCartVM.OrderHeader.OrderTotal += (item.Price * item.Count); item.Product.ProductDescription = StaticDetails.ConvertToRawHtml(item.Product.ProductDescription); if (item.Product.ProductDescription.Length > 100) { item.Product.ProductDescription = item.Product.ProductDescription.Substring(0, 99) + "..."; } } return(View(ShoppingCartVM)); }
public IActionResult Index() { var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); if (claim != null) { ShoppingCartVM = new ShoppingCartVM() { OrderHeader = new Models.OrderHeader(), ListCart = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId == claim.Value, includeProperties: "Product") }; ShoppingCartVM.OrderHeader.OrderTotal = 0; foreach (var list in ShoppingCartVM.ListCart) { list.Price = StaticDetails.GetPriceBasedOnQuantity(list.Count, list.Product.Price, list.Product.Price50, list.Product.Price100); ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count); list.Product.Description = StaticDetails.ConvertToRawHtml(list.Product.Description); if (list.Product.Description.Length > 100) { list.Product.Description = list.Product.Description.Substring(0, 99) + "..."; } } return(View(ShoppingCartVM)); } else { return(RedirectToAction("Index", "Home")); } }
public IActionResult Index() { var claimsIdentity = (ClaimsIdentity)User.Identity; //To get user id and verify user var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ShoppingCartVM = new ShoppingCartViewModel() { OrderHeader = new BookStoreModels.OrderHeader(), CartList = _unitOfWork.Cart.GetAll(u => u.AppUserId == claim.Value, includeProperties: "Book") }; ShoppingCartVM.OrderHeader.OrderTotal = 0; ShoppingCartVM.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser. GetFirstOrDefault(u => u.Id == claim.Value, includeProperties: "Company"); //to fill app user //To populate ListCart foreach (var list in ShoppingCartVM.CartList) { list.Price = list.Book.Price; ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count); list.Book.Description = StaticDetails.ConvertToRawHtml(list.Book.Description); if (list.Book.Description.Length > 100) { list.Book.Description = list.Book.Description.Substring(0, 99) + "..."; } } return(View()); }
public IActionResult Index() { var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ShoppingCartViewModel = new ShoppingCartViewModel() { OrderHeader = new OrderHeader(), ListCart = _unitOfWork.ShoppingCart.GetAll(u => u.ApplicationUserId == claim.Value, includeProperties: "Product") }; ShoppingCartViewModel.OrderHeader.OrderTotal = 0; ShoppingCartViewModel.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser .GetFirstOrDefault(u => u.Id == claim.Value, includeProperties: "Company"); foreach (var list in ShoppingCartViewModel.ListCart) { list.Price = StaticDetails.GetPriceBasedOnQuantity(list.Count, list.Product.Price, list.Product.Price50, list.Product.Price100); ShoppingCartViewModel.OrderHeader.OrderTotal += (list.Price * list.Count); list.Product.Descreption = StaticDetails.ConvertToRawHtml(list.Product.Descreption); if (list.Product.Descreption.Length > 100) { list.Product.Descreption = list.Product.Descreption.Substring(0, 99) + "..."; } } return(View(ShoppingCartViewModel)); }
public IActionResult Index() { //logged in user var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ShoppingCartVM = new ShoppingCartViewModel() { OrderHeader = new Models.OrderHeader(), // load product along with cart 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); //go through all items in cart foreach (var list in ShoppingCartVM.ListCart) { list.Price = list.Product.Price; ShoppingCartVM.OrderHeader.OrderTotal += (list.Price * list.Count); list.Product.Description = StaticDetails.ConvertToRawHtml(list.Product.Description); //get first 100 chars only if (list.Product.Description.Length > 100) { list.Product.Description = list.Product.Description.Substring(0, 99) + "..."; } } return(View(ShoppingCartVM)); }
public async Task <IActionResult> Index() { DetailsCart = new OrderDetailsCart() { OrderHeader = new Models.OrderHeader() }; DetailsCart.OrderHeader.OrderTotal = 0; var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var cart = db.ShoppingCart.Where(sc => sc.ApplicationUserId == claim.Value); if (cart != null) { DetailsCart.ListCart = cart.ToList(); } foreach (var shoppingCart in DetailsCart.ListCart) { shoppingCart.MenuItem = await db.MenuItem.FirstOrDefaultAsync(mi => mi.Id == shoppingCart.MenuItemId); DetailsCart.OrderHeader.OrderTotal = DetailsCart.OrderHeader.OrderTotal + (shoppingCart.MenuItem.Price * shoppingCart.Count); shoppingCart.MenuItem.Description = StaticDetails.ConvertToRawHtml(shoppingCart.MenuItem.Description); if (shoppingCart.MenuItem.Description.Length > 100) { shoppingCart.MenuItem.Description = shoppingCart.MenuItem.Description.Substring(0, 99) + "..."; } } DetailsCart.OrderHeader.OrderTotalOriginal = DetailsCart.OrderHeader.OrderTotal; return(View(DetailsCart)); }
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)); }