示例#1
0
        public async Task <bool> DeleteShuttle(string toSearch, List <Guid> guids)
        {
            var shuttlesToDelete = await _repository.GetAllShuttles(
                new ShuttleFilter { ToSearch = toSearch, Ids = guids, PerfectMatch = true });

            if (!shuttlesToDelete.Any())
            {
                throw new CrewApiException
                      {
                          ExceptionMessage = "Shuttle is not in the repository.",
                          Severity         = ExceptionSeverity.Error,
                          Type             = ExceptionType.ServiceException
                      }
            }
            ;

            foreach (var shuttle in shuttlesToDelete)
            {
                var sameShuttleIdTeams = await _teamOfExplorersRepository.GetAllTeamsOfExplorers(
                    new TeamOfExplorersFilter { ShuttleGuid = shuttle.Id });

                if (sameShuttleIdTeams.Any())
                {
                    throw new CrewApiException
                          {
                              ExceptionMessage = $"Teams still contain the shuttle id {shuttle.Id}. Delete them before removing the shuttle.",
                              Severity         = ExceptionSeverity.Error,
                              Type             = ExceptionType.ServiceException
                          }
                }
                ;

                var client = _clientFactory.CreateClient();
                using var httpResponse =
                          await client.PutAsync($"http://localhost:5001/exports/update?shuttleId={shuttle.Id}", null);

                httpResponse.EnsureSuccessStatusCode();

                await _repository.DeleteShuttle(shuttle.Id);
            }

            return(true);
        }