コード例 #1
0
ファイル: ReportsIM.cs プロジェクト: pmoda/TFFCode
        public IEnumerable<WaiterStatsViewModel> findWaiterStats(restaurant r, System.DateTime start, System.DateTime end)
        {
            String s = start.ToString("yyyy-MM-dd HH:mm:ss.fff");
            String e = end.ToString("yyyy-MM-dd HH:mm:ss.fff");

            var sql = " select r.id as restoId, r.name as restoName, w.id as waiterId, w.first_name as waiterFirstName, w.last_name as waiterLastName, COUNT(o.id) as completedOrders"
            + " from dbo.[order] o"
            + " Join dbo.waiter w on o.waiter_id = w.id"
            + " Join dbo.restaurant r on w.resto_id = r.id"
            + " WHERE o.order_status = " + (int)OrderStatusHelper.OrderItemStatusEnum.DELIVERED
            + " and r.id = " + r.id
            + " and o.timestamp >= '" + s + "'"
            + " and o.timestamp <= '" + e + "'"
            + " Group By w.first_name, w.last_name, r.id, r.name, w.id"
            + " order by completedOrders desc";

            System.Diagnostics.Debug.WriteLine(sql);
            IEnumerable<WaiterStatsViewModel> waiters = db.Database.SqlQuery<WaiterStatsViewModel>(sql);

            foreach(WaiterStatsViewModel waiter in waiters){
                System.Diagnostics.Debug.WriteLine(waiter.waiterFirstName + " made "+waiter.completedOrders);
            }

            return waiters;
        }
コード例 #2
0
ファイル: RestaurantController.cs プロジェクト: pmoda/TFFCode
        public ActionResult Create(restaurant restaurant)
        {
            if (ModelState.IsValid)
            {
                // Try to add the restaurant to the database and save the changes
                // Exception will be thrown in case of errors. Since there is only one exception thrown
                // by the RestaurantOM (of type InvalidOperationException), the same error is thrown for both situations.
                try
                {
                    if (om.Create(restaurant, Util.User.UserUtil.getAuthenticatedUser(Request)))
                    {
                        return RedirectToAction("Index");
                    }
                }
                catch (InvalidOperationException e)
                {
                    ViewBag.Error = Global.ServerError;
                    return View(restaurant);
                }
                catch (Exception)
                {
                    ViewBag.Error = Global.ServerError;
                    return View(restaurant);
                }

            }
            ViewBag.Error = Global.ServerError;
            return View(restaurant);
        }
コード例 #3
0
ファイル: UserUtil.cs プロジェクト: pmoda/TFFCode
        /// <summary>
        /// Gets suggested Dishes based on User History
        /// First builds a dictionary for metascores, then find all potential dishes
        /// It then computes a score for each of the dishes based on the metascore values
        /// Finally sorts and returns the best 10 dishes
        /// </summary>
        /// <param name="u"></param>
        /// <param name="r"></param>
        public static List<KeyValuePair<menu_item, int>> GetSuggestions(user u, restaurant r)
        {
            totalOrdersCount = 0;
            totalOrderItemsCount = 0;
            totalReviewsCount = 0;
            metaDataCount = 0;
            List<menu> menus = db.menus.Where(m => m.is_active == true && m.is_deleted == false && m.resto_id == r.id).ToList();
            List<menu_category> menu_categories = new List<menu_category>();
            List<menu_item> menu_items_available = new List<menu_item>();
            Dictionary<menu_item, int> ItemScores;
            Dictionary<string, int[]> MetaScores;
            //Build the Metascores using all past orders and reviews
            MetaScores = BuildMetaScores(u);

            //Find all available items we can order
            foreach (menu m in menus)
            {
                menu_categories.AddRange(m.menu_category.Where(mc => mc.is_active == true && mc.is_deleted == false));
            }
            foreach (menu_category mc in menu_categories)
            {
                menu_items_available.AddRange(mc.menu_item.Where(mi => mi.is_active == true && mi.is_deleted == false));
            }

            //Give a score to every potential menu item currently available
            ItemScores = CalculateItemScores(MetaScores, menu_items_available);

            return SortByScore(ItemScores);
        }
コード例 #4
0
 public static void MyClassInitialize(TestContext testContext)
 {
     //Add test data (order specific)
     testDatabase = new TestDatabaseHelper();
     restaurant1 = testDatabase.AddRestaurant();
     table1 = testDatabase.AddTable(restaurant1);
 }
コード例 #5
0
        public static void MyClassInitialize(TestContext testContext)
        {
            testDatabase = new TestDatabaseHelper();

            //Add test data (order specific)
            restaurant1 = testDatabase.AddRestaurant();
            menu1 = testDatabase.AddMenu(restaurant1);
        }
コード例 #6
0
ファイル: MenuControllerTest.cs プロジェクト: pmoda/TFFCode
 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);
 }
