public IActionResult Summary() { var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ShoppingCartVm = new ShoppingCartVM() { OrderHeader = new OrderHeader(), ShoppingCarts = _unitOfWork.ShoppingCart.GetAll(c => c.ApplicationUserId == claim.Value, includeProperties: "Product") }; ShoppingCartVm.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser.GetFirstOrDefault(u => u.Id == claim.Value, includeProperties: "Company"); foreach (var list in ShoppingCartVm.ShoppingCarts) { list.Price = SD.GetPriceBasedOnQuatity(list.Count, list.Product.Price, list.Product.Price50, list.Product.Price100); ShoppingCartVm.OrderHeader.OrderTotal += (list.Price * list.Count); } ShoppingCartVm.OrderHeader.Name = ShoppingCartVm.OrderHeader.ApplicationUser.Name; ShoppingCartVm.OrderHeader.PhoneNumber = ShoppingCartVm.OrderHeader.ApplicationUser.PhoneNumber; ShoppingCartVm.OrderHeader.StreetAddress = ShoppingCartVm.OrderHeader.ApplicationUser.StreetAddress; ShoppingCartVm.OrderHeader.City = ShoppingCartVm.OrderHeader.ApplicationUser.City; ShoppingCartVm.OrderHeader.State = ShoppingCartVm.OrderHeader.ApplicationUser.State; ShoppingCartVm.OrderHeader.PostalCode = ShoppingCartVm.OrderHeader.ApplicationUser.PostalCode; return(View(ShoppingCartVm)); }
public IActionResult Index() { var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ShoppingCartVm = new ShoppingCartVM() { ShoppingCarts = _context.ShoppingCarts .Where(s => s.ApplicationUserId == claim.Value).Include(s => s.Product).ToList(), OrderHeader = new OrderHeader() }; ShoppingCartVm.OrderHeader.OrderTotal = 0; ShoppingCartVm.OrderHeader.ApplicationUser = _context.Users .FirstOrDefault(a => a.Id == claim.Value); foreach (var shoppingCart in ShoppingCartVm.ShoppingCarts) { shoppingCart.Price = SD.GetPriceBasedOnQuatity(shoppingCart.Count, shoppingCart.Product.Price, shoppingCart.Product.Price50, shoppingCart.Product.Price100); ShoppingCartVm.OrderHeader.OrderTotal += (shoppingCart.Price * shoppingCart.Count); } return(View(ShoppingCartVm)); }
public IActionResult Summary() { if (TempData["trxId"] != null) { ViewBag.TrxId = "trxid is missing"; } var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ShoppingCartVm = new ShoppingCartVM() { OrderHeader = new OrderHeader(), ShoppingCarts = _context.ShoppingCarts.Include(s => s.Product).Where(c => c.ApplicationUserId == claim.Value).ToList() }; ShoppingCartVm.OrderHeader.ApplicationUser = _context.Users .FirstOrDefault(u => u.Id == claim.Value); foreach (var list in ShoppingCartVm.ShoppingCarts) { list.Price = SD.GetPriceBasedOnQuatity(list.Count, list.Product.Price, list.Product.Price50, list.Product.Price100); ShoppingCartVm.OrderHeader.OrderTotal += (list.Price * list.Count); } ShoppingCartVm.OrderHeader.Name = ShoppingCartVm.OrderHeader.ApplicationUser.UserName; ShoppingCartVm.OrderHeader.PhoneNumber = ShoppingCartVm.OrderHeader.ApplicationUser.PhoneNumber; return(View(ShoppingCartVm)); }
public IActionResult Plus(int cartId) { var cart = _unitOfWork.ShoppingCart.GetFirstOrDefault(c => c.Id == cartId, includeProperties: "Product"); cart.Count += 1; cart.Price = SD.GetPriceBasedOnQuatity(cart.Count, cart.Product.Price, cart.Product.Price50, cart.Product.Price100); _unitOfWork.Save(); return(RedirectToAction(nameof(Index))); }
public IActionResult Plus(int cartId) { var cart = _context.ShoppingCarts.Include(s => s.Product).FirstOrDefault(c => c.Id == cartId); cart.Count += 1; cart.Price = SD.GetPriceBasedOnQuatity(cart.Count, cart.Product.Price, cart.Product.Price50, cart.Product.Price100); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public IActionResult SummaryPost() { if (ShoppingCartVm.OrderHeader.TransactionId == null) { TempData["trxId"] = "trxid is missing"; return(RedirectToAction("Summary")); } var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ShoppingCartVm.OrderHeader.ApplicationUser = _context.Users.FirstOrDefault(c => c.Id == claim.Value); ShoppingCartVm.ShoppingCarts = _context.ShoppingCarts.Where(s => s.ApplicationUserId == claim.Value).Include(s => s.Product).ToList(); ShoppingCartVm.OrderHeader.OderStatus = SD.OrderStatusPending; ShoppingCartVm.OrderHeader.PaymentStatus = SD.PaymentStatusPending; ShoppingCartVm.OrderHeader.ApplicationUserId = claim.Value; ShoppingCartVm.OrderHeader.OrderDate = DateTime.Now; ShoppingCartVm.OrderHeader.PaymentDate = DateTime.Now; _context.OrderHeaders.Add(ShoppingCartVm.OrderHeader); _context.SaveChanges(); foreach (var item in ShoppingCartVm.ShoppingCarts) { item.Price = SD.GetPriceBasedOnQuatity(item.Count, item.Product.Price, item.Product.Price50, item.Product.Price100); OrderDetails orderDetails = new OrderDetails() { ProductId = item.ProductId, OrderId = ShoppingCartVm.OrderHeader.Id, Count = item.Count, Price = item.Price }; ShoppingCartVm.OrderHeader.OrderTotal += orderDetails.Count * orderDetails.Price; _context.OrderDetails.Add(orderDetails); _context.SaveChanges(); } _context.ShoppingCarts.RemoveRange(ShoppingCartVm.ShoppingCarts); HttpContext.Session.SetInt32("Session_ShoppingCart", 0); return(RedirectToAction("OrderConfirmation", "Cart", new { id = ShoppingCartVm.OrderHeader.Id })); }
public IActionResult Index() { var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ShoppingCartVm = new ShoppingCartVM() { ShoppingCarts = _unitOfWork.ShoppingCart .GetAll(s => s.ApplicationUserId == claim.Value, includeProperties: "Product"), OrderHeader = new OrderHeader() }; ShoppingCartVm.OrderHeader.OrderTotal = 0; ShoppingCartVm.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser .GetFirstOrDefault(a => a.Id == claim.Value, includeProperties: "Company"); foreach (var shoppingCart in ShoppingCartVm.ShoppingCarts) { shoppingCart.Price = SD.GetPriceBasedOnQuatity(shoppingCart.Count, shoppingCart.Product.Price, shoppingCart.Product.Price50, shoppingCart.Product.Price100); ShoppingCartVm.OrderHeader.OrderTotal += (shoppingCart.Price * shoppingCart.Count); if (shoppingCart.Product.Description != null) { shoppingCart.Product.Description = SD.ConvertToRawHtml(shoppingCart.Product.Description); if (shoppingCart.Product.Description.Length > 100) { shoppingCart.Product.Description = shoppingCart.Product.Description.Substring(0, 99) + "..."; } } } return(View(ShoppingCartVm)); }
public IActionResult Minus(int cartId) { var cart = _unitOfWork.ShoppingCart.GetFirstOrDefault(c => c.Id == cartId, includeProperties: "Product"); if (cart.Count == 1) { var cnt = _unitOfWork.ShoppingCart.GetAll(sC => sC.ApplicationUserId == cart.ApplicationUserId).ToList().Count(); _unitOfWork.ShoppingCart.Remove(cart); _unitOfWork.Save(); HttpContext.Session.SetInt32(SD.Session_ShoppingCart, cnt - 1); } else { cart.Count -= 1; cart.Price = SD.GetPriceBasedOnQuatity(cart.Count, cart.Product.Price, cart.Product.Price50, cart.Product.Price100); _unitOfWork.Save(); } return(RedirectToAction(nameof(Index))); }
public IActionResult Minus(int cartId) { var cart = _context.ShoppingCarts.Include(s => s.Product).FirstOrDefault(c => c.Id == cartId); if (cart.Count == 1) { var cnt = _context.ShoppingCarts.Where(sC => sC.ApplicationUserId == cart.ApplicationUserId).ToList().Count(); _context.ShoppingCarts.Remove(cart); _context.SaveChanges(); HttpContext.Session.SetInt32("Session_ShoppingCart", cnt - 1); } else { cart.Count -= 1; cart.Price = SD.GetPriceBasedOnQuatity(cart.Count, cart.Product.Price, cart.Product.Price50, cart.Product.Price100); _context.SaveChanges(); } return(RedirectToAction(nameof(Index))); }
public IActionResult SummaryPost(string stripeToken) { var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); ShoppingCartVm.OrderHeader.ApplicationUser = _unitOfWork.ApplicationUser.GetFirstOrDefault(c => c.Id == claim.Value, includeProperties: "Company"); ShoppingCartVm.ShoppingCarts = _unitOfWork.ShoppingCart.GetAll(s => s.ApplicationUserId == claim.Value, includeProperties: "Product"); ShoppingCartVm.OrderHeader.OderStatus = SD.OrderStatusPending; ShoppingCartVm.OrderHeader.PaymentStatus = SD.PaymentStatusPending; ShoppingCartVm.OrderHeader.ApplicationUserId = claim.Value; ShoppingCartVm.OrderHeader.OrderDate = DateTime.Now; _unitOfWork.OrderHeader.Add(ShoppingCartVm.OrderHeader); _unitOfWork.Save(); List <OrderDetails> orderDetailsList = new List <OrderDetails>(); foreach (var item in ShoppingCartVm.ShoppingCarts) { item.Price = SD.GetPriceBasedOnQuatity(item.Count, item.Product.Price, item.Product.Price50, item.Product.Price100); OrderDetails orderDetails = new OrderDetails() { ProductId = item.ProductId, OrderId = ShoppingCartVm.OrderHeader.Id, Count = item.Count, Price = item.Price }; ShoppingCartVm.OrderHeader.OrderTotal += orderDetails.Count * orderDetails.Price; _unitOfWork.OrderDetails.Add(orderDetails); } _unitOfWork.ShoppingCart.RemoveRange(ShoppingCartVm.ShoppingCarts); _unitOfWork.Save(); HttpContext.Session.SetInt32(SD.Session_ShoppingCart, 0); if (stripeToken == null) { } else { // process the payment var option = new ChargeCreateOptions() { Amount = Convert.ToInt32(ShoppingCartVm.OrderHeader.OrderTotal * 100), Currency = "usd", Description = "Order Id :" + ShoppingCartVm.OrderHeader.Id, Source = stripeToken }; var service = new ChargeService(); Charge charge = service.Create(option); if (charge.BalanceTransactionId == null) { ShoppingCartVm.OrderHeader.PaymentStatus = SD.PaymentStatusRejected; } else { ShoppingCartVm.OrderHeader.TransactionId = charge.BalanceTransactionId; } if (charge.Status.ToLower() == "succeeded") { ShoppingCartVm.OrderHeader.PaymentStatus = SD.PaymentStatusApproved; ShoppingCartVm.OrderHeader.OderStatus = SD.OrderStatusApproved; ShoppingCartVm.OrderHeader.PaymentDate = DateTime.Now; } } _unitOfWork.Save(); return(RedirectToAction("OrderConfirmation", "Cart", new { id = ShoppingCartVm.OrderHeader.Id })); }