コード例 #1
0
        public async Task <IEnumerable <ResupplyResponse> > CalculateResupplyRequiredForAllStarships(decimal distance)
        {
            var starships = await _starshipRepository.GetAllStarships();

            var calculedResupplies = new List <ResupplyResponse>();

            foreach (var starship in starships)
            {
                calculedResupplies.Add(CalculateResupplyStops(starship, distance));
            }

            return(calculedResupplies);
        }
コード例 #2
0
        public async Task <ActionResult <IList <Starship> > > GetStarships()
        {
            var results = await _starshipRepository.GetAllStarships();

            try
            {
                if (results.Count > 0 || results != null)
                {
                    _logger.LogInformation("Getting starships from database");
                    return(Ok(results));
                }
                else
                {
                    _logger.LogInformation($"Could not get any starships from the database");
                    return(NotFound());
                }
            }
            catch (Exception exception)
            {
                _logger.LogInformation($"Could not get any starships from the database");
                return(StatusCode(StatusCodes.Status500InternalServerError, $"Database failure: {exception.Message}"));
            }
        }
コード例 #3
0
        public async Task <ActionResult <IEnumerable <Starship> > > GetStarships()
        {
            var starships = await _repository.GetAllStarships();

            return(Ok(starships));
        }