// GET: FlightController/Edit/5 public ActionResult Edit([FromRoute] int id) { ViewBag.IsLoggedIn = true; List <Pilot> pilotsAll = uow.Pilot.GetAll(); List <SelectListItem> pilots = new List <SelectListItem>(); foreach (Pilot pilot in pilotsAll) { pilots.Add(new SelectListItem { Text = pilot.FirstName + " " + pilot.LastName, Value = pilot.PilotID.ToString() }); } Flight flight = uow.Flight.FindById(id); AddFlightViewModel model = new AddFlightViewModel { Date = flight.Date, DurationInMinutes = flight.DurationInMinutes, StartDestination = flight.StartDestination, EndDestination = flight.EndDestination, Price = flight.Price, Pilots = pilots }; return(View(model)); }
public ActionResult Edit([FromForm] AddFlightViewModel model, [FromRoute(Name = "id")] int id) { ViewBag.IsLoggedIn = true; if (ModelState.IsValid) { Flight f = new Flight { FlightID = id, Date = model.Date, DurationInMinutes = model.DurationInMinutes, StartDestination = model.StartDestination, EndDestination = model.EndDestination, Price = model.Price, PilotID = model.PilotID }; uow.Flight.Change(f); uow.Commit(); return(RedirectToAction(nameof(Index))); } else { return(Edit(id)); } }
public async Task <IActionResult> Add() { AddFlightViewModel model = new AddFlightViewModel(); List <Airline> airlines = await _airlines.GetAirlinesAsync(); model.SetAirlines(airlines); return(View(model)); }
public IActionResult Create() { byte[] empIdBytes = new byte[200]; if (HttpContext.Session.TryGetValue("empId", out empIdBytes)) { int employeeId = int.Parse(Encoding.UTF8.GetString(empIdBytes)); if (employeeId == 1) { List <Employee> employees = (from emp in _context.Employees where emp.Id == employeeId select emp).ToList(); Employee employee = employees[0]; ViewData["username"] = employee.Username; ViewData["isLoggedIn"] = true; ViewData["isAdmin"] = true; AddFlightViewModel model = new AddFlightViewModel(); List <Plane> planes = (from p in _context.Planes select p).ToList(); ViewData["allPlanes"] = planes; return(View(model)); } else if (employeeId != 1 && employeeId > 0) { List <Employee> employees = (from emp in _context.Employees where emp.Id == employeeId select emp).ToList(); Employee employee = employees[0]; ViewData["username"] = employee.Username; ViewData["isLoggedIn"] = true; ViewData["isAdmin"] = false; return(RedirectToAction(nameof(Index))); } else { ViewData["isLoggedIn"] = false; ViewData["isAdmin"] = false; return(RedirectToAction(nameof(Index))); } } else { ViewData["isLoggedIn"] = false; ViewData["isAdmin"] = false; return(RedirectToAction(nameof(Index))); } }
public ViewResult FlightsManagement(Flight?flight) { var flights = _context.Flights .Include(a => a.ArrivalAirport) .Include(b => b.DepartureAirport) .Include(b => b.Plane); var viewModel = new AddFlightViewModel() { Flights = flights.ToList() }; return(View(flights)); }
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)); }
public async Task <IActionResult> Add(AddFlightViewModel model) { if (ModelState.IsValid) { string number = model.FlightNumber; await _flights.AddFlightAsync(number, model.Embarkation, model.Destination, model.AirlineId); ModelState.Clear(); model.Clear(); model.Message = $"Flight '{number}' added successfully"; } List <Airline> airlines = await _airlines.GetAirlinesAsync(); model.SetAirlines(airlines); return(View(model)); }
public async Task <IActionResult> Create(AddFlightViewModel model) { if (model.DepartureAirportId == model.DestinationAirportId) { ModelState.AddModelError(string.Empty, DefaultMessages.SameAirportErrorMessage); var viewModel = await GetAddFlightViewModel(); return(View(viewModel)); } var createFlightCommand = new FlightCreate.Command( model.DepartureAirportId, model.DestinationAirportId); await _mediator.Send(createFlightCommand); TempData[nameof(DefaultMessages.FlightCreatedMessage)] = DefaultMessages.FlightCreatedMessage; return(RedirectToAction(nameof(Index))); }
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); }
public async Task CreatePost_SameAirports_ReturnsError() { // Arrange var airportId = Guid.NewGuid(); var viewModel = new AddFlightViewModel { DepartureAirportId = airportId, DestinationAirportId = airportId }; var expectedAirports = _fixture.CreateMany <Airport>().ToList(); _mediatorMock .Setup(x => x.Send( It.IsAny <AirportAll.Query>(), It.IsAny <CancellationToken>())) .ReturnsAsync(expectedAirports); var target = new FlightsController(_mediatorMock.Object); // Act var result = await target.Create(viewModel); // Assert var viewResult = result .Should() .BeOfType <ViewResult>().Subject; var model = viewResult.ViewData.Model .Should() .BeOfType <AddFlightViewModel>().Subject; model.Airports .Should() .HaveCount(expectedAirports.Count); target.ModelState.IsValid.Should().BeFalse(); }
// GET: FlightController/Create public ActionResult Create() { ViewBag.IsLoggedIn = true; List <Pilot> pilotsAll = uow.Pilot.GetAll(); List <SelectListItem> p = new List <SelectListItem>(); foreach (Pilot pilot in pilotsAll) { p.Add(new SelectListItem { Text = pilot.FirstName + " " + pilot.LastName, Value = pilot.PilotID.ToString() } ); } AddFlightViewModel model = new AddFlightViewModel { Pilots = p }; return(View(model)); }
public ActionResult AddFlight() { var countries = this.countryServices.GetAllCountries() .Select(c => new SelectListItem() { Text = c.Name, Value = c.Id.ToString() }) .ToList(); var airlines = this.airlineService.GetAllAirlines() .Select(a => new SelectListItem() { Text = a.Name, Value = a.Id.ToString() }) .ToList(); var viewModel = new AddFlightViewModel() { Countries = countries, Airlines = airlines }; return(PartialView("_AddFlight", viewModel)); }
public ActionResult Create([FromForm] AddFlightViewModel model) { ViewBag.IsLoggedIn = true; if (ModelState.IsValid) { Flight f = new Flight { Date = model.Date, DurationInMinutes = model.DurationInMinutes, StartDestination = model.StartDestination, EndDestination = model.EndDestination, Price = model.Price, PilotID = model.PilotID }; uow.Flight.Add(f); uow.Commit(); return(RedirectToAction(nameof(Index))); } else { return(Create()); } }
public async Task <IActionResult> Create(AddFlightViewModel model) { byte[] empIdBytes = new byte[200]; if (HttpContext.Session.TryGetValue("empId", out empIdBytes)) { int employeeId = int.Parse(Encoding.UTF8.GetString(empIdBytes)); if (employeeId == 1) { List <Employee> employees = (from emp in _context.Employees where emp.Id == employeeId select emp).ToList(); Employee employee = employees[0]; ViewData["username"] = employee.Username; ViewData["isLoggedIn"] = true; ViewData["isAdmin"] = true; if (ModelState.IsValid) { int id = _context.Flights.Max(f => f.Id); Flight flight = new Flight { Id = id + 1, LocationFromId = model.LocationFromId, LocationToId = model.LocationToId, TakeOffDateTime = model.TakeOffDateTime, LandingDateTime = model.LandingDateTime, PlaneId = model.PlaneId }; _context.Flights.Add(flight); await _context.SaveChangesAsync(); passagerNames.Add(new Tuple <int, List <string> >(flight.Id, new List <string>())); return(RedirectToAction(nameof(Index))); } return(View(model)); } else if (employeeId != 1 && employeeId > 0) { List <Employee> employees = (from emp in _context.Employees where emp.Id == employeeId select emp).ToList(); Employee employee = employees[0]; ViewData["username"] = employee.Username; ViewData["isLoggedIn"] = true; ViewData["isAdmin"] = false; return(RedirectToAction(nameof(Index))); } else { ViewData["isLoggedIn"] = false; ViewData["isAdmin"] = false; return(RedirectToAction(nameof(Index))); } } else { ViewData["isLoggedIn"] = false; ViewData["isAdmin"] = false; return(RedirectToAction(nameof(Index))); } }
public AddFlight() { InitializeComponent(); DataContext = new AddFlightViewModel(); }