public async Task <FlightDetailsViewModel> GetFlight(string flightId) { var flight = await this.db.Flights.Include(f => f.Reservations).FirstOrDefaultAsync(f => f.Id == flightId); var result = new FlightDetailsViewModel() { FlightId = flight.Id, FromLocation = flight.FromLocation, AirlineID = flight.AirlineID, AirlineName = flight.AirlineName, FlightDuration = (flight.DepatureTime - flight.ArrivalTime).TotalHours.ToString(), BusinessCapacity = flight.BusinessCapacity, Capacity = flight.Capacity, DepatureTime = flight.DepatureTime, PilotName = flight.PilotName, ToLocation = flight.ToLocation, Reservations = flight.Reservations.Select(r => new ReservationUserViewModel() { FirstName = r.FirstName, LastName = r.LastName, TicketType = r.TicketType, }).ToList(), }; return(result); }
/// <summary> /// Either retrieve an existing flight or create a new one /// </summary> /// <param name="userName"></param> /// <returns></returns> private async Task <Flight> RetrieveOrCreateFlight(string userName) { Flight flight = null; // Retrieve the flight details from the cache string key = GetCacheKey(FlightDetailsKeyPrefix, userName); FlightDetailsViewModel details = _cache.Get <FlightDetailsViewModel>(key); if (details != null) { // If this is a sighting for an existing flight, just return it. // Otherwise, we need to create a new flight if (details.FlightId > 0) { flight = await _flights.GetFlightByIdAsync(details.FlightId); } else { if (details.AirlineId == 0) { // If there's no airline selected, we're creating a new one Airline airline = await _airlines.AddAirlineAsync(details.NewAirline); details.AirlineId = airline.Id; } // Create the flight flight = await _flights.AddFlightAsync(details.FlightNumber, details.Embarkation, details.Destination, details.AirlineId); } } return(flight); }
public IActionResult ChangeFlightReservationsPageSize(FlightDetailsViewModel model, int pageSize) { FlightDetailsPaging.Pager.PageSize = pageSize; FlightDetailsPaging.Pager.CurrentPage = 1; return(View("FlightDetails", GetFlightDetails())); }
public async Task <IActionResult> Index(int id) { Flight flight = await _flights.GetFlightAsync(id); FlightDetailsViewModel model = _mapper.Map <FlightDetailsViewModel>(flight); await LoadModelPropertiesAsync(model); return(View(model)); }
public ActionResult Details(FlightDetailsViewModel createModel) { if (!ModelState.IsValid) { return(View(createModel)); } else { return(RedirectToAction("Reserve", "Reservations", new { flightid = createModel.FlightId, ticketNum = createModel.TicketNum, availableRegularSeats = createModel.RegularSeats, availableBusinessSeats = createModel.BusinessSeats })); } }
/// <summary> /// /// </summary> /// <param name="model"></param> /// <returns></returns> private async Task LoadModelPropertiesAsync(FlightDetailsViewModel model) { // Load any existing flight property values model.Properties = await _properties.GetFlightPropertyValuesAsync(model.Id); // The model will only contain values for properties where the value // has been set. This is not necessarily all available properties but // we need controls for all properties to be rendered so we can enter // values for them. To achieve this, merge in the list of available // properties (with empty values) List <FlightProperty> availableProperties = await _properties.GetFlightPropertiesAsync(); model.MergeProperties(availableProperties); model.PropertiesPerRow = _settings.Value.FlightPropertiesPerRow; }
public IActionResult Details(int Id) { var currentFlight = this.context.Flights.First(c => c.Id == Id); FlightDetailsViewModel flightDetailsViewModel = new FlightDetailsViewModel() { Id = currentFlight.Id, From = currentFlight.From, To = currentFlight.To, DepartureTime = currentFlight.Departure, Arrival = currentFlight.Arrival, PlaneId = currentFlight.PlaneId, PilotName = currentFlight.PilotName, CapacityBusiness = currentFlight.BusinessCapacity, CapacityEconomy = currentFlight.EconomyCapacity }; return(View(flightDetailsViewModel)); }
/// <summary> /// Retrieve or constuct the flight details model /// </summary> /// <param name="userName"></param> /// <returns></returns> public async Task <FlightDetailsViewModel> GetFlightDetailsModelAsync(string userName) { // Retrieve the model from the cache string key = GetCacheKey(FlightDetailsKeyPrefix, userName); FlightDetailsViewModel model = _cache.Get <FlightDetailsViewModel>(key); if (model == null) { // Not cached, so create a new one, using the cached sighting details // model to supply the flight number key = GetCacheKey(SightingDetailsKeyPrefix, userName); SightingDetailsViewModel sighting = _cache.Get <SightingDetailsViewModel>(key); model = new FlightDetailsViewModel { FlightNumber = sighting.FlightNumber }; } // Set the available airlines List <Airline> airlines = await GetAirlinesAsync(); model.SetAirlines(airlines); // Set the matching flight numbers List <Flight> flights = await GetFlightsAsync(model.FlightNumber); model.SetFlights(flights); // If we have any flights, pick the first one as the default selection from // which to populate the model Flight flight = flights?.FirstOrDefault(); if (flight != null) { model.FlightId = flight.Id; model.Embarkation = flight.Embarkation; model.Destination = flight.Destination; model.AirlineId = flight.AirlineId; } return(model); }
public IHttpResponse Edit(FlightDetailsViewModel model) { var flight = this.Db.Flights.FirstOrDefault(f => f.Id == model.Id); if (flight == null) { return(this.BadRequestError("Flight do not exist.")); } //TODO verification flight.Destination = model.Destination; flight.Origin = model.Origin; flight.Date = model.Date; flight.Time = model.Time; flight.ImageUrl = model.ImageUrl; flight.PublicFlag = model.PublicFlag; this.Db.SaveChanges(); return(this.Redirect("/Flights/Details?id=" + flight.Id)); }
public ActionResult Details(int id) { var flight = _context.Flights.Find(id); int[] availableSeats = GetAvailableTickets(id); FlightDetailsViewModel model = new FlightDetailsViewModel() { FlightId = flight.Id, LocationFrom = flight.LocationFrom, LocationTo = flight.LocationTo, DepartureTime = flight.DepartureTime, LandingTime = flight.LandingTime, PlaneType = flight.PlaneType, PlaneNumber = flight.PlaneNumber, PilotName = flight.PilotName, RegularSeats = availableSeats[0], BusinessSeats = availableSeats[1] }; return(View(model)); }
public IHttpResponse Edit(int id) { var flight = this.Db.Flights.FirstOrDefault(f => f.Id == id); if (flight == null) { return(this.BadRequestError("Flight do not exist.")); } var model = new FlightDetailsViewModel() { Id = id, Destination = flight.Destination, Origin = flight.Origin, Date = flight.Date, Time = flight.Time, ImageUrl = flight.ImageUrl, PublicFlag = flight.PublicFlag }; return(this.View(model)); }
public async Task <IActionResult> Index(FlightDetailsViewModel model) { // Load the flight details Flight flight = await _flights.GetFlightAsync(model.Id); _mapper.Map <Flight, FlightDetailsViewModel>(flight, model); // The (complex) model properties will not be bound by the model binder // and so need to be loaded, here, and updated using the dictionary of // property values that are bound by the model binder await LoadModelPropertiesAsync(model); if (ModelState.IsValid) { // Apply property values from the bound collection model.UpdatePropertiesFromBoundValues(); // Save newly added property values for (int i = 0; i < model.Properties.Count; i++) { FlightPropertyValue value = model.Properties[i]; if (value.IsNewPropertyValue) { model.Properties[i] = await AddNewPropertyValueAsync(model.Id, model.Properties[i]); } else if (value.Id > 0) { model.Properties[i] = await _properties.UpdateFlightPropertyValueAsync( value.Id, value.NumberValue, value.StringValue, value.DateValue); } } } return(View(model)); }
public async Task <IActionResult> Index(FlightDetailsViewModel model) { IActionResult result; string newAirline = (model.NewAirline ?? "").Trim(); bool haveAirline = (model.AirlineId > 0) || !string.IsNullOrEmpty(newAirline); if (haveAirline && ModelState.IsValid && (model.Action == ControllerActions.ActionNextPage)) { _wizard.CacheFlightDetailsModel(model, User.Identity.Name); result = RedirectToAction("Index", "AircraftDetails"); } else if (model.Action == ControllerActions.ActionPreviousPage) { _wizard.ClearCachedFlightDetailsModel(User.Identity.Name); int?sightingId = _wizard.GetCurrentSightingId(User.Identity.Name); result = RedirectToAction("Index", "SightingDetails", new { Id = sightingId }); } else { if (!haveAirline) { model.AirlineErrorMessage = "You must select an airline or give a new airline name"; } List <Flight> flights = await _wizard.GetFlightsAsync(model.FlightNumber); model.SetFlights(flights); List <Airline> airlines = await _wizard.GetAirlinesAsync(); model.SetAirlines(airlines); result = View(model); } return(result); }
public IActionResult Delete(int id, int?page, int pageSize = 10) { int pageNumber = (page ?? 1); Flight flight = flightService.GetFlightById(id); FlightDetailsViewModel model = new FlightDetailsViewModel() { FlightId = flight.Id, BusinessClassCapacity = flight.BusinessClassCapacity, PilotName = flight.PilotName, DepartureCity = flight.LeavingFrom, DepartureTime = flight.Departure, DestinationCity = flight.GoingTo, FlightDuration = flight.Arrival.Subtract(flight.Departure), PlaneCapacity = flight.PassengersCapacity, PlaneType = flight.AirplaneType, BusinessTicketsLeft = flight.BusinessTicketsLeft, TicketsLeft = flight.TicketsLeft, Reservations = reservationService.GetAllReservationsForFlight(flight).Select(r => new FlightReservationViewModel() { Email = r.Email, Name = r.FirstName + " " + r.MiddleName + " " + r.Surname, Nationality = r.Nationality, PhoneNumber = r.PhoneNumber, SSN = r.SSN, TicketType = r.TicketType, TicketsCount = r.TicketsCount }).ToList(), PageNumber = pageNumber, PageSize = pageSize, PagesCount = (int)Math.Ceiling(reservationService.GetAllReservationsForFlight(flight).Count / (double)pageSize) }; model.Reservations = model.Reservations.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList(); return(View(model)); }
public IHttpResponse Details(int id) { var flight = this.Db.Flights.FirstOrDefault(f => f.Id == id); if (flight == null) { return(this.BadRequestError("Flight do not exist.")); } var availableFligthSeats = this.Db.Seats.Where(s => s.FlightId == flight.Id).ToList(); var model = new FlightDetailsViewModel() { Id = flight.Id, Destination = flight.Destination, Origin = flight.Origin, Date = flight.Date, Time = flight.Time, ImageUrl = flight.ImageUrl.UrlDecode(), AvailableFlightSeats = availableFligthSeats }; return(this.View(model)); }
/// <summary> /// Cache the flight details view model /// </summary> /// <param name="userName"></param> /// <param name="model"></param> public void CacheFlightDetailsModel(FlightDetailsViewModel model, string userName) { string key = GetCacheKey(FlightDetailsKeyPrefix, userName); _cache.Set <FlightDetailsViewModel>(key, model, _settings.Value.CacheLifetimeSeconds); }
/// <summary> /// Construct the model to confirm sighting details /// </summary> /// <param name="userName"></param> /// <returns></returns> public async Task <ConfirmDetailsViewModel> GetConfirmDetailsModelAsync(string userName) { // Get the sighting, flight details and aircraft models and map them // into the confirm details model ConfirmDetailsViewModel model = new ConfirmDetailsViewModel(); string key = GetCacheKey(SightingDetailsKeyPrefix, userName); SightingDetailsViewModel sighting = _cache.Get <SightingDetailsViewModel>(key); _mapper.Map <SightingDetailsViewModel, ConfirmDetailsViewModel>(sighting, model); key = GetCacheKey(FlightDetailsKeyPrefix, userName); FlightDetailsViewModel flight = _cache.Get <FlightDetailsViewModel>(key); _mapper.Map <FlightDetailsViewModel, ConfirmDetailsViewModel>(flight, model); key = GetCacheKey(AircraftDetailsKeyPrefix, userName); AircraftDetailsViewModel aircraft = _cache.Get <AircraftDetailsViewModel>(key); _mapper.Map <AircraftDetailsViewModel, ConfirmDetailsViewModel>(aircraft, model); // For the location, if we have a new location specified then use that as the // location. Otherwise, look up the location by its ID if (sighting.LocationId == 0) { model.Location = sighting.NewLocation; } else { Location location = await _locations.GetLocationAsync(sighting.LocationId); model.Location = location.Name; } // Repeat the above logic for the airline if (flight.AirlineId == 0) { model.Airline = flight.NewAirline; } else { Airline airline = await _airlines.GetAirlineAsync(flight.AirlineId); model.Airline = airline.Name; } // Repeat the above logic for the manufacturer if ((aircraft.ManufacturerId ?? 0) == 0) { model.Manufacturer = aircraft.NewManufacturer; } else { int manufacturerId = aircraft.ManufacturerId ?? 0; Manufacturer manufacturer = await _manufacturers.GetManufacturerAsync(manufacturerId); model.Manufacturer = manufacturer.Name; } // Repeat the above logic for the model if ((aircraft.ModelId ?? 0) == 0) { model.Model = aircraft.NewModel; } else { int modelId = aircraft.ModelId ?? 0; Model aircraftModel = await _models.GetModelAsync(modelId); model.Model = aircraftModel.Name; } return(model); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); _vm = new FlightDetailsViewModel(); DataContext = _vm; }
public IActionResult Details(int id) { FlightDetailsViewModel model = flightService.GetById <FlightDetailsViewModel>(id); return(View(model)); }
public async Task <IActionResult> Index() { FlightDetailsViewModel model = await _wizard.GetFlightDetailsModelAsync(User.Identity.Name); return(View(model)); }
public IActionResult Details(int id) { if (!this.User.IsAuthenticated) { return(RedirectToLogin()); } Flight flight; var isAdmin = false; using (this.Context) { flight = this.Context.Flights.Find(id); isAdmin = this.Context.Users.First(u => u.Name == this.User.Name).IsAdmin; } if (flight is null) { return(RedirectToHome()); } var model = new FlightDetailsViewModel { Id = flight.Id, Origin = flight.Origin, Date = flight.Date, Time = flight.Time, Tickets = flight.Tickets, Diration = flight.Destination, ImageUrl = flight.ImageUrl }; var editButton = isAdmin ? $@"<a href=""/flight/edit?id={model.Id}"" class=""edit-flight-detail""> <img src=""../Content/img/pencil.jpg"" style=""margin-top: 0px;"" alt=""image""></a>" : string.Empty; this.Model.Data["details"] = $@" <section class=""ticket-area""> <div class=""ticket-area-left""> <img src = ""{model.ImageUrl}"" alt=""image""> </div> <div class=""ticket-area-right""> <h3>{model.Diration}</h3> <div>from {model.Origin}</div> <div class=""data-and-time"">{model.Date} {model.Time} {editButton}</div> </div> </section>"; var createSeat = isAdmin ? $@"<section class=""seat - info""> <form action = ""/ticket/add?id={model.Id}"" class=""seat-form""> <input type = ""text"" id=""Price"" name=""Price"" placeholder=""Price""> <input type = ""text"" id=""Class"" name=""Class"" placeholder=""Type""> <input type = ""number"" id=""TicketCount"" name=""TicketCount"" name=""quantity"" min=""1"" max=""999"" placeholder=""Tickets Counter""> <input type = ""submit"" class=""create-seat"" value=""Create Seat""> </form> </section>" : string.Empty; var seats = new StringBuilder(); foreach (var modelTicket in model.Tickets) { seats.AppendLine($@"<form action="""" class=""seat - form""> <span>600$</span><span>Business</span> <input type=""text"" placeholder = ""Add Number"" > <input type=""submit"" class=""create-seat"" value=""Add to Cart"">"); if (isAdmin) { seats.AppendLine($@"<a href = ""/ticket/delete?id={modelTicket.Id}"" class=""delete"">X</a>"); } seats.Append("</form>"); } this.Model.Data["createSeat"] = createSeat; this.Model.Data["seats"] = seats.ToString(); return(this.View()); }