コード例 #1
0
        /// <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
            });
        }
コード例 #2
0
        /// <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);
        }
コード例 #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
                });
            }
        }