Beispiel #1
0
        public async Task <AddResult> AddAsync(Flight flight)
        {
            FlightEntity flightDal = _mapper.Map <FlightEntity>(flight);

            AirportEntity toAirport = await _airportRepository.GetByIdAsync(flightDal.ToAirportId);

            AirportEntity fromAirport = await _airportRepository.GetByIdAsync(flightDal.FromAirportId);

            if (toAirport == null || fromAirport == null)
            {
                return(new AddResult(ResultTypes.NotFound, null));
            }

            AirplaneEntity airplane = await _airplaneRepository.GetByIdAsync(flightDal.AirplaneId);

            if (airplane == null)
            {
                return(new AddResult(ResultTypes.NotFound, null));
            }

            if (flight.ArrivalTime <= flight.DepartureTime)
            {
                return(new AddResult(ResultTypes.InvalidData, null));
            }

            int addedFlightId = await _flightRepository.AddAsync(flightDal);

            return(new AddResult(ResultTypes.Ok, addedFlightId));
        }
Beispiel #2
0
        public async Task <Airplane> GetByIdAsync(int id)
        {
            AirplaneEntity airplaneDal = await _airplaneRepository.GetByIdAsync(id);

            Airplane airplane = _mapper.Map <Airplane>(airplaneDal);

            return(airplane);
        }
Beispiel #3
0
        // GET: Airplanes/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var airplane = await _airplaneRepository.GetByIdAsync(id.Value);

            if (airplane == null)
            {
                return(NotFound());
            }

            return(View(airplane));
        }