public int AddMenuItem(int id, int side_id) { user authUser = Util.User.UserUtil.getAuthenticatedUser(Request); if (authUser == null) return -1; order currentOrder = (order)Session["ORDER"]; if (currentOrder == null) { currentOrder = Util.Session.SessionUtil.getOpenOrder(authUser); if (currentOrder == null) { currentOrder = new order(); currentOrder.order_status = (int)OrderStatusHelper.OrderStatusEnum.OPEN; currentOrder.user_id = authUser.id; currentOrder.table_id = authUser.current_table_id; } else { if (currentOrder.order_status == (int)OrderStatusHelper.OrderStatusEnum.PLACED || currentOrder.order_status == (int)OrderStatusHelper.OrderStatusEnum.OPEN) { currentOrder.order_status = (int)OrderStatusHelper.OrderStatusEnum.EDITING; db.orders.Find(currentOrder.id).order_status = currentOrder.order_status; om.edit(currentOrder); } else { ViewBag.error = "Your order cannot be editied because it is already being processed"; return -1; } } Session["ORDER"] = currentOrder; } menu_item mi = db.menu_item.Find(id); if (mi == null) { return -1; // failure; } side si; if (side_id == -1) { si = new side(); si.id = side_id; } else { si = db.sides.Find(side_id); if (si == null) { return -1; } } const OrderStatusHelper.OrderItemStatusEnum status = OrderStatusHelper.OrderItemStatusEnum.PENDING; currentOrder.AddMenuItem(mi, si, status); Session["ORDER"] = currentOrder; return currentOrder.id; }
public ReviewVM(review review,order order) { this.is_anonymous = false; this.review = review; this.review_order_items = new List<review_order_item>(); this.order = order; createReviewOrderItemList(order); }
public OrderVM(order order) { if (order != null) { this.order = new order(order); } this.orderItemVMs = new List<OrderItemVM>(); checkObjects(); }
/// <summary> /// Write a order object to the database /// </summary> /// <param name="order">The order object to write</param> /// <param name="setToDefault">If true, sets the order object to default values, if false: leaves object unmodified</param> /// <returns>True if successful, false otherwise</returns> public bool Create(order order, bool setToDefault) { if (setToDefault) { order.order_status = (int)OrderStatusHelper.OrderStatusEnum.PLACED; order.timestamp = DateTime.Now; } db.orders.Add(order); return (db.SaveChanges() == 1); }
public static bool CheckItemsRemaining(order order) { foreach (order_item oi in order.order_item) { if ((oi.bill_id == null || oi.bill_id <= 0) && oi.bill == null) { return true; } } return false; }
/// <summary> /// for each order item in the order, create a place holder in the review order items /// </summary> /// <param name="order"></param> private void createReviewOrderItemList(order order) { foreach (order_item oi in order.order_item) { if (oi.review_order_item.Count == 0) { review_order_item roi = new review_order_item(); roi.order_item = oi; roi.order_item_id = oi.id; review_order_items.Add(roi); } } }
public static void MyClassInitialize(TestContext testContext) { testDatabase = new TestDatabaseHelper(); //Add test data (order specific) restaurant1 = testDatabase.AddRestaurant(); table1 = testDatabase.AddTable(restaurant1); order1 = testDatabase.AddOrder(table1); item1 = testDatabase.AddItem(); category1 = testDatabase.AddCategory(); menu1 = testDatabase.AddMenu(restaurant1); menuCategory1 = testDatabase.AddMenuCategory(category1, menu1); menuItem1 = testDatabase.AddMenuItem(item1, menuCategory1); }
public static bool CheckProcessing(order order) { bool processing = true; foreach (order_item oi in order.order_item) { if (oi.order_item_status == (int)OrderStatusHelper.OrderItemStatusEnum.PLACED || oi.order_item_status == (int)OrderStatusHelper.OrderItemStatusEnum.PENDING) { processing = false; break; } } return processing; }
public order(order order) { id = order.id; order_item = order.order_item; order_status = order.order_status; table_id = order.table_id; table = order.table; timestamp = order.timestamp; total = order.total; user = order.user; user_id = order.user_id; version = order.version; waiter = order.waiter; waiter_id = order.waiter_id; written_by = order.written_by; }
public static void mergeExistingOrderToDb(order order) { order initialOrder = db.orders.Find(order.id); db.Entry(initialOrder).State = EntityState.Modified; initialOrder.order_status = order.order_status; initialOrder.total = order.total; initialOrder.waiter_id = order.waiter_id; initialOrder.table_id = order.table_id; initialOrder.version++; initialOrder.written_by = order.written_by; foreach (order_item oi in order.order_item) { if (oi.id <= 0) { db.order_item.Add(oi); } } List<order_item> toRemove = new List<order_item>(); for (int i = 0; i < initialOrder.order_item.Count; i++) { bool found = false; for (int k = 0; k < order.order_item.Count; k++) { if (order.order_item.ElementAt(k).id == initialOrder.order_item.ElementAt(i).id) { found = true; break; } } if (!found) { toRemove.Add(initialOrder.order_item.ElementAt(i)); } } for (int i = 0; i < toRemove.Count; i++) { db.order_item.Remove(toRemove[i]); } db.SaveChanges(); }
public static void MyClassInitialize(TestContext testContext) { //Add test data (order specific) testDatabase = new TestDatabaseHelper(); restaurant1 = testDatabase.AddRestaurant(); table1 = testDatabase.AddTable(restaurant1); user1 = testDatabase.AddUser("*****@*****.**", table1, (int)SiteRoles.Admin); order1 = testDatabase.AddOrder(table1); item1 = testDatabase.AddItem(); category1 = testDatabase.AddCategory(); menu1 = testDatabase.AddMenu(restaurant1); menuCategory1 = testDatabase.AddMenuCategory(category1, menu1); menuItem1 = testDatabase.AddMenuItem(item1, menuCategory1); //Session db = new touch_for_foodEntities(); BillController target = new BillController(); Session session = new Session(db, target); session.simulateLogin(user1.username, user1.password); }
public static void UpdatePrice(ref order theOrder) { theOrder.total = 0; decimal tempPrice = 0; foreach (order_item oi in theOrder.order_item) { if (oi.order_item_status == (int)OrderStatusHelper.OrderItemStatusEnum.REJECTED) continue; menu_item tempMenuItem = db.menu_item.Find(oi.menu_item_id); tempPrice = tempMenuItem.price; theOrder.total += tempPrice; } }
public void MyTestInitialize() { //Add test data (order specific) restaurant1 = testDatabase.AddRestaurant(); table1 = testDatabase.AddTable(restaurant1); user1 = testDatabase.AddUser("*****@*****.**", table1, (int)SiteRoles.Admin); user3 = testDatabase.AddUser("*****@*****.**", table1, (int)SiteRoles.Customer); friendship1 = testDatabase.AddFriendship(user1, user3); restaurantUser1 = testDatabase.AddRestaurantUser(user1, restaurant1); order1 = testDatabase.AddOrder(table1); // Create a valid user object with test values user2 = new user(); user2.username = "******"; user2.password = "******"; user2.ConfirmPassword = "******"; user2.first_name = "*****@*****.**"; user2.last_name = "*****@*****.**"; user2.email = "*****@*****.**"; user2.image_url = null; user2.current_table_id = table1.id; }
public void MyTestInitialize() { //Add test data (order specific) restaurant1 = testDatabase.AddRestaurant(); table1 = testDatabase.AddTable(restaurant1); table2 = new table(); user1 = testDatabase.AddUser("*****@*****.**", table1, (int)SiteRoles.Restaurant); order1 = testDatabase.AddOrder(table1); request1 = testDatabase.AddServiceRequest(table1); restaurantUser1 = testDatabase.AddRestaurantUser(user1, restaurant1); //Session db = new touch_for_foodEntities(); target = new TableController(); Session session = new Session(db, target); session.simulateLogin(user1.username, user1.password); }
public void MyTestInitialize() { //Add test data (order specific) category1 = testDatabase.AddCategory(); restaurant1 = testDatabase.AddRestaurant(); menu1 = testDatabase.AddMenu(restaurant1); menuCategory1 = testDatabase.AddMenuCategory(category1, menu1); table1 = testDatabase.AddTable(restaurant1); order1 = testDatabase.AddOrder(table1); item1 = testDatabase.AddItem(category1); menuItem1 = testDatabase.AddMenuItem(item1, menuCategory1); orderItem1 = testDatabase.AddOrderItem(order1, menuItem1); }
/// <summary> /// Creates an entry of type order in the database. /// </summary> /// <param name="orderTable">The table where orders are made from.</param> /// <param name="orderWaiter">The waiter in charge of order.</param> /// <returns>The created order entry.</returns> public order AddOrder(table orderTable, waiter orderWaiter) { //Initialise db = new touch_for_foodEntities(); order testOrder = new order(); //Set Attributes testOrder.timestamp = DateTime.Now; testOrder.table_id = orderTable.id; testOrder.waiter_id = orderWaiter.id; testOrder.version = 1; //Save db.orders.Add(testOrder); db.SaveChanges(); db.Dispose(); return testOrder; }
/// <summary> /// Adds a bill entry to the database /// </summary> /// <param name="orderEntity">The associated order</param> /// <returns>The created bill entity.</returns> internal bill AddBill(order orderEntity) { //Initialise db = new touch_for_foodEntities(); bill testBill = new bill(); //Set attributes testBill.order_id = orderEntity.id; testBill.is_deleted = false; //Save db.bills.Add(testBill); db.SaveChanges(); db.Dispose(); return testBill; }
public void MyTestInitialize() { //Add test data (order specific) order1 = testDatabase.AddOrder(table1); //Session db = new touch_for_foodEntities(); target = new OrderController(); Session session = new Session(db, target); session.simulateLogin(user1.username, user1.password); }
public static waiter filterWaiter(order order) { waiter w = (waiter)db.waiters.Find(order.waiter_id); return w; }
public static table filterTable(order order) { table t = (table)db.tables.Find(order.table_id); return t; }
/// <summary> /// Creates an entry of type order item in the database. /// </summary> /// <param name="orderEntity">Order that order items belongs to.</param> /// <param name="billEntity">Bill that order item belongs to.</param> /// <returns>The created order item entity.</returns> public order_item AddOrderItem(order orderEntity, bill billEntity, menu_item menuItem) { //Initialise db = new touch_for_foodEntities(); order_item testOrderItem = new order_item(); //Set Attributes testOrderItem.order_id = orderEntity.id; testOrderItem.bill_id = billEntity.id; testOrderItem.menu_item_id = menuItem.id; testOrderItem.version = 1; //Save db.order_item.Add(testOrderItem); db.SaveChanges(); db.Dispose(); return testOrderItem; }
/// <summary> /// Creates an entry of type review in the database. public review AddReview(restaurant r, order o, user u) { //Initialise db = new touch_for_foodEntities(); review testReview = new review(); //Set attributes testReview.is_anonymous = false; testReview.order_id = o.id; testReview.restaurant_id = r.id; testReview.user_id = u.id; testReview.rating = 0; //Save db.reviews.Add(testReview); db.SaveChanges(); db.Dispose(); return testReview; }
public ActionResult Edit(order order) { if (ModelState.IsValid) { try { if (om.edit(order)) return RedirectToAction("Index"); else { ViewBag.Error = Global.OrderLockError; } } catch (Exception) { ViewBag.Error = Global.ServerError; } } else { ViewBag.Error = Global.ServerError; } ViewBag.user_id = new SelectList(db.users, "id", "username", order.user_id); ViewBag.waiter_id = new SelectList(db.waiters, "id", "first_name", order.waiter_id); return View(order); }
public ActionResult Create(order order) { if (ModelState.IsValid) { try { if (om.Create(order, true)) { return RedirectToAction("Index"); } } catch (Exception) { } } ViewBag.Error = Global.ServerError; var statuses = from TouchForFood.Models.OrderStatusHelper.OrderStatusEnum s in Enum.GetValues(typeof(TouchForFood.Models.OrderStatusHelper.OrderStatusEnum)) select new { Value = (int)s, Name = s.ToString() }; ViewData["order_status"] = new SelectList(statuses, "Value", "Name", OrderStatusHelper.OrderStatusEnum.OPEN); ViewBag.user_id = new SelectList(db.users, "id", "username", order.user_id); ViewBag.waiter_id = new SelectList(db.waiters, "id", "first_name", order.waiter_id); return View(order); }
public static user filterUser(order order) { user u = (user)db.users.Find(order.user_id); return u; }
public void MyTestInitialize() { //Add test data (order specific) restaurant1 = testDatabase.AddRestaurant(); restaurant2 = new restaurant(); table1 = testDatabase.AddTable(restaurant1); user1 = testDatabase.AddUser("*****@*****.**", table1, (int)SiteRoles.Admin); restaurantUser1 = testDatabase.AddRestaurantUser(user1, restaurant1); menu1 = testDatabase.AddMenu(restaurant1); order1 = testDatabase.AddOrder(table1); review1 = testDatabase.AddReview(restaurant1, order1, user1); //Session db = new touch_for_foodEntities(); target = new RestaurantController(); Session session = new Session(db, target); session.simulateLogin(user1.username, user1.password); }
public void MyTestInitialize() { //Add test data (order specific) restaurant1 = testDatabase.AddRestaurant(); table1 = testDatabase.AddTable(restaurant1); order1 = testDatabase.AddOrder(table1); serviceRequest1 = testDatabase.AddServiceRequest(table1); }
public Boolean edit(order order) { OrderIM im = new OrderIM(db); order dbVersion = im.find(order.id); if (dbVersion.version == order.version) { ((IObjectContextAdapter)db).ObjectContext.Detach(dbVersion); db.Entry(order).State = EntityState.Modified; order.version = order.version + 1; db.SaveChanges(); return true; } return false; }
public static void MyClassInitialize(TestContext testContext) { testDatabase = new TestDatabaseHelper(); //Add test data (order specific) item1 = testDatabase.AddItem(); category1 = testDatabase.AddCategory(); restaurant1 = testDatabase.AddRestaurant(); menu1 = testDatabase.AddMenu(restaurant1); menuCategory1 = testDatabase.AddMenuCategory(category1, menu1); table1 = testDatabase.AddTable(restaurant1); order1 = testDatabase.AddOrder(table1); user1 = testDatabase.AddUser("*****@*****.**", table1, (int)SiteRoles.Admin); review1 = testDatabase.AddReview(restaurant1, order1, user1); }
/// <summary> /// Removes an order from the database. /// </summary> /// <param name="orderEntity">Order to be removed.</param> public void RemoveOrder(order orderEntity) { db = new touch_for_foodEntities(); if (orderEntity != null) { db.orders.Remove(db.orders.Find(orderEntity.id)); db.SaveChanges(); } db.Dispose(); }