Exemplo n.º 1
0
        public ActionResult Create(restaurant_user restaurant_user)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (restaurant_user.restaurant_id != null && restaurant_user.user_id != null)
                    {
                        db.restaurant_user.Add(restaurant_user);
                        db.SaveChanges();
                        return RedirectToAction("Index");
                    }
                    ViewBag.Error = Global.RestaurantUserNotSpecifiedError;
                }
                catch (Exception)
                {
                    ViewBag.Error = Global.ServerError;
                }
            }

            ViewBag.restaurant_id = new SelectList(db.restaurants, "id", "name", restaurant_user.restaurant_id);
            ViewBag.user_id = new SelectList(db.users.Where(u => u.user_role == (int)SiteRoles.Restaurant
                || u.user_role == (int)SiteRoles.Admin), "id", "username");
            return View(restaurant_user);
        }
Exemplo n.º 2
0
        /// <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;
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 /// <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();
 }
Exemplo n.º 7
0
        /// <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;
        }
Exemplo n.º 8
0
        public void MyTestInitialize()
        {
            //Add test data (order specific)
            restoUser1 = testDatabase.AddRestaurantUser(user1, restaurant1);

            restoUser2 = new restaurant_user();
            restoUser2.restaurant_id = restaurant1.id;
            restoUser2.user_id = user1.id;
        }