public void Command_Should_Add_New_Flight_To_Repository() { //Given var model = new CreateFlightModel { DestinationAirportId = 1, DepartureAirportId = 1, AircraftId = 1 }; //When _command.Execute(model); //Then _repositories.Verify(x => x.AddFlight(It.IsAny <Flight>()), Times.Once); }
public void Command_Should_Persist_Changes() { //Given var model = new CreateFlightModel { DestinationAirportId = 1, DepartureAirportId = 1, AircraftId = 1 }; //When _command.Execute(model); //Then _uow.Verify(x => x.Save(), Times.Once); }
public long CreateFlight(CreateFlightModel model) { using var dbContext = new LocalDatabaseContext(); var copilot = model.CopilotId != null ? dbContext.Persons.Find(model.CopilotId) : null; var flight = new Flight { Airplane = dbContext.Airplanes.Find(model.AirplaneId), Copilot = copilot, Pilot = dbContext.Persons.Find(model.PilotId), TakeoffTime = model.TakeOffTime, Task = model.Task }; dbContext.Flights.Add(flight); dbContext.SaveChanges(); return(flight.Id); }
public IActionResult CreateFlight(CreateFlightModel model) { if (!IsValidModel(model) || !IsAdmin) { this.ShowError("Function only for Admins!"); return(RedirectToHome()); } var success = this.flights.Create (model.Destination, model.Origin, model.Date, model.ImageUrl); if (!success) { this.ShowError("Not valid Flight data!"); return(this.View()); } this.ShowSuccess("Flight added successfully!"); return(this.RedirectToHome()); }