示例#1
0
        public async Task <IActionResult> Add()
        {
            List <Drone> drones = await _drones.GetDronesAsync();

            List <Location> locations = await _locations.GetLocationsAsync();

            List <Operator> operators = await _operators.GetOperatorsAsync();

            AddFlightViewModel model = new AddFlightViewModel();

            model.SetDrones(drones);
            model.SetLocations(locations);
            model.SetOperators(operators);

            return(View(model));
        }
示例#2
0
        public async Task <IActionResult> Add(AddFlightViewModel model)
        {
            IActionResult result;

            if (ModelState.IsValid)
            {
                DateTime start = CombineDateAndTime(model.StartDate, model.StartTime);
                DateTime end   = CombineDateAndTime(model.EndDate, model.EndTime);

                Flight flight = await _flights.AddFlightAsync(
                    model.DroneId,
                    model.LocationId,
                    model.OperatorId,
                    start,
                    end);

                // Redirect to the flight details/properties page
                result = RedirectToAction("Index", "FlightDetails", new { id = flight.Id });
            }
            else
            {
                // If the model state isn't valid, load the lists of drones,
                // locations and operators and redisplay the flight logging page
                List <Drone> drones = await _drones.GetDronesAsync();

                List <Location> locations = await _locations.GetLocationsAsync();

                List <Operator> operators = await _operators.GetOperatorsAsync();

                model.SetDrones(drones);
                model.SetLocations(locations);
                model.SetOperators(operators);

                result = View(model);
            }

            return(result);
        }