public async Task <IActionResult> PutProductOrders(int id, ProductOrders productOrders) { if (id != productOrders.ID) { return(BadRequest()); } _context.Entry(productOrders).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductOrdersExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Edit(int id, [Bind("ProductOrderId,ProductId,OrderId,Quantity")] ProductOrders productOrders) { if (id != productOrders.ProductOrderId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productOrders); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductOrdersExists(productOrders.ProductOrderId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["OrderId"] = new SelectList(_context.Orders, "OrderId", "OrderId", productOrders.OrderId); ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "Name", productOrders.ProductId); return(View(productOrders)); }
public async Task <ActionResult <ProductOrders> > PostProductOrders(ProductOrders productOrders) { _context.ProductOrders.Add(productOrders); await _context.SaveChangesAsync(); return(CreatedAtAction("GetProductOrders", new { id = productOrders.ID }, productOrders)); }
public int CorrectPriority(int priority) { if (priority <= 0) { return(1); } int count = ProductOrders.Count(); return(priority > count ? count : priority); }
public static XtraReport ProductOrders(IEnumerable <OrderItem> sales, IList <State> states, bool sortByOrderDate, DateTime fromDate, DateTime toDate) { var report = new ProductOrders(); report.DataSource = sales; report.SetStates(states); report.Parameters["paramOrderDate"].Value = sortByOrderDate; report.Parameters["paramFromDate"].Value = fromDate; report.Parameters["paramToDate"].Value = toDate; return(report); }
static XtraReport CreateProductOrdersReport(long productID) { var report = new ProductOrders(); var product = DataProvider.Products.FirstOrDefault(p => p.Id == productID); if (product != null) { report.DataSource = product.OrderItems; } report.SetStates(DataProvider.States.ToList()); return(report); }
public async Task <IActionResult> Create([Bind("ProductOrderId,ProductId,OrderId,Quantity")] ProductOrders productOrders) { if (ModelState.IsValid) { _context.Add(productOrders); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["OrderId"] = new SelectList(_context.Orders, "OrderId", "OrderId", productOrders.OrderId); ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "Name", productOrders.ProductId); return(View(productOrders)); }
// GET: Products public ActionResult Index(int?productId) { var viewModel = new ProductOrders(); viewModel.Products = db.Products.Include(i => i.Orders); if (productId != null) { ViewBag.productId = productId.Value; viewModel.Orders = viewModel.Products.Where( i => i.productId == productId.Value).Single().Orders; } return(View(viewModel)); }
// GET: Customers public ActionResult Index(int?id, int?customerId) { //var view = db.Customer.Include(c => c.Orders); //return View(); var viewModel = new ProductOrders(); viewModel.Customers = db.Customer; if (customerId != null) { ViewBag.customerId = customerId.Value; viewModel.Orders = viewModel.Customers.Where( i => i.customerId == customerId.Value).Single().Orders; } // .Include(i => i.Orders) // .OrderBy(i => i.lastname); //return view(viewModel); return(View(viewModel)); }
public ActionResult Order(OrderViewModel orderViewModel) { if (ModelState.IsValid) { using (ShopDbDataContext db = new ShopDbDataContext()) { Orders newOrder = new Orders { UserId = orderViewModel.UserId, Address = orderViewModel.Address, Phone = orderViewModel.Phone, Price = orderViewModel.Price, DateOfOrder = DateTime.Now }; db.Orders.InsertOnSubmit(newOrder); db.SubmitChanges(); foreach (var product in orderViewModel.ProductsToBuy) { ProductOrders newProductOrder = new ProductOrders { OrderId = newOrder.Id, ProductId = int.Parse(product.Key), Quantity = int.Parse(product.Value) }; db.ProductOrders.InsertOnSubmit(newProductOrder); } var cartToDelete = db.Carts.Where(c => c.UserId == orderViewModel.UserId); db.Carts.DeleteAllOnSubmit(cartToDelete); db.SubmitChanges(); } return(View("OrderDone")); } else { return(View(orderViewModel)); } }
public IActionResult addItemToCart(int id) { //this section should go in the add cart button //create a new order for the guest user Order newOrder = new Order { OrderNumber = HttpContext.Session.GetString("guid"), // total = Product.Price, status = "not processed", }; dbContext.Orders.Add(newOrder); dbContext.SaveChanges(); //search db for the product Product ProductFromDB = dbContext.Products.FirstOrDefault(p => p.ProductId == id); //search for the order with guid so we can get the id of order Order OrderFromdb = dbContext.Orders.FirstOrDefault(o => o.OrderNumber == HttpContext.Session.GetString("guid")); //point product to order ProductOrders newProductOrder = new ProductOrders { OrderId = OrderFromdb.OrderId, // total = Product.Price, ProductId = ProductFromDB.ProductId, }; dbContext.ProductOrders.Add(newProductOrder); dbContext.SaveChanges(); System.Console.WriteLine("//////////////////////////"); return(RedirectToAction("DisplayProductPage", "UserPage", new{ id = 1 })); }
public Task <ActionResult <ProductOrders> > GetOrders(ProductOrders productOrders) { return(null); }