public IActionResult DeleteToCart(long ProductID) { Product product = repository.Products.FirstOrDefault(p => p.ProductID == ProductID); Itemcart = HttpContext.Session.GetJson <Itemcart>("cart") ?? new Itemcart(); Itemcart.DeleteAItem(product, 1); HttpContext.Session.SetJson("cart", Itemcart); return(Redirect(Request.Headers["Referer"].ToString())); }
public IActionResult RemoveToCart(long ProductID) { Product product = repository.Products.FirstOrDefault(p => p.ProductID == ProductID); Itemcart = HttpContext.Session.GetJson <Itemcart>("cart") ?? new Itemcart(); Itemcart.RemoveItem(product); HttpContext.Session.SetJson("cart", Itemcart); if (Itemcart.Items.Count == 0) { HttpContext.Session.Remove("cart"); } return(Redirect(Request.Headers["Referer"].ToString())); }
public IViewComponentResult Invoke() { Itemcart Items = HttpContext.Session.GetJson <Itemcart>("cart"); return(View(Items)); }
public async Task <IActionResult> Checkout(int payment_method, double total, string firstName, string lastName, string email, string Number, string address) { Random random = new Random(); StringBuilder builder = new StringBuilder(); string OrderOPP = builder.Append(Convert.ToInt32(random.Next(1, 99999))).ToString(); Customer customer = new Customer { CustomerName = firstName + lastName, CustomerEmail = email, CustomerPhone = Number, ImageUrl = null, }; await context.Customers.AddAsync(customer); await context.SaveChangesAsync(); //var customer1 = new Customer(); //Where(c => c.CustomerEmail == customer.CustomerEmail) Models.Order order = new Models.Order { OrderOPP = OrderOPP, CustomerID = customer.CustomerID, OrderAddress = address, ShipMethod = 1, PaymentMethod = payment_method, PaymentStatus = false, TotalPrice = total, dateTime = DateTime.Now, OrderStatus = true }; await context.Orders.AddAsync(order); await context.SaveChangesAsync(); var orderID = order.OrderID; Itemcart Items = HttpContext.Session.GetJson <Itemcart>("cart"); foreach (var item in Items.Items) { OrderItem orderItem = new OrderItem { ProductID = item.Product.ProductID, OrderID = orderID, ProductQty = item.Quantity, }; await context.OrderItems.AddAsync(orderItem); } ; context.SaveChanges(); string url = null; if (payment_method == 2) { HttpContext.Session.Remove("cart"); url = "/"; } else { if (payment_method == 1) { url = await PaypalPayment(total); if (url != null) { order.PaymentStatus = true; context.Update(order); await context.SaveChangesAsync(); HttpContext.Session.Remove("cart"); } ; } } //await sendMailService.SendCheckoutEmailAsync(order); return(Redirect(url)); }
public IActionResult Index() { Itemcart Items = HttpContext.Session.GetJson <Itemcart>("cart"); return(View(Items)); }