protected void AddOrderToDB(CartItem ci, int order_code) { XhDataContext db = new XhDataContext(); XhOrder order = new XhOrder(); //get current user order.cust_id = db.XhCustomers.Single(c => c.cust_mail.Equals(User.Identity.Name)).cust_id; order.ord_code = order_code; order.ord_date = DateTime.Now; order.ord_delivered = false; order.ord_quantity = ci.Quantity; order.prod_id = ci.ProductId; db.XhOrders.InsertOnSubmit(order); XhProduct product = db.XhProducts.Single(p => p.prod_id == ci.ProductId); //substract <quantity> units from stock for this product //we can't have negative values in stock! int tempstock = product.prod_stock - order.ord_quantity; if (product.prod_stock > 0 && tempstock > 0) { product.prod_stock = tempstock; } //write changes db.SubmitChanges(); }
internal static void MailOrderDetails(string emailaddress) { XhOrder order = new XhOrder(); ShoppingCart cart = ShoppingCart.GetShoppingCart(); string subj = "Order Confirmation"; string body = "X-Hardware.notld order confirmation" + Environment.NewLine + Environment.NewLine + "Thank you for purchasing with us!" + Environment.NewLine + "This e-mail confirms your order with us. Please keep this mail for further reference." + Environment.NewLine + Environment.NewLine + "Orders:" + Environment.NewLine + Environment.NewLine; double total = 0; foreach (CartItem ci in cart.Items) { //Make changes to mailbody double subtotal = ci.Quantity * ci.UnitPrice; body += "+ " + ci.Quantity + " x \"" + ci.Manufacter + " " + ci.Name + " " + ci.Model + "\" @ " + ci.UnitPrice + " EUR/item = " + subtotal + " EUR subtotal." + Environment.NewLine + Environment.NewLine; total += subtotal; } body += "Total Price: " + total + " EUR" + Environment.NewLine + Environment.NewLine + "The following methods of payment are accepted:" + Environment.NewLine + "* By cash payment on delivery" + Environment.NewLine + "* By bank transfer no more than 5 days after delivery." + Environment.NewLine + Environment.NewLine + "If you choose to work by bank transfer, please use the following information:" + Environment.NewLine + "* International Bank Account Number: IBEN XX98 7654 3210 0123" + Environment.NewLine + "* Comment: Payment for Order Number " + (GetNextOrderId() - 1).ToString(); SendMail(emailaddress, "*****@*****.**", subj, body); }