protected void ButtonAddProduct_Click(object sender, EventArgs e) { try { int pid = int.Parse(ddlProduct.SelectedValue.ToString()); var product = theGateContext.Products.Where(p => p.productID == pid).FirstOrDefault(); var neworderline = new OrderLine() { productID = product.productID, quantity = int.Parse(TextBoxProductQuantity.Text), orderID = orderA.orderID, price = product.price }; theGateContext.OrderLines.Add(neworderline); theGateContext.SaveChanges(); TextBoxProductQuantity.Text = string.Empty; ddlProduct.SelectedIndex = 0; LoadOrderDetails(); } catch (Exception ex) { PanelAddAlertError.Visible = true; LabelAddAlert.Text = "Error adding new product: " + ex.Message; } }
protected string GetOrderLinePrice(OrderLine ol) { return ol.price.ToString("C"); }
protected string GetOrderLineProduct(OrderLine ol) { return ol.Product.productName; }
protected string GetOrderLineTotal(OrderLine ol) { return (ol.price * ol.quantity).ToString("C"); }
protected void ProceedBtn_Click(object sender, EventArgs e) { var order = new Order() { type = 1, state = 1, contactID = contact.contactID, accountID = contact.accountID, dateMade = DateTime.Now }; theGateContext.Orders.Add(order); theGateContext.SaveChanges(); int orderIdVal = order.orderID; Dictionary<string, int> ht = (Dictionary<string, int>)Session["cartHashTable"]; foreach (var pair in ht) { Session["currentKey"] = pair.Key; var orderline = new OrderLine() { orderID = orderIdVal, productID = Product.productID, quantity = pair.Value, price = pair.Value * Product.price }; theGateContext.OrderLines.Add(orderline); theGateContext.SaveChanges(); } Dictionary<string, int> clearHT = new Dictionary<string, int>(); Session["cartHashTable"] = clearHT; Response.Redirect("OrderSuccess.aspx"); }