コード例 #7
0
 public static void MyClassInitialize(TestContext testContext)
 {
     //Add test data (order specific)
     testDatabase = new TestDatabaseHelper();
     restaurant1 = testDatabase.AddRestaurant();
     menu1 = testDatabase.AddMenu(restaurant1);
     category1 = testDatabase.AddCategory();
     item1 = testDatabase.AddItem();
 }
コード例 #8
0
ファイル: HomeControllerTest.cs プロジェクト: pmoda/TFFCode
        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);

            //Session
            db = new touch_for_foodEntities();
            target = new HomeController();
            Session session = new Session(db, target);
            session.simulateLogin(user1.username, user1.password);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
ファイル: ReportsIM.cs プロジェクト: pmoda/TFFCode
        public IEnumerable<MostPopularDishViewModel> findMostPopular(restaurant r)
        {
            var sql = "select r.name as restoName, i.name as menuItemName, COUNT(oi.id) AS timesOrdered, mi.id as menuItemId"
              + " from dbo.order_item oi"
              + " JOIN dbo.menu_item mi on oi.menu_item_id = mi.id"
              + " JOIN dbo.item i on mi.item_id = i.id"
              + " JOIN dbo.menu_category mc on mi.menu_category_id = mc.id"
              + " JOIN dbo.menu m on mc.menu_id = m.id"
              + " JOIN dbo.restaurant r on m.resto_id = r.id"
              + " WHERE r.id = " + r.id
              + " Group by i.name, r.name, mi.id"
              + " Order by timesOrdered desc";

            IEnumerable<MostPopularDishViewModel> dishes = db.Database.SqlQuery<MostPopularDishViewModel>(sql);
            return dishes;
        }
コード例 #11
0
ファイル: ReviewOM.cs プロジェクト: pmoda/TFFCode
        /// <summary>
        /// Calculates the restaurant's rating
        /// </summary>
        /// <param name="restaurant">Restaurant who's rating we need to caluclate</param>
        /// <returns>rating - a decimal representing the restaurant rating</returns>
        private decimal calculateRating(restaurant restaurant)
        {
            if (restaurant.reviews.Count > 0)
            {
                decimal allRatings = 0.0m;

                foreach (review r in restaurant.reviews)
                {
                    allRatings += r.rating;
                }
                return allRatings / restaurant.reviews.Count;
            }
            else
            {
                return 0;
            }
        }
コード例 #12
0
ファイル: BillControllerTest.cs プロジェクト: pmoda/TFFCode
        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);
        }
コード例 #13
0
ファイル: RestaurantOM.cs プロジェクト: pmoda/TFFCode
        /// <summary>
        /// Writes a restaurant obejct to the database
        /// </summary>
        /// <param name="restaurant">The restaurant object to write</param>
        /// <param name="user">The user to associate as owner to the restaurant</param>
        /// <returns>True if successful, false otherwise</returns>
        /// <exception cref="InvalidOperationException"></exception>
        public bool Create(restaurant restaurant, user user)
        {
            if (user == null) return false;
            db.restaurants.Add(restaurant);
            if (db.SaveChanges() == 0) return false;

            // assign the user to this restaurant.
            restaurant_user ru = new restaurant_user();
            ru.user_id = user.id;
            ru.restaurant_id = restaurant.id;
            db.restaurant_user.Add(ru);

            if (db.SaveChanges() == 0)
            {
                // Remove the restaurant because the owner could not be assigned to it.
                delete(restaurant.id);
                return false;
            }
            return true;
        }
コード例 #14
0
ファイル: OrderOMTest.cs プロジェクト: pmoda/TFFCode
 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);
 }
コード例 #15
0
ファイル: RestaurantOM.cs プロジェクト: pmoda/TFFCode
 /// <summary>
 /// when updating a record we would like to increment the value of version to
 /// </summary>
 /// <param name="restaurant"></param>
 /// <returns></returns>
 /// <exception cref="InvalidOperationException"></exception>
 public Boolean edit(restaurant restaurant)
 {
     RestaurantIM im = new RestaurantIM(db);
     restaurant dbVersion = im.find(restaurant.id);
     if (dbVersion.version == restaurant.version)
     {
         ((IObjectContextAdapter)db).ObjectContext.Detach(dbVersion);
         db.Entry(restaurant).State = EntityState.Modified;
         restaurant.version = restaurant.version + 1;
         db.SaveChanges();
         return true;
     }
     return false;
 }
コード例 #16
0
ファイル: TestDatabaseHelper.cs プロジェクト: pmoda/TFFCode
        /// <summary>
        /// Creates an entry of type menu in the database.
        /// </summary>
        /// <param name="restaurantEntity">The restaurant the menu belongs to</param>
        /// <returns>The created menu entry.</returns>
        public menu AddMenu(restaurant restaurantEntity)
        {
            //Initialise
            db = new touch_for_foodEntities();
            menu testMenu = new menu();

            //Set Attributes
            testMenu.resto_id = restaurantEntity.id;
            testMenu.name = "UnitTest";
            testMenu.is_active = false;
            testMenu.is_deleted = false;

            //Save
            db.menus.Add(testMenu);
            db.SaveChanges();
            db.Dispose();

            return testMenu;
        }
