Exemplo n.º 1
0
        public async Task ExecuteAsync(DeletePilotCommand command)
        {
            var pilot = await _pilotRepository.GetById(command.PilotId);

            if (pilot == null)
            {
                throw new Exception("Pilot with this Id does not exist");
            }

            await _pilotRepository.Delete(pilot.Id);
        }
        public async Task ExecuteAsync(CreatePilotCommand command)
        {
            if (await _pilotRepository.GetById(command.Id) != null)
            {
                throw new Exception("Pilot with same Id already exists");
            }

            var pilot = _mapper.Map <Airport.Domain.Entities.Pilot>(command);

            await _pilotRepository.Create(pilot);
        }
        public async Task <PilotByIdResponse> ExecuteAsync(PilotByIdQuery request)
        {
            var pilot = await _pilotRepository.GetById(request.PilotId);

            if (pilot == null)
            {
                throw new Exception("Idea not found");
            }

            var mappedPilot = _mapper.Map <PilotByIdResponse>(pilot);

            return(mappedPilot);
        }
        public async Task ExecuteAsync(UpdateCrewCommand command)
        {
            var crew = await _crewRepository.GetById(command.CrewId);

            if (crew == null)
            {
                throw new Exception("Crew with this Id does not exist");
            }

            crew.Pilot        = _pilotRepository.GetById(command.PilotId).Result;
            crew.Stewardesses = _stewardessRepository.GetAll().Where(y => command.StewardressesId.Contains(y.Id));

            await _crewRepository.Update(crew);
        }
Exemplo n.º 5
0
        public async Task ExecuteAsync(UpdatePilotCommand command)
        {
            var pilot = await _pilotRepository.GetById(command.Id);

            if (pilot == null)
            {
                throw new Exception("Pilot with this Id does not exist");
            }

            pilot.FirstName   = command.FirstName ?? pilot.FirstName;
            pilot.LastName    = command.LastName ?? pilot.LastName;
            pilot.DateOfBirth = command.DateOfBirth;
            pilot.Experience  = command.Experience;

            await _pilotRepository.Update(pilot);
        }
        public async Task ExecuteAsync(CreateCrewCommand command)
        {
            if (await _crewRepository.GetById(command.Id) != null)
            {
                throw new Exception("Crew with same Id already exists");
            }

            var crew = new Domain.Entities.Crew
            {
                Id           = command.Id,
                Pilot        = await _pilotRepository.GetById(command.PilotId),
                Stewardesses = await _stewardessRepository.GetAll().Where(y => command.StewardressesId.Contains(y.Id)).ToListAsync()
            };

            await _crewRepository.Create(crew);
        }
Exemplo n.º 7
0
        /// <summary>
        /// This service will get all starships with their existing pilots
        /// if it can hold a certain amount of passengers.
        /// </summary>
        /// <param name="passengerCount"></param>
        /// <returns></returns>
        public async Task <List <Starship> > GetStarshipsByPassengerCount(int passengerCount)
        {
            var starships = await starshipRepository.GetAll();

            var availableStarships = starships.Where(s =>
            {
                if (int.TryParse(s.Passengers, out var maxCapacity))
                {
                    if (maxCapacity >= passengerCount && s.PilotEndpoints != null)
                    {
                        return(true);
                    }
                }
                return(false);
            });

            var starshipViewList = new List <Starship>();

            foreach (var starship in availableStarships)
            {
                var starshipView = new Starship
                {
                    Name   = starship.Name,
                    Pilots = new List <Pilot>()
                };

                if (starship.PilotEndpoints?.Count > 0)
                {
                    foreach (var endpoint in starship.PilotEndpoints)
                    {
                        var pilot = new Pilot
                        {
                            Id = Convert.ToInt32(endpoint.Split(@"/").Where(part => part != string.Empty).Last())
                        };

                        var pilotInfo = await pilotRepository.GetById(pilot.Id);

                        pilot.Name = pilotInfo.Name;
                        starshipView.Pilots.Add(pilot);
                    }
                }

                starshipViewList.Add(starshipView);
            }

            return(starshipViewList);
        }