public async Task <bool> Handle(CreateFlightEveryDayOfWeekCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var plane = await _planeRepo.Get(request.PlaneId);

                var pilot = await _userRepo.FindById(request.PilotId);

                var departureAirport = await _airportRepo.Get(request.DepartureAirportId);

                var arrivalAirport = await _airportRepo.Get(request.ArrivalAirportId);

                if (plane == null || pilot == null || departureAirport == null || arrivalAirport == null)
                {
                    // TRHOW EXCEPTION
                }

                var flights = GenerateFlights(request, plane, pilot, departureAirport, arrivalAirport);

                foreach (var flight in flights)
                {
                    await _flightRepo.Create(flight);
                }
                //pilot.PilotFlights.Add(flight);
                //await _userRepo.Update(pilot);

                return(true);
            }
            catch (Exception ex)
            {
            }
            return(false);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Details(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var plane = await _repository.Get(id);

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

            return(View(plane));
        }
        public async Task <bool> Handle(UpdatePlaneToOkStatusCommand request, CancellationToken cancellationToken)
        {
            var plane = _repo.Get(request.PlaneId).Result;

            plane.UpdateStateToOk();
            await _repo.UpdateStatus(plane);

            return(true);
        }
        public async Task <bool> Handle(UpdatePlaneStatusCommand request, CancellationToken cancellationToken)
        {
            var plane = _repo.Get(request.Id).Result;

            if (plane == null)
            {
                // THROW EXCEPTION
            }
            plane.CheckAndUpdateState();
            await _repo.UpdateStatus(plane);

            return(true);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OnGetAsync(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Plane = await _repository.Get(id);

            if (Plane == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Id,DepartureAirport,ArrivalAirport,Plane")] Flight flight)
        {
            if (ModelState.IsValid)
            {
                flight.DepartureAirport = await _airportRepository.Get(flight.DepartureAirport.Id);

                flight.ArrivalAirport = await _airportRepository.Get(flight.ArrivalAirport.Id);

                flight.Plane = await _planeRepository.Get(flight.Plane.Id);

                var result = await _repository.CreateOrUpdate(flight);

                if (result == null)
                {
                    return(RedirectToAction(nameof(Index)));
                }

                return(RedirectToAction(nameof(Details), new { id = result }));
            }

            await SetViewData(flight);

            return(View(flight));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Flight.DepartureAirport = await _airportRepository.Get(Flight.DepartureAirport.Id);

            Flight.ArrivalAirport = await _airportRepository.Get(Flight.ArrivalAirport.Id);

            Flight.Plane = await _planeRepository.Get(Flight.Plane.Id);

            var result = await _repository.CreateOrUpdate(Flight);

            if (result == null)
            {
                return(RedirectToPage("./Index"));
            }

            return(RedirectToPage("./Details", new { id = result }));
        }
 public PlaneDTO GetPlaneById(int id)
 {
     return(Mapper.Map <Plane, PlaneDTO>(planeRepo.Get(id)));
 }
 public async Task <Plane> Handle(GetPlaneQuery request, CancellationToken cancellationToken)
 {
     return(await _repo.Get(request.PlaneId));
 }