Example #1
0
        public async Task <BaseResponse <RestaurantGetResponse> > GetAsync(RestaurantGetRequest request)
        {
            BaseResponse <RestaurantGetResponse> response = new BaseResponse <RestaurantGetResponse>();
            var dataRequest = request.Map <RestaurantGetCoreRequest>();

            try
            {
                if (!string.IsNullOrEmpty(request.Id))
                {
                    var dataResponse = await _restaurantsRepository.GetAsync(dataRequest);

                    response.Data = dataResponse.Data.Map <RestaurantGetResponse>();
                }
                else
                {
                    response.Errors.Add("Id is can not be empty.");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);

                response.Errors.Add("An error occurred while processing your request.");
            }

            return(response);
        }
Example #2
0
        public async Task <IActionResult> Get(string id)
        {
            try
            {
                RestaurantGetRequest request = new RestaurantGetRequest {
                    Id = id
                };
                BaseResponse <Restaurant> RestaurantResponse = await _RestaurantService.GetRestaurantAsync(request);

                if (RestaurantResponse.HasError)
                {
                    return(BadRequest(RestaurantResponse.Errors));
                }

                if (RestaurantResponse.Data == null)
                {
                    return(NotFound("No Restaurant found for requested filter."));
                }

                return(Ok(RestaurantResponse));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Example #3
0
        public async Task <BaseResponse <Restaurant> > GetRestaurantAsync(RestaurantGetRequest request)
        {
            BaseResponse <Restaurant> response = new BaseResponse <Restaurant>();

            try
            {
                IAsyncCursor <Restaurant> Restaurants = await _mongoDatabase.GetCollection <Restaurant>(BEKLEMEYAPMA_RESTAURANT_COLLECTION_NAME).FindAsync(d => d.Id == request.Id);

                response.Data = await Restaurants.FirstOrDefaultAsync();
            }
            catch (Exception ex)
            {
                response.Errors.Add(ex.Message);
                _logger.LogError(ex, ex.Message);
            }

            return(response);
        }
Example #4
0
        public async Task <IActionResult> Get(string id)
        {
            RestaurantGetRequest restaurantGetRequest = new RestaurantGetRequest()
            {
                Id = id
            };

            BaseResponse <RestaurantGetResponse> response = await _restaurantsService.GetAsync(restaurantGetRequest);

            if (!response.HasError && response.Data != null)
            {
                return(Ok(response.Data));
            }
            else if (!response.HasError && response.Data == null)
            {
                return(NotFound("No product found for requested filter."));
            }
            else
            {
                return(BadRequest(response.Errors));
            }
        }