public async Task <IActionResult> PutOrder_Products([FromRoute] int id, [FromBody] Order_Products order_Products) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != order_Products.SerialNo) { return(BadRequest()); } _context.Entry(order_Products).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Order_ProductsExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task OnGetAsync() { Employee1 = HttpContext.Session.GetLogin(_context.Employee); Employees = await _context.Employee .Where(r => r.EmployeeID == Employee1.EmployeeID).ToListAsync(); Order = await _context.Order .Include(o => o.Customer) .Include(o => o.Employee).ToListAsync(); Customer = await _context.Customer.ToListAsync(); Product = await _context.Product.ToListAsync(); Order_Products = await _context.Order_Product.ToListAsync(); var a = new List <groupProduct>(); foreach (var item in Product) { var z = new groupProduct(); var group_product = Order_Products.Where(s => s.ProductID == item.ProductID).ToList(); z.sum = group_product.Sum(s => s.Qty); z.product = item; a.Add(z); } groupProducts = a; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { grd_customerorders.DataSource = Order_Products.GetCustomerOrder(3); grd_customerorders.DataBind(); } }
public async Task <IActionResult> PostOrder_Products([FromBody] Order_Products order_Products) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Orders_Products.Add(order_Products); await _context.SaveChangesAsync(); return(CreatedAtAction("GetOrder_Products", new { id = order_Products.SerialNo }, order_Products)); }
public async Task <IActionResult> GetProduct([FromBody] OrderInfo OrderInfoObj) { List <int> Id = OrderInfoObj.ProductIds; string Status = OrderInfoObj.Status; int totalItems = 0; float price = 0; float sumTax = 0; List <Product> PID = new List <Product>(); //lastId=(from order in _context.Orders // select order.Order_Idd).Max(); //lastId++; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } foreach (int item in Id) { var product = await _context.Products.FindAsync(item); if (product == null) { return(NotFound()); } PID.Add(product); totalItems++; price += product.Product_Price; sumTax += product.Product_Tax; } Order OrderUser = new Order(); OrderUser.Order_Status = Status; OrderUser.Total_Items = totalItems; OrderUser.Total_Price = price; OrderUser.Total_Sum_Tax = sumTax; OrderUser.Total_Tax = sumTax; await PostOrder(OrderUser); foreach (var item in PID) { Order_Products reference = new Order_Products(); reference.Order_ref = OrderUser; reference.Product_ref = item; await PostOrder_Products(reference); } return(Ok()); }
// GET: Checkout public ActionResult Checkout() { // Open and automatically dispose of database. using (ProductsEntities database = new ProductsEntities()) { // Convert session object to int for use with database. var convertInt = Convert.ToInt32(Session["UserId"]); // Get the cart dictionary from the session variable. Dictionary <Product, int> cart = (Dictionary <Product, int>)Session["cart"]; // If no order for the session exists. if (Session["OrderId"] == null) { // Get customers that match the session UserId. var cust = from c in database.Customers where c.UserId == convertInt select c; // Create a new Order for adding to the database. Order order = new Order(); // Get the customer found in the above linq query. Customer customer = cust.FirstOrDefault(); // Assign the order details. order.CustId = customer.CustId; order.OrderDate = DateTime.Now; order.OrderStatus = "OPEN"; // Add the order to the database and save. database.Orders.Add(order); database.SaveChanges(); // Loop through the cart. foreach (KeyValuePair <Product, int> entry in cart) { // Order the products, recording OrderId, ProductId, quantity and current price. Order_Products ordProd = new Order_Products(); ordProd.OrderID = order.OrderId; ordProd.ProductID = entry.Key.ProductID; ordProd.Quantity = entry.Value; ordProd.Price = entry.Key.Price; // Add the product orders to the database and save the changes. database.Order_Products.Add(ordProd); database.SaveChanges(); } // Set the session variable OrderId to indicate the order has been created and products added. Session["OrderId"] = order.OrderId; } // If the order already exists. else { // Convert the session order id to an int for use with the database. var convertIntOrder = Convert.ToInt32(Session["OrderId"]); // Find all the product orders for the session Order ID. var orderProd = from o in database.Order_Products where o.OrderID == convertIntOrder select o; // Remove the product orders from the database. foreach (var op in orderProd) { database.Order_Products.Remove(op); } // Re-add the product orders from the cart to the database to reflect any new changes. // Loop through the cart. foreach (KeyValuePair <Product, int> entry in cart) { // Order the products, recording OrderId, ProductId, quantity and current price. Order_Products ordProd = new Order_Products(); ordProd.OrderID = convertIntOrder; ordProd.ProductID = entry.Key.ProductID; ordProd.Quantity = entry.Value; ordProd.Price = entry.Key.Price; // Add the product orders to the database. database.Order_Products.Add(ordProd); } // Save the database changes. database.SaveChanges(); } return(View()); } }
public IActionResult SubmitOrder(BillingAddresses newBilling, ShippingAddresses newShipping, PaymentMethods newPayment, string month, string year) { var user = HttpContext.Session.GetInt32("user"); var cart = _context.Cart.Where(x => x.UsersId == (int)user).Include(y => y.Product).ToList(); string expiration = month + "/" + year; if (ModelState.IsValid) { _context.BillingAddresses.Add(newBilling); _context.ShippingAddresses.Add(newShipping); _context.SaveChanges(); PaymentMethods newPay = new PaymentMethods() { UsersId = (int)user, BillingAddressesId = newBilling.id, card_type = newPayment.card_type, card_name = newPayment.card_name, card_num = newPayment.card_num, card_ccv = newPayment.card_ccv, card_exp = expiration, nickname = newPayment.nickname, }; _context.PaymentMethods.Add(newPay); _context.SaveChanges(); Orders newOrder = new Orders() { UsersId = (int)user, BillingAddressesId = newBilling.id, ShippingAddressesId = newShipping.id, PaymentMethodsId = newPay.id, order_status = "Processing" }; _context.Orders.Add(newOrder); _context.SaveChanges(); foreach (var item in cart) { Inventory updateInventory = _context.Inventory.FirstOrDefault(x => x.ProductsId == item.ProductsId); Order_Products newItem = new Order_Products() { OrdersId = newOrder.id, ProductsId = item.ProductsId, quantity = item.quantity, cost = item.cost }; updateInventory.quantity_new -= item.quantity; updateInventory.quantity_sold += item.quantity; _context.Order_Products.Add(newItem); _context.Cart.Remove(item); _context.SaveChanges(); } return(RedirectToAction("OrderView")); } ViewBag.cart = _context.Cart.Where(x => x.UsersId == HttpContext.Session.GetInt32("user")) .Include(y => y.Product).ThenInclude(z => z.Prices) .Include(y => y.Product).ThenInclude(z => z.product_img).ToList(); ViewBag.cost = 0; foreach (var item in ViewBag.cart) { ViewBag.cost += item.cost; } return(View("Checkout")); }