Esempio n. 1
0
        public override async Task <DefaultResponse> AddFlightRoute(FlightRouteRequestModel request, ServerCallContext context)
        {
            var result = new DefaultResponse();

            try
            {
                var airports = await _airportProxy.GetAllAirports();

                if (!airports.Where(x => x.City == request.Source).Any())
                {
                    result.Message = $"There is no connection with the airport in {request.Source}";
                    return(result);
                }

                if (!airports.Where(x => x.City == request.Target).Any())
                {
                    result.Message = $"There is no connection with the airport in {request.Target}";
                    return(result);
                }

                var fligthRoute = new FlightRouteRaw()
                {
                    Source        = airports.Where(x => x.City == request.Source).FirstOrDefault().Id,
                    Target        = airports.Where(x => x.City == request.Target).FirstOrDefault().Id,
                    EstimatedTime = request.EstimatedTime
                };
                _airlineRepository.AddFligthRoute(fligthRoute);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"ERROR: Adding FligthRoute");
            }

            return(result);
        }