/** * Filters the sides and only returns those that are not already assigned to the menu * that is passed in. * */ public static IList<side> FilterListBySide(menu_category menu_category) { touch_for_foodEntities db = new touch_for_foodEntities(); List<side> filteredList = new List<side>(); int resto_id = menu_category.menu.resto_id; // We want all sides that do not exist in this menu_category and that belong to this restaurant. // is_deleted and is_active need to be considered too. Show only sides where is_active is false // if side is_deleted is true, then there should be another page to revert that. the side functionality // I'm putting should only set a side to is_active is true or false List<side> restaurantSides = db.sides.Where ( si => si.menu_category.menu.resto_id == resto_id && si.is_active == false && si.is_deleted == false ).ToList(); foreach (var side in restaurantSides) { if (side.menu_category_id.Equals(menu_category.id)) { filteredList.Add(side); } } db.Dispose(); return filteredList; }
public static void MyClassCleanup() { touch_for_foodEntities db = new touch_for_foodEntities(); review r = db.reviews.Find(m_review.id); db.reviews.Remove(r); db.SaveChanges(); db.Dispose(); }
public static void MyClassInitialize(TestContext testContext) { touch_for_foodEntities db = new touch_for_foodEntities(); m_review = new review(); m_review.restaurant_id = db.restaurants.First().id; m_review.rating = 1; m_review.is_anonymous = true; db.reviews.Add(m_review); db.SaveChanges(); db.Dispose(); }
/// <summary> /// Creates a friendship entity /// </summary> /// <param name="user1">The first user in the friendship</param> /// <param name="user2">The second user in the friendship</param> /// <returns>the created friendship entity</returns> public friendship AddFriendship(user user1, user user2) { //Initialise db = new touch_for_foodEntities(); friendship testFriendship = new friendship(); //Set Attributes testFriendship.first_user = user1.id; testFriendship.second_user = user2.id; //Save db.friendships.Add(testFriendship); db.SaveChanges(); db.Dispose(); return testFriendship; }
/// <summary> /// Adds a category entry to the database /// </summary> /// <returns>The created category entity.</returns> public category AddCategory() { //Initialise db = new touch_for_foodEntities(); category testCategory = new category(); //Set attributes testCategory.name = "UnitTest"; testCategory.version = 0; //Save db.categories.Add(testCategory); db.SaveChanges(); db.Dispose(); return testCategory; }
/** * Filters the categories and only returns those that are not already assigned to the menu * that is passed in. * */ public static IList<item> filterListByItem(menu_category menu_category,touch_for_foodEntities db) { List<item> filteredList = new List<item>(); MenuItemIM im = new MenuItemIM(db); int resto_id = menu_category.menu.resto_id; bool reject = false; foreach (item i in db.items.ToList()) { reject = false; //First check that the category does belong to the restaurant //Find all usages of the category in question in the current restaurant List<menu_item> usages = db.menu_item.Where(mi => mi.item_id == i.id && mi.menu_category.menu.resto_id == resto_id).ToList(); //If it was never used by this restaurant, then the restaurant could not have created it // because create automatically adds the created item to the menu if (usages.Count == 0) { reject = true; } if (menu_category.category.id == i.category_id) { foreach (menu_item m_i in im.find(false, menu_category.id)) { if (i.id == m_i.item_id) { reject = true; break; } } if (!reject) { filteredList.Add(i); } } } db.Dispose(); return filteredList; }
/// <summary> /// Removes a side item from the database. /// </summary> /// <param name="testSide">The side to be removed.</param> public void RemoveSide(side testSide) { db = new touch_for_foodEntities(); if (db.sides.Find(testSide.id) != null) { db.sides.Remove(db.sides.Find(testSide.id)); db.SaveChanges(); } db.Dispose(); }
public void RemoveReviewOrderItem(review_order_item reviewEntityOI) { db = new touch_for_foodEntities(); if (db.review_order_item.Find(reviewEntityOI.id) != null) { db.review_order_item.Remove(db.review_order_item.Find(reviewEntityOI.id)); db.SaveChanges(); } db.Dispose(); }
/// <summary> /// Removes a service request item from the database. /// </summary> /// <param name="serviceRequest">The service request to be removed.</param> public void RemoveServiceRequest(service_request serviceRequest) { db = new touch_for_foodEntities(); if (db.service_request.Find(serviceRequest.id) != null) { db.service_request.Remove(db.service_request.Find(serviceRequest.id)); db.SaveChanges(); } db.Dispose(); }
/// <summary> /// Creates an entry of type service request in the database. /// </summary> /// <param name="tableEntity">the table the service request is associated to.</param> /// <returns>The created service request entity.</returns> public service_request AddServiceRequest(table tableEntity) { //Initialise db = new touch_for_foodEntities(); service_request testServiceRequest = new service_request(); //Set Attributes testServiceRequest = new service_request(); testServiceRequest.note = "UnitTest"; testServiceRequest.created = DateTime.Now; testServiceRequest.status = (int)ServiceRequestUtil.ServiceRequestStatus.OPEN; testServiceRequest.version = 0; testServiceRequest.table_id = tableEntity.id; //Save db.service_request.Add(testServiceRequest); db.SaveChanges(); db.Dispose(); return testServiceRequest; }
///<summary> /// Removes a bill from the database. /// </summary> /// <param name="billEntity">Bill to be removed.</param> public void RemoveBill(bill billEntity) { db = new touch_for_foodEntities(); if (db.bills.Find(billEntity.id) != null) { db.bills.Remove(db.bills.Find(billEntity.id)); db.SaveChanges(); } db.Dispose(); }
/// <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; }
/// <summary> /// Creates an entry of type table in the database. /// </summary> /// <param name="restaurantEntity">The restaurant where the table is located.</param> /// <returns>The created table entity.</returns> public table AddTable(restaurant restaurantEntity) { //Initialise db = new touch_for_foodEntities(); table testTable = new table(); //Set Attributes testTable.name = "Unit Test"; testTable.restaurant_id = restaurantEntity.id; //Save db.tables.Add(testTable); db.SaveChanges(); db.Dispose(); return testTable; }
/// <summary> /// Remove menu item from database. /// </summary> /// <param name="menuCategoryEntity">Menu Category item to be removed.</param> public void RemoveMenuCategory(menu_category menuCategoryEntity) { db = new touch_for_foodEntities(); if (db.menu_category.Find(menuCategoryEntity.id) != null) { db.menu_category.Remove(db.menu_category.Find(menuCategoryEntity.id)); db.SaveChanges(); } db.Dispose(); }
/// <summary> /// Remove menu item item from database. /// </summary> /// <param name="menuEntity">Menu item item to be removed.</param> public void RemoveMenuItem(menu_item menuItemEntity) { db = new touch_for_foodEntities(); if (db.menu_item.Find(menuItemEntity.id) != null) { db.menu_item.Remove(db.menu_item.Find(menuItemEntity.id)); db.SaveChanges(); } db.Dispose(); }
/// <summary> /// Remove item item from database. /// </summary> /// <param name="menuEntity">Item item to be removed.</param> public void RemoveItem(item itemEntity) { db = new touch_for_foodEntities(); if (db.items.Find(itemEntity.id) != null) { db.items.Remove(db.items.Find(itemEntity.id)); db.SaveChanges(); } db.Dispose(); }
/// <summary> /// Remove menu item from database. /// </summary> /// <param name="menuEntity">Menu item to be removed.</param> public void RemoveMenu(menu menuEntity) { db = new touch_for_foodEntities(); if (menuEntity != null) { db.menus.Remove(db.menus.Find(menuEntity.id)); db.SaveChanges(); } db.Dispose(); }
/// <summary> /// Remove friendship item from database. /// </summary> /// <param name="menuEntity">Friendships item to be removed.</param> public void RemoveFriendship(friendship friendshipEntity) { db = new touch_for_foodEntities(); if (db.friendships.Find(friendshipEntity.id) != null) { db.friendships.Remove(db.friendships.Find(friendshipEntity.id)); db.SaveChanges(); } db.Dispose(); }
///<summary> /// Removes a bill from the database. /// </summary> /// <param name="billEntity">Bill to be removed.</param> public void RemoveCategory(category categoryEntity) { db = new touch_for_foodEntities(); if (db.categories.Find(categoryEntity.id) != null) { db.categories.Remove(db.categories.Find(categoryEntity.id)); db.SaveChanges(); } db.Dispose(); }
/// <summary> /// Creates an entry of type user in the database. /// </summary> /// <param name="username">A unique string to represent the user.</param> /// <param name="currentTable">A table in the restaurant.</param> /// <param name="userRole">The role of the user (ex: Administrator, Client)</param> /// <returns>The created user entity.</returns> public user AddUser(string email, table currentTable, int userRole) { //Initialise db = new touch_for_foodEntities(); user testUser = new user(); //Set attributes testUser.username = email; // Make sure the password is encrypted AES aes = new AES(); testUser.password = aes.EncryptToString(email); testUser.ConfirmPassword = aes.EncryptToString(email); testUser.first_name = email; testUser.last_name = email; testUser.email = email; testUser.image_url = email; testUser.current_table_id = currentTable.id; testUser.version = 1; testUser.user_role = userRole; //Save db.users.Add(testUser); db.SaveChanges(); db.Dispose(); return testUser; }
/// <summary> /// Removes a table item from the database. /// </summary> /// <param name="tableEntity">The table to be removed.</param> public void RemoveTable(table tableEntity) { db = new touch_for_foodEntities(); if (db.tables.Find(tableEntity.id) != null) { db.tables.Remove(db.tables.Find(tableEntity.id)); db.SaveChanges(); } db.Dispose(); }
public review_order_item AddReviewOrderItem(review r, order_item oi, string text, int rating) { //Initialise db = new touch_for_foodEntities(); review_order_item testReviewOI = new review_order_item(); //Set attributes testReviewOI.rating = rating; testReviewOI.order_item_id = oi.id; testReviewOI.review_id = r.id; testReviewOI.submitted_on = System.DateTime.Now; testReviewOI.rating = 0; //Save db.review_order_item.Add(testReviewOI); db.SaveChanges(); db.Dispose(); return testReviewOI; }
/// <summary> /// Removes a waiter item from the database. /// </summary> /// <param name="waiterEntity">The waiter to be removed</param> public void RemoveWaiter(waiter waiterEntity) { db = new touch_for_foodEntities(); if (db.waiters.Find(waiterEntity.id) != null) { db.waiters.Remove(db.waiters.Find(waiterEntity.id)); db.SaveChanges(); } db.Dispose(); }
/// <summary> /// Removes an order item from the database. /// </summary> /// <param name="orderEntity">Order item to be removed.</param> public void RemoveOrderItem(order_item orderItem) { db = new touch_for_foodEntities(); if(db.order_item.Find(orderItem.id) != null) { db.order_item.Remove(db.order_item.Find(orderItem.id)); db.SaveChanges(); } db.Dispose(); }
/// <summary> /// Creates an entry of type item in the database. /// </summary> /// <param name="catagoryEntity">Category that item is related to.</param> /// <returns>The created item entry.</returns> public item AddItem(category catagoryEntity) { //Initialise db = new touch_for_foodEntities(); item testItem = new item(); //Set Attributes testItem.name = "UnitTest"; testItem.category_id = catagoryEntity.id; //Save db.items.Add(testItem); db.SaveChanges(); db.Dispose(); return testItem; }
/// <summary> /// Removes a restaurant_user item from the database. /// </summary> /// <param name="restaurantEntity">restaurant_user item to be removed.</param> public void RemoveRestaurantUser(restaurant_user restaurantUserEntity) { db = new touch_for_foodEntities(); if (db.restaurant_user.Find(restaurantUserEntity.id) != null) { db.restaurant_user.Remove(db.restaurant_user.Find(restaurantUserEntity.id)); db.SaveChanges(); } db.Dispose(); }
/// <summary> /// Creates an entry of type side in the database. /// </summary> /// <param name="menuCategory">The menu category associated to the side</param> /// <returns>The created side entity.</returns> public side AddSide(menu_category menuCategory) { //Initialise db = new touch_for_foodEntities(); side testSide = new side(); //Set Attributes testSide.name = "UnitTest"; testSide.price = new decimal(2.99); testSide.version = 1; testSide.menu_category_id = menuCategory.id; testSide.is_active = false; testSide.is_deleted = false; //Save db.sides.Add(testSide); db.SaveChanges(); db.Dispose(); return testSide; }
/// <summary> /// Removes a review item from the database. /// </summary> /// <param name="userEntity">The review to be removed.</param> public void RemoveReview(review reviewEntity) { db = new touch_for_foodEntities(); if (db.reviews.Find(reviewEntity.id) != null) { db.reviews.Remove(db.reviews.Find(reviewEntity.id)); db.SaveChanges(); } db.Dispose(); }
/// <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(); }
/// <summary> /// Creates a waiter entity /// </summary> /// <param name="restaurantEntity">Associated restaurant</param> /// <returns>Created restaurant entity</returns> public waiter AddWaiter(restaurant restaurantEntity) { //Initialise db = new touch_for_foodEntities(); waiter testWaiter = new waiter(); //Set attributes testWaiter.first_name = "UnitTest"; testWaiter.last_name = "UnitTest"; testWaiter.version = 1; testWaiter.resto_id = restaurantEntity.id; //Save db.waiters.Add(testWaiter); db.SaveChanges(); db.Dispose(); return testWaiter; }