Esempio n. 1
0
        public override void Execute()
        {
            try
            {
                //TODO: validate user permission
                if (!Repository.DoseCuisineIdExist(Request.CuisineId))
                {
                    Response.WasSucessfull = false;
                    throw new CuisineNotFoundException();
                }
                var fetchedRestaurants = Repository.GetRestaurantForCuisine(Request.CuisineId);

                Response.Restaurants   = fetchedRestaurants ?? Enumerable.Empty <Restaurant>();
                Response.WasSucessfull = true;
            }
            catch (CuisineNotFoundException)
            {
                ApplicationLog.InformationLog($"CuisineId ID {Request.CuisineId} not found");
                throw;
            }
            catch (Exception ex)
            {
                ApplicationLog.ErrorLog($"Error retrieving restaurants with CuisineId Id {Request.CuisineId}", ex);
                Response.WasSucessfull = false;
            }
        }
Esempio n. 2
0
        public override void Execute()
        {
            try
            {
                //TODO: validate user permission
                if (!Repository.DoseRestaurentIdExist(Request.RestaurantId))
                {
                    Response.WasSucessfull = false;
                    throw new RestaurantNotFoundException();
                }

                var fetchedReviewsForRestaurant = Repository.GetReviewsForRestaurant(Request.RestaurantId);

                Response.Reviews       = fetchedReviewsForRestaurant ?? Enumerable.Empty <Review>();
                Response.WasSucessfull = true;
            }
            catch (RestaurantNotFoundException)
            {
                ApplicationLog.InformationLog($"Restaurant with ID {Request.RestaurantId} not found");
                throw;
            }
            catch (Exception ex)
            {
                ApplicationLog.ErrorLog($"Error retrieving restaurant Id {Request.RestaurantId}", ex);
                Response.WasSucessfull = false;
            }
        }
        public override void Execute()
        {
            try
            {
                //TODO: validate user permission
                var restaurantFetched = Repository.GetRestaurantWithReviewsById(Request.RestaurantId);

                if (restaurantFetched == null)
                {
                    Response.WasSucessfull = false;
                    throw new RestaurantNotFoundException();
                }
                else
                {
                    Response.WasSucessfull = true;
                }
                Response.CuisineId     = restaurantFetched.Cuisine.Id;
                Response.CuisineName   = restaurantFetched.Cuisine.Name;
                Response.Name          = restaurantFetched.Name;
                Response.RestaurantId  = restaurantFetched.Id;
                Response.Reviews       = restaurantFetched.Reviews;
                Response.AverageRating = restaurantFetched.AverageRating;
                Response.ReviewCount   = restaurantFetched.ReviewCount;
            }
            catch (RestaurantNotFoundException)
            {
                ApplicationLog.InformationLog($"Restaurant with ID {Request.RestaurantId} not found");
                throw;
            }
            catch (Exception ex)
            {
                ApplicationLog.ErrorLog($"Error retrieving restaurant Id {Request.RestaurantId}", ex);
                Response.WasSucessfull = false;
            }
        }
Esempio n. 4
0
        public override void Execute()
        {
            try
            {
                //TODO: validate user permission
                if (Repository.DoseRestaurentNameAlreadyExist(Request.Name))
                {
                    throw new RestaurantAlreadyExistsException();
                }

                var cuisineRef = Repository.GetCuisineById(Request.CuisineId);
                if (cuisineRef == null)
                {
                    throw new CuisineNotFoundException();
                }

                Response.RestaurantId = Repository.AddRestaurentGetNewId(Request);
                Response.CuisineName  = cuisineRef.Name;

                Response.WasSucessfull = true;
            }
            catch (RestaurantAlreadyExistsException)
            {
                ApplicationLog.InformationLog($"Restaurant name {Request.Name} already exists");
                throw;
            }
            catch (Exception ex)
            {
                ApplicationLog.ErrorLog("Error adding new restaurant", ex);
                Response.WasSucessfull = false;
            }
        }
Esempio n. 5
0
        public override void Execute()
        {
            try
            {
                if (!Repository.DoseRestaurentIdExist(Request.RestaurantId))
                {
                    throw new RestaurantNotFoundException($"Restaurant ID :{Request.RestaurantId} not found");
                }
                if (!Repository.DoseUserIdAlreadyExist(Request.UserId))
                {
                    throw new UserNotFoundException($"User Id :{Request.UserId} not found");
                }
                //TODO: validate user permission

                var newReviewNumber = Repository.AddReviewGetNewId(Request);
                Response.ReviewNumber  = newReviewNumber;
                Response.WasSucessfull = true;
            }
            catch (RestaurantNotFoundException)
            {
                ApplicationLog.InformationLog($"Restaurant ID :{Request.RestaurantId} not found");
                throw;
            }
            catch (UserNotFoundException)
            {
                ApplicationLog.InformationLog($"User Id :{Request.UserId} not found");
                throw;
            }
            catch (Exception ex)
            {
                ApplicationLog.ErrorLog("Unable to add review", ex);
                Response.WasSucessfull = false;
            }
        }
Esempio n. 6
0
        public override void Execute()
        {
            try
            {
                //TODO: validate user permission
                var restaurantToUpdate = Repository.GetRestaurantById(Request.RestaurantId);
                if (restaurantToUpdate == null)
                {
                    throw new RestaurantNotFoundException();
                }

                if (IsRestaurantDataInRequestDifferentFromRepository(restaurantToUpdate))
                {
                    UpdateRequesWithMissingData(restaurantToUpdate);

                    ValidateInputRequest();

                    Repository.UpdateRestaurant(Request);
                }
                Response.WasSucessfull = true;
            }
            catch (RestaurantNotFoundException)
            {
                ApplicationLog.InformationLog($"Restaurant with ID {Request.RestaurantId} not found");
                throw;
            }
            catch (RestaurantAlreadyExistsException)
            {
                ApplicationLog.InformationLog($"Restaurant name {Request.Name} exists");
                throw;
            }
            catch (RestaurantInvalidInputException ex)
            {
                ApplicationLog.InformationLog(ex.Message);
                throw;
            }
            catch (CuisineNotFoundException ex)
            {
                ApplicationLog.InformationLog(ex.Message);
                throw;
            }
            catch (Exception ex)
            {
                ApplicationLog.ErrorLog("Restaurant was not updated", ex);
                Response.WasSucessfull = false;
            }
        }