public ActionResult CompleteOrder() { //finalize the order from cart //shopping cart data int Locationid = int.Parse(HttpContext.Request.Cookies["LocationID"]); int customerid = int.Parse(HttpContext.Request.Cookies["CustomerID"]); int ProductID1 = int.Parse(HttpContext.Request.Cookies["ProID1"]); int ProductID2 = int.Parse(HttpContext.Request.Cookies["ProID2"]); int ProductID3 = int.Parse(HttpContext.Request.Cookies["ProID3"]); int ProductID4 = int.Parse(HttpContext.Request.Cookies["ProID4"]); int ProductID5 = int.Parse(HttpContext.Request.Cookies["ProID5"]); int Amount1 = int.Parse(HttpContext.Request.Cookies["PA1"]); int Amount2 = int.Parse(HttpContext.Request.Cookies["PA2"]); int Amount3 = int.Parse(HttpContext.Request.Cookies["PA3"]); int Amount4 = int.Parse(HttpContext.Request.Cookies["PA4"]); int Amount5 = int.Parse(HttpContext.Request.Cookies["PA5"]); //New Order History OrderHistory orderHistory = new OrderHistory { LocationId = Locationid, CustomerId = customerid }; _orderhistoryRepo.Create(orderHistory); //The new Order ID int orderid = _orderhistoryRepo.GetAll().Count(); //note to self, compress next step into dynamic //new orders if (ProductID1 == 1) { Inventory inventory1 = new Inventory { LocationId = Locationid, ProductId = ProductID1, Amount = Amount1 }; Orders orders1 = new Orders { OrderID = orderid, ProductID = ProductID1, Amount = Amount1 }; //finalize _inventoryRepo.Update(inventory1); _ordersRepo.Create(orders1); } if (ProductID2 == 2) { Inventory inventory2 = new Inventory { LocationId = Locationid, ProductId = ProductID2, Amount = Amount2 }; Orders orders2 = new Orders { OrderID = orderid, ProductID = ProductID2, Amount = Amount2 }; //finalize _inventoryRepo.Update(inventory2); _ordersRepo.Create(orders2); } if (ProductID3 == 3) { Inventory inventory3 = new Inventory { LocationId = Locationid, ProductId = ProductID3, Amount = Amount3 }; Orders orders3 = new Orders { OrderID = orderid, ProductID = ProductID3, Amount = Amount3 }; //finalize _inventoryRepo.Update(inventory3); _ordersRepo.Create(orders3); } if (ProductID4 == 4) { Inventory inventory4 = new Inventory { LocationId = Locationid, ProductId = ProductID4, Amount = Amount4 }; Orders orders4 = new Orders { OrderID = orderid, ProductID = ProductID4, Amount = Amount4 }; //finalize _inventoryRepo.Update(inventory4); _ordersRepo.Create(orders4); } if (ProductID5 == 5) { Inventory inventory5 = new Inventory { LocationId = Locationid, ProductId = ProductID5, Amount = Amount5 }; Orders orders5 = new Orders { OrderID = orderid, ProductID = ProductID5, Amount = Amount5 }; //finalize _inventoryRepo.Update(inventory5); _ordersRepo.Create(orders5); } return(RedirectToAction(nameof(Index))); }
public async Task <bool> MakeOrderAsync(/*string name, string emailAddress*/ OrderData data) { //OrderData: [email protected], adresa, [{id=1], {id=4}], quantity bool isCreated = true; /* * * * * String orderId = Guid.NewGuid().ToString(); * MakeOder(OrderData data){ * foreach(products in data.products){ * * OrderHistory order = new OrderHistory * { * Id = Guid.NewGuid().ToString(), * OrderId = orderId, * CompleteName = DATA.name, * EmailAddress = emailAddress, * EquipmentId = products.id, * Quantity = products.quantity * * * }; * _orderHistoryRepository.Create(order); * } * } */ String orderId = Guid.NewGuid().ToString(); int totalPrice = 0; foreach (OrderProduct products in data.Products) { totalPrice = totalPrice + products.Price * int.Parse(products.Quantity); } int saleTotal = totalPrice - (25 * totalPrice) / 100; foreach (OrderProduct products in data.Products) { OrderHistory order = new OrderHistory { Id = Guid.NewGuid().ToString(), OrderId = orderId, CompleteName = data.Name, EmailAddress = data.Email, EquipmentId = products.Id, ProductQuantity = products.Quantity, DeliveryAddress = data.DeliveryAddress, TotalPrice = totalPrice, }; _orderHistoryRepository.Create(order); } string tableContent = ""; string tableHead = "<table><tr><th>Product Name</th><th></th><th>Measure</th><th>Quantity</th><th>Price</th></tr>"; string tableEnd = "</table>"; string totalTableVoucherPrice = "<br></br><br></br><table><tr><th></th><th>Total Price</th></tr>" + "<tr><td>TOTAL ORDER</td><td>" + totalPrice.ToString() + " RON" + "</td></tr><tr><td>-25% OFF VOUCHER</td><td>" + saleTotal + " RON" + "</td></tr><tr><td>EXPRESS COURIER DELIVERY</td><td> 10 RON </td></tr><tr><td>TOTAL ORDER VALUE</td><td>" + (saleTotal + 10).ToString() + " RON" + "</td></tr></table>"; string totalTablePrice = "<br></br><br></br><table><tr><th></th><th>Total Price</th></tr><tr><td>EXPRESS COURIER DELIVERY</td><td> 10 RON </td></tr>" + "<tr><td>TOTAL ORDER</td><td>" + totalPrice.ToString() + " RON" + "</td></tr><tr><td>TOTAL ORDER VALUE</td><td>" + (totalPrice + 10).ToString() + " RON" + "</td></tr></table>"; string details = "<br></br><br></br>Your products will be delivered in a maximum of 2-3 working days by express courier." + "<br></br><br></br>" + "The order was registered in the name of " + data.Name + " and the delivery address is " + data.DeliveryAddress + "." + "<br></br><br></br>" + "Before delivery, the courier will contact you at the number " + data.PhoneNumber + "." + "<br></br><br></br>" + "Do not hesitate to contact us in case of any questions or problems, thank you for the order you made on our site, " + "<br></br><br></br>" + "Just Move Team ."; foreach (OrderProduct products in data.Products) { tableContent = tableContent + "<tr><td>" + products.Name + "</td>" + "<td>" + "<p><img src='" + products.Image + "'</p> " + "</td>" + "<td> " + products.Measure + "</td>" + "<td> " + products.Quantity + "</td>" + "<td> " + products.Price + " RON" + "</td></tr>"; } if (data.AppliedVoucher == true) { string message = "Dear " + data.Name + ", your order on our website has been registered." + "<br></br><br></br>" + "Your order summary is:" + "<br></br><br></br>" + tableHead + tableContent + tableEnd + totalTableVoucherPrice + details; await _emailSender.SendEmailAsync(data.Email /*"*****@*****.**"*/, "Order Confirmation", message); } else { string message = "Dear " + data.Name + ", your order on our website has been registered." + "<br></br><br></br>" + "Your order summary is:" + "<br></br><br></br>" + tableHead + tableContent + tableEnd + totalTablePrice + details; await _emailSender.SendEmailAsync(data.Email /*"*****@*****.**"*/, "Order Confirmation", message); } /* OrderHistory order = new OrderHistory * { * Id = Guid.NewGuid().ToString(), * * CompleteName = name, * * EmailAddress = emailAddress * * * }; * _orderHistoryRepository.Create(order);*/ return(isCreated); }