public override async Task <AircraftRequestModel> GetAircraft(AircraftsFilter request, ServerCallContext context)
        {
            var response = new AircraftRequestModel();

            try
            {
                var aircrafts = await _aircraftRepository.GetAirCraft(request.LicensePlate);

                if (aircrafts == null)
                {
                    response.Message = $"Aircraft {request.LicensePlate} does not exist";
                    _logger.LogInformation($"Get Aircraft {request.LicensePlate} does not exist");
                    return(response);
                }
                response.LicensePlate = aircrafts.LicensePlate;
                response.Model        = aircrafts.Model;
                response.Passengers   = aircrafts.Passengers;

                _logger.LogInformation($"Get {aircrafts.LicensePlate} Aircraft");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"ERROR: Get {request.LicensePlate} Aircraft");
            }
            return(response);
        }
Exemple #2
0
        public async Task <IActionResult> Search(AircraftRequestModel aircraftRequestModel)
        {
            List <AircraftType> matchedAircraftTypes = string.IsNullOrEmpty(aircraftRequestModel.AircraftType)
                                                    ? await _context.AircraftTypes.ToListAsync()
                                                    : await _context.AircraftTypes.Where(act => act.Name.Contains(aircraftRequestModel.AircraftType)).ToListAsync();

            List <Guid> ListAircraftTypeId = matchedAircraftTypes.Select(act => act.Id).ToList();

            List <Aircraft> matchedAircraft = await _context.Aircrafts.Where(ac => ListAircraftTypeId.Contains(ac.AircraftTypeId)).ToListAsync();

            List <Guid> ListAirlineId = matchedAircraft.Select(ac => ac.AirlineId).ToList();


            List <Airline> matchedAirlines = string.IsNullOrEmpty(aircraftRequestModel.Airline)
                                            ? await _context.Airlines.Where(al => ListAirlineId.Contains(al.Id)).ToListAsync()
                                            : await _context.Airlines.Where(al => al.Name.Contains(aircraftRequestModel.Airline)).ToListAsync();

            List <AircraftSearch> aircraftSearches = new List <AircraftSearch>();

            foreach (var aircraft in matchedAircraft)
            {
                AircraftType aircraftTypeFound = matchedAircraftTypes.FirstOrDefault(act => act.Id == aircraft.AircraftTypeId);
                Airline      airlineFound      = matchedAirlines.FirstOrDefault(al => al.Id == aircraft.AirlineId);

                if (aircraftTypeFound != null && airlineFound != null)
                {
                    AircraftSearch newAircraftSearch = new AircraftSearch
                    {
                        AircraftType   = aircraftTypeFound,
                        CurrentAirline = airlineFound
                    };
                    aircraftSearches.Add(newAircraftSearch);
                }
            }

            AircraftIndexModel viewModel = new AircraftIndexModel()
            {
                AircraftSearches = aircraftSearches,
                Notification     = new AlertNotification()
            };

            return(View("Index", viewModel));
        }
        public override Task <DefaultResponse> AddAircraft(AircraftRequestModel request, ServerCallContext context)
        {
            try
            {
                var aircraft = new AircraftRaw()
                {
                    LicensePlate = request.LicensePlate,
                    Model        = request.Model,
                    Passengers   = request.Passengers
                };
                _aircraftRepository.AddAirCraft(aircraft);
                _logger.LogInformation($"Add {request.LicensePlate} Aircraft");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"ERROR: Add {request.LicensePlate} Aircraft");
            }

            return(Task.FromResult(new DefaultResponse()));
        }