public ActionResult Book(FlightsBook viewModel)
        {
            Connection conn = connectionRepository.Find(viewModel.Connection.ID);

            Flight bookedFlight = new Flight();

            bookedFlight.AircraftTypeICAO = viewModel.AircraftTypeICAO;
            bookedFlight.AirlineICAO = conn.AirlineICAO;
            bookedFlight.BookedOn = DateTime.UtcNow;
            bookedFlight.DepartureAirportICAO = conn.DepartureAirportICAO;
            bookedFlight.DestinationAirportICAO = conn.DestinationAirportICAO;
            // TODO maybe change to prefix and id seperated
            bookedFlight.FlightNumber = conn.Name;
            bookedFlight.UserID = UserContext.GetCurrent().ID;

            flightRepository.InsertOrUpdate(bookedFlight);
            flightRepository.Save();

            if (viewModel.Option == 1 || viewModel.Option == 2) {

                Rotation rotation;

                if(viewModel.Option == 1) {
                    rotation = new Rotation();
                    rotation.Name = viewModel.NewRotationName;
                    rotation.Flights = new List<Flight>();
                    rotation.UserID = UserContext.GetCurrent().ID;

                } else {
                    rotation = rotationRepository.AllIncluding(m => m.Flights).Single(t => t.ID == viewModel.RotationID.Value);
                }

                rotation.Flights.Add(bookedFlight);

                rotationRepository.InsertOrUpdate(rotation);
                rotationRepository.Save();
            }

            return RedirectToAction("BookingSaved", new { id = conn.ID });
        }
        public PartialViewResult Book(int id)
        {
            FlightsBook viewModel = new FlightsBook();

            int userID = UserContext.GetCurrent().ID;

            var rotationsOfUser = rotationRepository.All.Where(t => t.UserID == userID).ToList();
            var selectedConnection = connectionRepository.AllIncluding(m => m.Departure, m => m.Destination).Single(t => t.ID == id);

            viewModel.PossibleRotations = rotationsOfUser.Select(t => new SelectListItem() { Text = t.Name, Value = t.ID.ToString() }).ToList();
            viewModel.Connection = selectedConnection;

            if (!selectedConnection.AircraftType.TypeGroup.HasValue) {
                throw new NotSupportedException("AircraftType of selected connection has no assigned TypeGroup");
            }

            int typeGroup = selectedConnection.AircraftType.TypeGroup.Value;

            List<int> currentTypeRatingsOfUser = userTypeRatingRepository.CurrentUserTypeRatings(userID).Select(t => t.TypeRatingID).ToList();

            if (!currentTypeRatingsOfUser.Any()) {
                throw new NotSupportedException("User has absolutely no type ratings.");
            }

            IQueryable<AircraftType> allPossibleAicraftTypes = aircraftTypeRepository.All.Where(t => t.TypeGroup == typeGroup && currentTypeRatingsOfUser.Contains(t.TypeRatingID.Value));

            viewModel.PossibleAircraftTypes = allPossibleAicraftTypes.ToList().Select(t => new SelectListItem() { Text = t.Longname, Value = t.ICAO }).ToList();

            return PartialView(viewModel);
        }