public async Task <bool> UpdateTeamOfExplorers(TeamOfExplorers inputTeamOfExplorers) { _dataContext.TeamsOfExplorers.Update(inputTeamOfExplorers); await _dataContext.SaveChangesAsync(); return(true); }
private static bool ValidateName(TeamOfExplorers inputTeamOfExplorers) { if (inputTeamOfExplorers.Name.Length <= 1) { throw new CrewApiException { ExceptionMessage = $"TeamOfExplorers's Name {inputTeamOfExplorers.Name} cannot be 1 character or less.", Severity = ExceptionSeverity.Error, Type = ExceptionType.ValidationException } } ; return(true); } }
public async Task <bool> CreateTeamOfExplorers(TeamOfExplorers inputTeamOfExplorers) { _teamOfExplorersValidator.Validate(inputTeamOfExplorers); var sameIdShuttles = await _shuttleRepository.GetAllShuttles( new ShuttleFilter { Ids = new List <Guid> { inputTeamOfExplorers.ShuttleId } }); if (sameIdShuttles.Count != 1) { throw new CrewApiException { ExceptionMessage = $"TeamOfExplorers's Shuttle id {inputTeamOfExplorers.ShuttleId} does not correspond to any shuttle !", Severity = ExceptionSeverity.Error, Type = ExceptionType.ServiceException } } ; var sameNameTeamsOfExplorers = await _repository.GetAllTeamsOfExplorers( new TeamOfExplorersFilter { ToSearch = inputTeamOfExplorers.Name, PerfectMatch = true }); if (sameNameTeamsOfExplorers.Any()) { throw new CrewApiException { ExceptionMessage = $"TeamOfExplorers name {inputTeamOfExplorers.Name} is not unique !", Severity = ExceptionSeverity.Error, Type = ExceptionType.ServiceException } } ; var sameIdTeamsOfExplorers = await _repository.GetAllTeamsOfExplorers( new TeamOfExplorersFilter { Ids = new List <Guid>() { inputTeamOfExplorers.Id } }); if (sameIdTeamsOfExplorers.Any()) { throw new CrewApiException { ExceptionMessage = $"TeamOfExplorers id {inputTeamOfExplorers.Id} already exists in the repository !", Severity = ExceptionSeverity.Error, Type = ExceptionType.ServiceException } } ; var sameShuttleIdTeamsOfExplorers = await _repository.GetAllTeamsOfExplorers( new TeamOfExplorersFilter { ShuttleGuid = sameIdShuttles.First().Id }); if (sameShuttleIdTeamsOfExplorers.Any()) { throw new CrewApiException { ExceptionMessage = $"TeamOfExplorers's Shuttle id {inputTeamOfExplorers.ShuttleId} has already been assigned to another team !", Severity = ExceptionSeverity.Error, Type = ExceptionType.ServiceException } } ; return(await _repository.CreateTeamOfExplorers(inputTeamOfExplorers)); }
public async Task <bool> UpdateTeamOfExplorers(TeamOfExplorers inputTeamOfExplorers) { _teamOfExplorersValidator.Validate(inputTeamOfExplorers); var sameIdTeamOfExplorers = await _repository.GetAllTeamsOfExplorers( new TeamOfExplorersFilter { Ids = new List <Guid> { inputTeamOfExplorers.Id } }); if (!sameIdTeamOfExplorers.Any()) { throw new CrewApiException { ExceptionMessage = "Team of explorers to update has not been found.", Severity = ExceptionSeverity.Error, Type = ExceptionType.ServiceException } } ; if (inputTeamOfExplorers.Name != sameIdTeamOfExplorers.First().Name) { var sameNameTeamOfExplorers = await _repository.GetAllTeamsOfExplorers( new TeamOfExplorersFilter { ToSearch = inputTeamOfExplorers.Name, PerfectMatch = true }); if (sameNameTeamOfExplorers.Any()) { throw new CrewApiException { ExceptionMessage = $"Cannot update team of explorers name {inputTeamOfExplorers.Name} to one that already exists.", Severity = ExceptionSeverity.Error, Type = ExceptionType.ServiceException } } ; } if (inputTeamOfExplorers.ShuttleId != sameIdTeamOfExplorers.First().ShuttleId) { var shuttlesWithId = await _shuttleRepository.GetAllShuttles(new ShuttleFilter { Ids = new List <Guid> { inputTeamOfExplorers.ShuttleId } }); if (!shuttlesWithId.Any()) { throw new CrewApiException { ExceptionMessage = $"TeamOfExplorers's Shuttle id {inputTeamOfExplorers.ShuttleId} does not correspond to any shuttle !", Severity = ExceptionSeverity.Error, Type = ExceptionType.ServiceException } } ; var sameShuttleIdTeams = await _repository.GetAllTeamsOfExplorers( new TeamOfExplorersFilter { ShuttleGuid = inputTeamOfExplorers.ShuttleId }); if (sameShuttleIdTeams.Any()) { throw new CrewApiException { ExceptionMessage = $"TeamOfExplorers's Shuttle id {inputTeamOfExplorers.ShuttleId} has already been assigned to another team !", Severity = ExceptionSeverity.Error, Type = ExceptionType.ServiceException } } ; } var team = sameIdTeamOfExplorers.First(); team.UpdateByReflection(inputTeamOfExplorers); return(await _repository.UpdateTeamOfExplorers(team)); } } }