Esempio n. 1
0
        public async Task <ActionResult> GetAllProducts()
        {
            _logger.LogInformation("Calling GetAllProducts on the repository");
            var error = new ErrorResponse {
                RequestId = HttpContext?.TraceIdentifier ?? Guid.NewGuid().ToString()
            };

            try
            {
                if (ModelState.IsValid)
                {
                    var result = await _evalRepository.GetAllProductsAsync();

                    if (result != null)
                    {
                        return(new JsonResult(result));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
            }
            catch (Exception e)
            {
                error.Errors.Add(ErrorModel.FromApiErrorCode(ApiErrorCode.FailToGetData));
                _logger.LogError($"Fail to retrieve prescribing information {e.Message}", e);
                return(StatusCode((int)HttpStatusCode.InternalServerError, error));
            }

            return(BadRequest());
        }