コード例 #17
0
ファイル: TestDatabaseHelper.cs プロジェクト: pmoda/TFFCode
        /// <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;
        }
コード例 #18
0
ファイル: TestDatabaseHelper.cs プロジェクト: pmoda/TFFCode
        /// <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;
        }
コード例 #19
0
        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);
        }
コード例 #20
0
ファイル: TableOMTest.cs プロジェクト: pmoda/TFFCode
 public void MyTestInitialize()
 {
     //Add test data (order specific)
     restaurant1 = testDatabase.AddRestaurant();
     table1 = testDatabase.AddTable(restaurant1);
     order1 = testDatabase.AddOrder(table1);
     serviceRequest1 = testDatabase.AddServiceRequest(table1);
 }
コード例 #21
0
ファイル: TestDatabaseHelper.cs プロジェクト: pmoda/TFFCode
        /// <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;
        }
コード例 #22
0
ファイル: UserControllerTest.cs プロジェクト: pmoda/TFFCode
        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;
        }
コード例 #23
0
ファイル: TestDatabaseHelper.cs プロジェクト: pmoda/TFFCode
 /// <summary>
 /// Removes a restaurant item from the database.
 /// </summary>
 /// <param name="restaurantEntity">Restaurant item to be removed.</param>
 public void RemoveRestaurant(restaurant restaurantEntity)
 {
     db = new touch_for_foodEntities();
     if (db.restaurants.Find(restaurantEntity.id) != null)
     {
         db.restaurants.Remove(db.restaurants.Find(restaurantEntity.id));
         db.SaveChanges();
     }
     db.Dispose();
 }
コード例 #24
0
ファイル: TestDatabaseHelper.cs プロジェクト: pmoda/TFFCode
        /// <summary>
        /// Creates an entry of type restaurant in the database.
        /// </summary>
        /// <returns>The created restaurant entity.</returns>
        public restaurant AddRestaurant()
        {
            //Initialise
            db = new touch_for_foodEntities();
            restaurant testRestaurant = new restaurant();

            //Set Attributes
            testRestaurant.name = "UnitTest";
            testRestaurant.address = "UnitTest";
            testRestaurant.city = "UnitTest";
            testRestaurant.version = 1;
            testRestaurant.is_deleted = false;

            //Save
            db.restaurants.Add(testRestaurant);
            db.SaveChanges();
            db.Dispose();

            return testRestaurant;
        }
コード例 #25
0
ファイル: TableControllerTest.cs プロジェクト: pmoda/TFFCode
        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);
        }
コード例 #26
0
ファイル: RestaurantController.cs プロジェクト: pmoda/TFFCode
        public ActionResult Edit(restaurant restaurant)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (om.edit(restaurant))
                    {

                        return RedirectToAction("Index");
                    }
                    else
                    {
                        ViewBag.Error = Global.VersioningError;
                        //TODO: delete this message once viewbag implemented on client side
                        //ModelState.AddModelError("name", Global.VersioningError);
                    }
                }
                catch(Exception e)
                {
                    ViewBag.Error = e.Message;
                }

            }
            return View(restaurant);
        }
コード例 #27
0
ファイル: TestDatabaseHelper.cs プロジェクト: pmoda/TFFCode
        /// <summary>
        /// Creates an entry of type restaurant_user in the database.
        /// </summary>
        /// <param name="testUser">User user_restaurant is associated to.</param>
        /// <param name="testRestaurant">Restaurant user_restaurant is associated to.</param>
        /// <returns>The created restaurant_user entity.</returns>
        public restaurant_user AddRestaurantUser(user testUser, restaurant testRestaurant)
        {
            //Initialise
            db = new touch_for_foodEntities();
            restaurant_user testRestaurantUser = new restaurant_user();

            //Set Attributes
            testRestaurantUser.user_id= testUser.id;
            testRestaurantUser.restaurant_id = testRestaurant.id;

            //Save
            db.restaurant_user.Add(testRestaurantUser);
            db.SaveChanges();
            db.Dispose();

            return testRestaurantUser;
        }
コード例 #28
0
        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);
        }
コード例 #29
0
ファイル: WaiterOMTest.cs プロジェクト: pmoda/TFFCode
 public void MyTestInitialize()
 {
     //Add test data (order specific)
     restaurant1 = testDatabase.AddRestaurant();
     table1 = testDatabase.AddTable(restaurant1);
     waiter1 = testDatabase.AddWaiter(restaurant1);
     order1 = testDatabase.AddOrder(table1, waiter1);
 }