/// <summary>
        /// Adds the specified restaurant to the specified user's Favorites
        /// Throws an exception if specified user or restraunt is not found in DB
        /// Also throws exception if Favorite list already exists for that user
        /// Must still call Save() after to persist changes to DB
        /// </summary>
        /// <param name="username">string containing user's username</param>
        /// <param name="restaurantId">string containing restaurant's Id</param>
        /// <param name="rRepo">RestaurantRepo object, required for validation to ensure the given restraunt exists in our DB</param>
        public void AddRestaurantToFavorites(string username, string restaurantId, RestaurantRepo rRepo)
        {
            if (!DBContainsUsername(username))
            {
                throw new DbUpdateException($"Username '{username}' not found.", new NotSupportedException());
            }
            if (!rRepo.DBContainsRestaurant(restaurantId))
            {
                throw new DbUpdateException($"Restaurant ID '{restaurantId}' not found.", new NotSupportedException());
            }
            Favorite fav = new Favorite()
            {
                Username = username, RestaurantId = restaurantId
            };

            _db.Add(fav);
        }
        /// <summary>
        /// Adds the specified restaurant to the specified user's blacklist
        /// Throws an exception if specified user or restraunt is not found in DB
        /// Also throws exception if Blacklist already exists for that user
        /// Must still call Save() after to persist changes to DB
        /// </summary>
        /// <param name="username">string containing user's username</param>
        /// <param name="restaurantId">string containing restaurant's Id</param>
        /// <param name="rRepo">RestaurantRepo object, required for validation to ensure the given restraunt exists in our DB</param>
        public void AddRestaurantToBlacklist(string username, string restaurantId, RestaurantRepo rRepo)
        {
            if (!DBContainsUsername(username))
            {
                throw new DbUpdateException($"Username '{username}' not found.", new NotSupportedException());
            }
            if (!rRepo.DBContainsRestaurant(restaurantId))
            {
                throw new DbUpdateException($"Restaurant ID '{restaurantId}' not found.", new NotSupportedException());
            }
            Blacklist bl = new Blacklist()
            {
                Username = username, RestaurantId = restaurantId
            };

            _db.Add(bl);
        }
Exemple #3
0
        public async Task AddQueryRestaurantJunctionAsync(int queryId, List <Restaurant> restaurants, RestaurantRepo rRepo)
        {
            var contains = await DBContainsQueryAsync(queryId);

            if (!contains)
            {
                throw new DbUpdateException($"Query Id {queryId} not recognized.", new NotSupportedException());
            }
            foreach (Restaurant r in restaurants)
            {
                contains = await rRepo.DBContainsRestaurantAsync(r.Id);

                if (!contains)
                {
                    throw new DbUpdateException($"Restaurant Id {r.Id} not recognized.", new NotSupportedException());
                }
                _db.QueryRestaurantJunction.Add(new QueryRestaurantJunction()
                {
                    QueryId = queryId, RestaurantId = r.Id
                });
            }
        }
Exemple #4
0
 /// <summary>
 /// Given a queryId and list of restaurants, adds entries to the QueryRestaurantJunction table.
 /// Throws an exception if QueryId not found for whatever reason.
 /// </summary>
 /// <param name="queryId"></param>
 /// <param name="restaurants"></param>
 /// <param name="rRepo"></param>
 public void AddQueryRestaurantJunction(int queryId, List <Restaurant> restaurants, RestaurantRepo rRepo)
 {
     if (!DBContainsQuery(queryId))
     {
         throw new DbUpdateException($"Query Id {queryId} not recognized.", new NotSupportedException());
     }
     foreach (Restaurant r in restaurants)
     {
         if (!rRepo.DBContainsRestaurant(r.Id))
         {
             throw new DbUpdateException($"Restaurant Id {r.Id} not recognized.", new NotSupportedException());
         }
         _db.QueryRestaurantJunction.Add(new QueryRestaurantJunction()
         {
             QueryId = queryId, RestaurantId = r.Id
         });
     }
 }
        /// <summary>
        /// Removes the restaurant from a user's blacklist, if it exists
        /// Throws an exception if either the user or restaurant ids don't exist in the db, or if that restaurant isn't even currently on the blacklist
        /// </summary>
        /// <param name="username">user id to remove from blacklist of</param>
        /// <param name="restaurantId">restaurant id to remove from blacklist</param>
        /// <param name="rRepo">RestaurantRepo object, required for validation to ensure the given restraunt exists in our DB</param>
        public async Task RemoveRestaurantFromBlacklistAsync(string username, string restaurantId, RestaurantRepo rRepo)
        {
            var contains = await DBContainsUsernameAsync(username);

            if (!contains)
            {
                throw new DbUpdateException($"Username '{username}' not found.", new NotSupportedException());
            }
            contains = await rRepo.DBContainsRestaurantAsync(restaurantId);

            if (!contains)
            {
                throw new DbUpdateException($"Restaurant ID '{restaurantId}' not found.", new NotSupportedException());
            }
            _db.Blacklist.Remove(new Blacklist {
                Username = username, RestaurantId = restaurantId
            });
        }
        /// <summary>
        /// Adds the specified restaurant to the specified user's Favorites
        /// Throws an exception if specified user or restraunt is not found in DB
        /// Also throws exception if Favorite list already exists for that user
        /// Must still call Save() after to persist changes to DB
        /// </summary>
        /// <param name="username">string containing user's username</param>
        /// <param name="restaurantId">int containing restaurant's ID number</param>
        /// <param name="rRepo">RestaurantRepo object, required for validation to ensure the given restraunt exists in our DB</param>
        public async Task AddRestaurantToFavoritesAsync(string username, string restaurantId, RestaurantRepo rRepo)
        {
            var contains = await DBContainsUsernameAsync(username);

            if (!contains)
            {
                throw new DbUpdateException($"Username '{username}' not found.", new NotSupportedException());
            }
            contains = await rRepo.DBContainsRestaurantAsync(restaurantId);

            if (!contains)
            {
                throw new DbUpdateException($"Restaurant ID '{restaurantId}' not found.", new NotSupportedException());
            }
            Favorite fav = new Favorite()
            {
                Username = username, RestaurantId = restaurantId
            };

            _db.Add(fav);
        }
 /// <summary>
 /// Removes the restaurant from a user's blacklist, if it exists
 /// Throws an exception if either the user or restaurant ids don't exist in the db, or if that restaurant isn't even currently on the blacklist
 /// </summary>
 /// <param name="username">user id to remove from blacklist of</param>
 /// <param name="restaurantId">restaurant id to remove from blacklist</param>
 /// <param name="rRepo">RestaurantRepo object, required for validation to ensure the given restraunt exists in our DB</param>
 public void RemoveRestaurantFromBlacklist(string username, string restaurantId, RestaurantRepo rRepo)
 {
     if (!DBContainsUsername(username))
     {
         throw new DbUpdateException($"Username '{username}' not found.", new NotSupportedException());
     }
     if (!rRepo.DBContainsRestaurant(restaurantId))
     {
         throw new DbUpdateException($"Restaurant ID '{restaurantId}' not found.", new NotSupportedException());
     }
     _db.Blacklist.Remove(new Blacklist {
         Username = username, RestaurantId = restaurantId
     });
 }