public IActionResult Index() { using (var context = new ProjektSklepContext()) { var paymentMethods = context.PaymentMethods.ToList(); var shippingMethods = context.ShippingMethods.ToList(); ViewData["PaymentMethods"] = new SelectList(paymentMethods, "PaymentMethodID", "Name"); ViewData["ShippingMethods"] = new SelectList(shippingMethods, "ShippingMethodID", "Name"); } _shoppingCart = CreateCart(); return(View(_shoppingCart)); }
public IActionResult Index(int?ProductID) { if (ProductID == null) { return(NotFound()); } using (var context = new ProjektSklepContext()) { var paymentMethods = context.PaymentMethods.ToList(); var shippingMethods = context.ShippingMethods.ToList(); ViewData["PaymentMethods"] = new SelectList(paymentMethods, "PaymentMethodID", "Name"); ViewData["ShippingMethods"] = new SelectList(shippingMethods, "ShippingMethodID", "Name"); } _shoppingCart = CreateCart(); var toRemove = _shoppingCart.ProductList.Find(x => x.Product.ProductID == ProductID); if (toRemove != null) { if (toRemove.Count > 1) { toRemove.Count--; toRemove.Sum -= toRemove.Product.Price; } else if (toRemove.Count == 1) { toRemove.Count--; toRemove.Sum -= toRemove.Product.Price; _shoppingCart.ProductList.Remove(toRemove); } } UpdateCookies(); return(View(_shoppingCart)); }
public CategoriesController(ProjektSklepContext context) { _context = context; }
public IActionResult OrderCompleted([Bind("PaymentMethodID,ShippingMethodID,DiscountCode")] ShoppingCart ShoppingCart) { var cart = CreateCart(); ShoppingCart.ProductList = cart.ProductList; ShoppingCart.CartPrice = cart.countCartPrice(); if (ModelState.IsValid) { if (ShoppingCart.ProductList.Count != 0) { using (var context = new ProjektSklepContext()) { var order = new Order { OrderStatus = State.Preparing, PaymentMethodID = ShoppingCart.PaymentMethodID, ShippingMethodID = ShoppingCart.ShippingMethodID, CustomerID = 1 // zmienić customera na tego zalogowanego }; context.Orders.Add(order); context.SaveChanges(); // dodanie OrderID przez EFCORE foreach (var product in ShoppingCart.ProductList) { for (int i = 0; i < product.Count; i++) { var productOrder = new ProductOrder { OrderID = order.OrderID, ProductID = product.Product.ProductID }; context.ProductOrders.Add(productOrder); } } context.SaveChanges(); var shippingMethod = context.ShippingMethods.Where(x => x.ShippingMethodID == ShoppingCart.ShippingMethodID).FirstOrDefault(); var paymentMethod = context.PaymentMethods.Where(x => x.PaymentMethodID == ShoppingCart.PaymentMethodID).FirstOrDefault(); var discountCode = context.DiscountCodes.Where(x => x.DiscoundCode == ShoppingCart.DiscountCode).FirstOrDefault(); ViewData["CenaBezRabatu"] = ShoppingCart.CartPrice; if (shippingMethod != null) { ViewData["ShippingMethod"] = shippingMethod.Name; } if (paymentMethod != null) { ViewData["PaymentMethod"] = paymentMethod.Name; } if (discountCode != null) { ViewData["DiscountCode"] = discountCode.Percent; decimal newPrice = ShoppingCart.CartPrice - (ShoppingCart.CartPrice * discountCode.Percent / 100); ShoppingCart.CartPrice = newPrice; } else { ViewData["DiscountCode"] = 0; } } } } return(View(ShoppingCart)); }
public ShoppingCartController(ILogger <HomeController> logger, ProjektSklepContext context) { _logger = logger; _context = context; }
public ExpertsController(ProjektSklepContext context) { _context = context; }
public ShippingMethodsController(ProjektSklepContext context) { _context = context; }
public AttachmentsController(ProjektSklepContext context) { _context = context; }
public ProductOrdersController(ProjektSklepContext context) { _context = context; }
public PageConfigurationsController(ProjektSklepContext context) { _context = context; }
public AddressesController(ProjektSklepContext context) { _context = context; }
public CustomersController(ProjektSklepContext context) { _context = context; }
public PaymentMethodsController(ProjektSklepContext context) { _context = context; }
public DiscountCodesController(ProjektSklepContext context) { _context = context; }