public ActionResult order_now(int id) { OrderMeal order = new OrderMeal(); order.MealId = id; order.UserId = (int)Session["UserId"]; db.OrderMeals.Add(order); db.SaveChanges(); return(Redirect(Request.UrlReferrer.ToString())); }
//SELECT queries are usually to get data for displaying //displayed Order meals are to be derived from qryOrderMeals //UPDATE/INSERT/DELETE queries are for modifying whats in the db //these queries will operate on tblOrderMeals private static OrderMeal ReaderToOrderMeal(OleDbDataReader reader) { OrderMeal orderMeal = new OrderMeal(); orderMeal.ID = (int)reader[QRY_OM_ID]; orderMeal.Name = (string)reader[QRY_NAME]; orderMeal.Quantity = (int)reader[QRY_QUANTITY]; orderMeal.Price = (decimal)reader[QRY_PRICE]; orderMeal.Subtotal = (decimal)reader[QRY_SUBTOTAL]; orderMeal.OrderID = (int)reader[QRY_ORDER]; return(orderMeal); }
public ActionResult DeleteOrder(int id) { int userid = (int)Session["UserId"]; using (DatabaseEntities db = new DatabaseEntities()) { OrderMeal del = db.OrderMeals.Where(y => y.MealId == id && y.UserId == userid).FirstOrDefault(); db.OrderMeals.Remove(del); db.SaveChanges(); return(RedirectToAction("ViewOrders", "Orders")); } }
private bool AlreadyExists(OrderMeal orderMeal) { ServiceOperation operation = CheckIfExists("tblOrderMeals", String.Format("OrderID = {0} AND MealID = {1}", orderMeal.OrderID, orderMeal.MealID)); bool exists = true; if (operation.Success) { if (operation.Data.Count == 0) { exists = false; } } return(exists); }
/// <summary> /// Event for when the "Save" Button is clicked. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { // Bundle data from page controls into object to send to DB. OrderMeal orderMeal = new OrderMeal(); try { int orderID = (int)Session["OrderToEdit_ID"]; orderMeal.ID = int.Parse(lblOrderMealID.Text); orderMeal.OrderID = orderID; orderMeal.MealID = int.Parse(ddlMeals.SelectedValue); orderMeal.OrderedQty = int.Parse(txtOrdQty.Text); } catch (Exception ex) { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = ex.Message; return; } // Send data to DB. CharityKitchenDataServiceSoapClient svc = new CharityKitchenDataServiceSoapClient(); ServiceOperation operation = new ServiceOperation(); if (orderMeal.ID == 0) { operation = svc.AddOrderMeal(orderMeal); } else { operation = svc.UpdateOrderMeal(orderMeal); } if (operation.Success) { lblInfo.ForeColor = System.Drawing.Color.DarkGreen; lblInfo.Text = operation.Message; // Refresh GridView if data was modified. GetOrderMeals(svc); } else { lblInfo.ForeColor = System.Drawing.Color.Red; lblInfo.Text = operation.Message; } }
public ServiceOperation AddOrderMeal(OrderMeal orderMeal) { // If it doesn't exist, then build query and send to DB and return result. if (!AlreadyExists(orderMeal)) { string query = "INSERT INTO tblOrderMeals (OrderID, MealID, OrderedQty) VALUES ({0}, {1}, {2})"; return(SendNonQuery(String.Format(query, orderMeal.OrderID, orderMeal.MealID, orderMeal.OrderedQty))); } // If already exists, make new ServiceOperation reflecting that fact, and return it. ServiceOperation operation = new ServiceOperation(); operation.Success = false; operation.Message = "Already Exists Error"; operation.Exception = "Either that Meal already exists in this Order, or some other unspecified error."; return(operation); }
public ServiceOperation UpdateOrderMeal(OrderMeal orderMeal) { string query = "UPDATE tblOrderMeals SET OrderID={0}, MealID={1}, OrderedQty={2} WHERE OrderMealID={3}"; return(SendNonQuery(String.Format(query, orderMeal.OrderID, orderMeal.MealID, orderMeal.OrderedQty, orderMeal.ID))); }