示例#1
0
        public async Task <ActionResult <Starship> > GetStarship([FromRoute] int id)
        {
            var starship = await _repository.GetStarshipById(id);

            if (starship == null)
            {
                return(NotFound());
            }

            return(Ok(starship));
        }
示例#2
0
        public async Task <ActionResult <Starship> > GetStarship(int id)
        {
            var result = await _starshipRepository.GetStarshipById(id);

            try
            {
                if (result != null)
                {
                    _logger.LogInformation($"Getting starship with id {id}.");
                    return(result);
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception exception)
            {
                _logger.LogInformation($"Could not get starship with id {id} from the database");
                return(StatusCode(StatusCodes.Status500InternalServerError, $"Database failure: {exception.Message}"));
            }
        }