private MailMessage BuildMailMessage(Cart cart, DeliveryDetails deliveryDetails, String CustEmail, int OrderKey) { StringBuilder body = new StringBuilder(); body.AppendLine("A new order has been submitted"); body.AppendLine(" "); body.AppendLine("Items:"); body.AppendLine("Item -- Quantity -- Price"); foreach (var line in cart.Lines) { var subtotal = line.MenuItem.Price * line.Quantity; body.AppendLine(line.MenuItem.ProductName + " -- " + line.Quantity + " -- " + line.MenuItem.Price); } body.AppendLine(" "); body.AppendLine("Total order value: " + cart.ComputeTotalValue()); body.AppendLine(" "); body.AppendLine("Deliver to:"); body.AppendLine(deliveryDetails.Firstname + " " + deliveryDetails.Surname); body.AppendLine(deliveryDetails.Address1); body.AppendLine(deliveryDetails.Address2); body.AppendLine(deliveryDetails.Address3); body.AppendLine(deliveryDetails.County); body.AppendLine(deliveryDetails.Country); body.AppendLine("Contact No: " + deliveryDetails.ContactPhone); body.AppendLine("To View Order: http://localhost:49209/OrderDisplay/CustomerDisplayOrders?orderID=" + OrderKey); return new MailMessage("*****@*****.**", // From CustEmail, // To "New order submitted!", // Subject body.ToString()); // Body }
public ActionResult CheckOut(Cart cart, DeliveryDetails deliveryDetails) { // Empty carts can't be checked out if (cart.Lines.Count == 0) ModelState.AddModelError("Cart", "Sorry, your cart is empty!"); if (ModelState.IsValid) { if (Session["CustID"] == null) { CustID = 1; } else { CustID = Convert.ToInt32(Session["CustID"]); CustEmail = Session["EmailAddr"].ToString(); } int orderid = orderSubmitter.SubmitOrder(cart, deliveryDetails, CustID, CustEmail); cart.Clear(); Response.Redirect("/OrderDisplay/CustomerDisplayOrders?orderID=" + orderid); return View("Completed"); } else // Something was invalid return View(deliveryDetails); }
public void SaveDelivery(DeliveryDetails deliveryDetails) { // If its a new product, just attach it to the DataContext if (deliveryDetails.DeliveryID == 0) deliveryTable.InsertOnSubmit(deliveryDetails); else if (deliveryTable.GetOriginalEntityState(deliveryDetails) == null) { // Were updating an existing menu item, but its not attached to the // this data context, so attach it and detect the changes deliveryTable.Attach(deliveryDetails); deliveryTable.Context.Refresh(RefreshMode.KeepCurrentValues, deliveryDetails); } deliveryTable.Context.SubmitChanges(); }
public int SubmitOrder(Cart cart, DeliveryDetails deliveryDetails, int CustID, String CustEmail) { // Need to pass the CustomerID in here!!! int orderKey = orderRepository.CreateOrder(CustID); deliveryDetails.FKOrderID = orderKey; int deliveryKey = deliveryRepository.CreateDelivery(deliveryDetails); orderItemRepository.CreateOrderList(orderKey,cart); using (var smtpClient = new SmtpClient()) using (var mailMessage = BuildMailMessage(cart, deliveryDetails, CustEmail, orderKey)) { smtpClient.Send(mailMessage); } return orderKey; }
public void DeleteItems(DeliveryDetails deliveryDetails) { deliveryTable.DeleteOnSubmit(deliveryDetails); deliveryTable.Context.SubmitChanges(); }
public int CreateDelivery(DeliveryDetails delivery) { SaveDelivery(delivery); return delivery.DeliveryID; }
public int SubmitOrder(Cart cart, DeliveryDetails deliveryDetails, int CustID, String CustEmail) { return 1; }