public ActionResult Submit(Invoice i) { int id = placing.getOrderIDs() + 1; ViewData["ID"] = id; ViewData["Email"] = i.NotiAddress; ((Invoice)Session["Index"]).NotiAddress = i.NotiAddress; ((Invoice)Session["Index"]).RID = i.RID; ((Invoice)Session["Index"]).name = i.name; if (ModelState.IsValid) { //Cart temp = ticket; ((Invoice)Session["Index"]).wait = (int)Session["Wait"]; placing.postTicket((Invoice)Session["Index"]); Session["Complete"] = Session["Index"]; //ticket.orderItems = new List<CartItem>(); //ticket.subTotal = 0.0; ticket = null; Session["Index"] = null; Session["Cart"] = null; } return View("Complete"); }
public void postTicket(Invoice ticket) { List<CartItem> orderItem = new List<CartItem>(); int OrderID = getOrderIDs() +1; int beginItemIDs = getItemIDs(); for(int i =0; i<ticket.orderItems.Count; i++) { ticket.orderItems[i].id +=beginItemIDs; } orderItem = ticket.orderItems; conn.Open(); for (int i = 0; i < orderItem.Count; i++) { MySqlCommand comm = conn.CreateCommand(); comm.CommandText = "INSERT INTO raiderplate.orderitem (OrderItemID, ItemID, Quanity, OrderID) VALUES(@a,@b,@c,@d)"; comm.Parameters.AddWithValue("@a", orderItem[i].id); comm.Parameters.AddWithValue("@b", orderItem[i].items.productID); comm.Parameters.AddWithValue("@c", orderItem[i].quantity); comm.Parameters.AddWithValue("@d", OrderID); comm.ExecuteNonQuery(); }; conn.Close(); conn.Open(); MySqlCommand comm2 = conn.CreateCommand(); comm2.CommandText = "INSERT INTO `raiderplate`.`orders` (`OrdersID`, `CustomerID`, `isFinished`,`email`) VALUES (@e, @f, '0',@g);"; comm2.Parameters.AddWithValue("e", OrderID); comm2.Parameters.AddWithValue("f", 1); comm2.Parameters.AddWithValue("g", ticket.NotiAddress); comm2.ExecuteNonQuery(); conn.Close(); //setup email content and send the notification email to users StringBuilder str = new StringBuilder(); str.Append("<h2 align = 'center' style='color:#cc0000'>Your Order ID: " + OrderID+"</h2>"); str.Append("<h4 align='center'>Customer's R Numbers:" + ticket.RID + ".<h4>"); str.Append("<h4 align='center'>Dear " + ticket.name + ", thanks for using our Raider Plate<h4>"); str.Append("<h4 align='center'>Your Order is being prepared. It's ready in about " + ticket.wait + " minutes.<h4>"); str.Append("<h4 align='center'>Item list:<h4>"); str.Append("<table border='1' cellpadding='15' cellspacing='0' align ='center' style='width:auto'><thead><tr>"); str.Append("<th>Kitchen</th><th>Items</th><th>Quantity</th><th>Cost</th></tr></thead>"); str.Append("<tbody>"); foreach (var i in ticket.orderItems) { str.Append("<tr align='center'><td>"+i.items.locationName + "</td><td>" + i.items.productName+ "</td><td>" + i.quantity + "</td><td>$" + Math.Round(i.quantity*i.items.productPrice,2) + "</td></tr>"); } str.Append("</tbody>"); str.Append("<tfoot><tr><td>SubTotal</td><td></td><td></td><td>$ " + ticket.subTotal + "</td></tr><tr>"); str.Append("<td>Total</td><td></td><td></td><td>$ " + Math.Round(ticket.subTotal*1.085,2) + "</td></tr></tfoot></table>"); informUser(OrderID, ticket.NotiAddress, str.ToString()); }