public ViewResult Save(Flight FlightMV) { if (!ModelState.IsValid) { var NewFlightMV = new NewFlightViewModel() { AircraftId = FlightMV.AircraftId, AirportDepartId = FlightMV.AirportDepartId, AirportDestinationId = FlightMV.AirportDestinationId, Distance = FlightMV.Distance, FuelNeeded = FlightMV.FuelNeeded, Aircrafts = _aircraftRepository.Aircrafts.OrderBy(a => a.AircraftId), Airport = _airportRepository.Airports.OrderBy(a => a.Name) }; return(View("FlightForm", NewFlightMV)); } if (FlightMV.FlightId == 0) { _flightRepository.AddFlight(FlightMV); } else { _flightRepository.UpdateFlight(FlightMV); } var mv = new FlightsViewModel() { Flights = _flightRepository.Flights.OrderBy(f => f.FlightId) }; return(View("Index", mv)); }
/// <summary> /// /// </summary> /// <returns></returns> public ViewResult New() { var mv = new NewFlightViewModel() { Aircrafts = _aircraftRepository.Aircrafts.OrderBy(a => a.AircraftId), Airport = _airportRepository.Airports.OrderBy(a => a.Name) }; return(View("FlightForm", mv)); }
/// <summary> /// /// </summary> /// <param name="Id"></param> /// <returns></returns> public ViewResult Edit(int Id) { var FlightMV = _flightRepository.GetFlight(Id); var mv = new NewFlightViewModel() { AircraftId = FlightMV.AircraftId, AirportDepartId = FlightMV.AirportDepartId, AirportDestinationId = FlightMV.AirportDestinationId, Distance = FlightMV.Distance, FuelNeeded = FlightMV.FuelNeeded, Aircrafts = _aircraftRepository.Aircrafts.OrderBy(a => a.AircraftId), Airport = _airportRepository.Airports.OrderBy(a => a.Name) }; return(View("FlightForm", mv)); }
public ActionResult NewFlight(NewFlightViewModel _flight) { if (ModelState.IsValid) { if (_flight.Arraival > DateTime.Now && _flight.Departure > DateTime.Now && _flight.Arraival >= _flight.Departure && _flight.Price > 0 && _flight.Total > 0 && _flight.Total < 100) { Flight flight = new Flight { Departure = _flight.Departure, Arrival = _flight.Arraival, FromCountry = _flight.FromCountry, FromCity = _flight.FromCity, ToCountry = _flight.ToCountry, ToCity = _flight.ToCity, Price = _flight.Price, TotalNumberPassengers = _flight.Total }; flightMethods.Create(flight); logger.Info($"Created fligth: Departure: {flight.Departure}, Arrival: {flight.Arrival}, FCity: {flight.FromCity}," + $"FCountry: {flight.FromCountry}, TCity: {flight.ToCity}, TCountry: {flight.ToCountry}, By: {HttpContext.User.Identity.Name}"); return(RedirectToAction("AllFlights", "Admin")); } else { ModelState.AddModelError("", "Check inptu data. Date must in future. Max passanger must be less then 100"); ModelState.IsValidField(""); return(View(_flight)); } } else { ModelState.AddModelError("", "Fill in all gaps, Date must be in future"); } return(View(_flight)); }