public FlightEntity InsertFlightEntity(FlightEntity flight) { FlightEntity plane = context.Flights.Add(flight); context.SaveChanges(); return(plane); }
public async Task <ResultTypes> UpdateAsync(Flight newFlight) { FlightEntity flightDal = _mapper.Map <FlightEntity>(newFlight); AirportEntity toAirport = await _airportRepository.GetByIdAsync(flightDal.ToAirportId); AirportEntity fromAirport = await _airportRepository.GetByIdAsync(flightDal.FromAirportId); if (toAirport == null || fromAirport == null) { return(ResultTypes.NotFound); } AirplaneEntity airplane = await _airplaneRepository.GetByIdAsync(flightDal.AirplaneId); if (airplane == null) { return(ResultTypes.NotFound); } if (newFlight.ArrivalTime <= newFlight.DepartureTime) { return(ResultTypes.InvalidData); } await _flightRepository.UpdateAsync(flightDal); return(ResultTypes.Ok); }
public void Reorganize(DateTime now) { context.Passsengers.ToList().ForEach(p => { bool AlreadyObBoard = false; p.Tickets.ToList().ForEach(t => { FlightEntity flight = t.Flight; if (flight.TimeDeparture < now && now < flight.TimeArrival) { p.PlaneId = flight.PlaneId; AlreadyObBoard = true; } else if (AlreadyObBoard == false) { p.PlaneId = null; } else { } }); }); context.SaveChanges(); }
public ReservationApiDbContext InitializeDatabase(string databaseName) { var options = new DbContextOptionsBuilder <ReservationApiDbContext>().UseInMemoryDatabase(databaseName).Options; var context = new ReservationApiDbContext(options); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); IEnumerable <FlightRequest> results; //TODO - Read the seed data fileName from the Settings files -> appsettings.json using (StreamReader r = new StreamReader(@".\..\..\..\..\..\InitialState.json")) { string json = r.ReadToEnd(); results = JsonConvert.DeserializeObject <IEnumerable <FlightRequest> >(json); foreach (var item in results) { FlightEntity flight = new FlightEntity { FlightKey = item.key, Origin = item.origin, Destination = item.destination, Time = item.time, }; context.Flights.Add(flight); } } context.SaveChanges(); return(context); }
public async Task <AddResult> AddAsync(Flight flight) { FlightEntity flightDal = _mapper.Map <FlightEntity>(flight); AirportEntity toAirport = await _airportRepository.GetByIdAsync(flightDal.ToAirportId); AirportEntity fromAirport = await _airportRepository.GetByIdAsync(flightDal.FromAirportId); if (toAirport == null || fromAirport == null) { return(new AddResult(ResultTypes.NotFound, null)); } AirplaneEntity airplane = await _airplaneRepository.GetByIdAsync(flightDal.AirplaneId); if (airplane == null) { return(new AddResult(ResultTypes.NotFound, null)); } if (flight.ArrivalTime <= flight.DepartureTime) { return(new AddResult(ResultTypes.InvalidData, null)); } int addedFlightId = await _flightRepository.AddAsync(flightDal); return(new AddResult(ResultTypes.Ok, addedFlightId)); }
public async Task <ResultTypes> AddFlightSeatTypeCostAsync(FlightSeatTypeCost seatTypeCost) { FlightSeatTypeCostEntity seatTypeCostDal = _mapper.Map <FlightSeatTypeCostEntity>(seatTypeCost); FlightEntity flight = await _flightRepository.GetByIdAsync(seatTypeCostDal.FlightId); if (flight == null) { return(ResultTypes.NotFound); } AirplaneSeatTypeEntity seatType = await _airplaneRepository.GetSeatTypeById(seatTypeCostDal.SeatTypeId); if (seatType == null) { return(ResultTypes.NotFound); } bool duplicate = await _flightRepository.CheckFlightSeatTypeCostDuplicateAsync(seatTypeCostDal); if (duplicate) { return(ResultTypes.Duplicate); } await _flightRepository.AddFlightSeatTypeCostAsync(seatTypeCostDal); return(ResultTypes.Ok); }
public async Task <Flight> GetByIdAsync(int id) { FlightEntity flightDal = await _flightRepository.GetByIdAsync(id); Flight flight = _mapper.Map <Flight>(flightDal); return(flight); }
protected void btnInsert_Click(object sender, EventArgs e) { string txtFlightName = Convert.ToString((idFlightView1.FooterRow.FindControl("txtInsertFlightName") as TextBox).Text); string txtFlightNumber = Convert.ToString((idFlightView1.FooterRow.FindControl("txtInsertFlightNumber") as TextBox).Text); FlightEntity flightEntity = new FlightEntity(txtFlightName, txtFlightNumber); FlightBL.InsertFlight(flightEntity); FillData(); }
public FlightEntity SaveFlightEntity(FlightEntity flight) { using (var context = new TUIAssessmentDALContext(_options)) { context.Flights.Add(flight); context.SaveChanges(); } return(flight); }
public void DeleteFlightEntity(int id) { FlightEntity pass = new FlightEntity() { PlaneId = id }; context.Flights.Attach(pass); context.Flights.Remove(pass); context.SaveChanges(); }
public FlightEntity GetFlightEntityByID(int Id) { FlightEntity flight = null; using (var context = new TUIAssessmentDALContext(_options)) { flight = context.Flights.Single(f => f.Id == Id); } return(flight); }
private void button3_Click(object sender, EventArgs e) { FlightEntity oldflight = flightEntities.Where(w => w.Id == Int32.Parse(label8.Text)).FirstOrDefault(); flightEntities.Remove(oldflight); MessageBox.Show("Deleted"); Form1 f = new Form1(); f.Show(); this.Hide(); }
public FlightAirportDto toDto(FlightEntity flight) { FlightAirportDto flightDto = new FlightAirportDto(); flightDto.FlightId = flight.FlightId; flightDto.TimeDeparture = flight.TimeDeparture; flightDto.TimeArrival = flight.TimeArrival; flightDto.AimArrivalCity = flight.AirportArrival.City; flightDto.AimDepartureCity = flight.AirportDeparture.City; flightDto.PlaneId = flight.PlaneId; return(flightDto); }
public FlightEntity toEntity(FlightDto flightDto) { FlightEntity flight = new FlightEntity(); flight.FlightId = flightDto.FlightId; flight.TimeDeparture = flightDto.TimeDeparture; flight.TimeArrival = flightDto.TimeArrival; flight.AimArrivalId = flightDto.AimArrivalId; flight.AimDepartureId = flightDto.AimDepartureId; flight.PlaneId = flightDto.PlaneId; return(flight); }
private void button1_Click(object sender, EventArgs e) { FlightEntity flightEntity = new FlightEntity { Id = ++Bid, FlightName = textBox1.Text, TakeOffTime = dateTimePicker1.Value }; flightEntities.Add(flightEntity); MessageBox.Show("Flight Added"); Form1 f = new Form1(); f.Show(); this.Hide(); }
private void button2_Click(object sender, EventArgs e) { FlightEntity oldflight = flightEntities.Where(w => w.Id == Int32.Parse(label8.Text)).FirstOrDefault(); oldflight.FlightName = textBox4.Text; oldflight.TakeOffTime = dateTimePicker2.Value; MessageBox.Show("Flight Updated"); Form1 f = new Form1(); f.Show(); this.Hide(); this.Hide(); }
public static IWebHost LoadSampleData(this IWebHost webHost) { using (var scope = webHost.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <FlightsDBContext>(); context.Flights.AddRange(FlightEntity.GenerateTestData()); context.Bookings.AddRange(BookingEntity.GenerateTestData()); context.SaveChanges(); } return(webHost); }
public async Task <AddResult> BookForTimeAsync(FlightBookInfo bookInfo) { FlightEntity flight = await _flightRepository.GetByIdAsync(bookInfo.FlightId); if (flight == null) { return(new AddResult(ResultTypes.NotFound, null)); } for (int seatBookIndex = 0; seatBookIndex < bookInfo.SeatBooks.Length; seatBookIndex++) { SeatBook seatBook = bookInfo.SeatBooks[seatBookIndex]; AirplaneSeatEntity seat = await _airplaneRepository.GetSeatById(seatBook.SeatId); if (seat == null) { return(new AddResult(ResultTypes.NotFound, null)); } bool canBook = await _flightRepository.CheckSeatBookAvailabilityAsync( bookInfo.FlightId, seatBook.SeatId ); if (!canBook) { return(new AddResult(ResultTypes.Duplicate, null)); } } bookInfo.BookType = BookType.AwaitingPayment; bookInfo.BookTime = DateTimeOffset.Now; bookInfo.AccountId = _accountId; FlightBookInfoEntity bookInfoDal = _mapper.Map <FlightBookInfoEntity>(bookInfo); int accountFlightInfoId = await _flightRepository.AddAccountFlightInfoAsync(bookInfoDal); foreach (SeatBook seatBook in bookInfo.SeatBooks) { seatBook.FlightBookInfoId = accountFlightInfoId; SeatBookEntity seatBookDal = _mapper.Map <SeatBookEntity>(seatBook); await _flightRepository.BookSeatAsync(seatBookDal); } return(new AddResult(ResultTypes.Ok, accountFlightInfoId));; }
public async Task GetFlightsAsync_WhenHasData() { // Create test data before the call var flights = FlightEntity.GenerateTestData(); _context.Flights.AddRange(flights); _context.SaveChanges(); // Make the call DefaultFlightService service = new DefaultFlightService(_context); var result = await service.GetFlightsAsync(CancellationToken.None); // Validate the result Assert.NotNull(result); Assert.Equal(flights.Length, Enumerable.Count <Flight>(result)); }
private FlightModel SetFlightFromFlightEntity(FlightEntity flightEntity) { var flight = new FlightModel { ID = flightEntity.Id, Distance = flightEntity.Distance, Carburant = flightEntity.FuelQuantity, Duration = flightEntity.TimeOfFlight, Creation = flightEntity.Creation, Update = flightEntity.Update }; flight.DepartureAirport = _airportBusiness.GetAirportById(flightEntity.DepartureAirportId); flight.ArrivalAirport = _airportBusiness.GetAirportById(flightEntity.ArrivalAirportId); return(flight); }
public IEnumerable <PlaneEntity> AvailablePlanes(int DepartureId, int ArrivalId, DateTime departure, DateTime arrival) { return(context.Planes.ToList().Where(p => { bool Available = true; p.Flights.ToList().ForEach(f => { if (arrival < f.TimeDeparture) //&& departure < f.TimeArrival) { } else if (departure > f.TimeArrival) //&& departure > f.TimeDeparture ) { } else { Available = false; } if (p.AirportId != DepartureId) { Available = false; } }); //test addition for (int i = 1; i < p.Flights.Count; i++) { FlightEntity prev = (FlightEntity)p.Flights.ElementAt(i - 1); FlightEntity current = (FlightEntity)p.Flights.ElementAt(i); if (prev.TimeArrival < departure && current.TimeDeparture > arrival) { if (prev.AimArrivalId != DepartureId || ArrivalId != current.AimDepartureId) { Available = false; } } } //test addition ends return Available; })); }
/// <summary> /// InitializeDatabase /// </summary> /// <param name="context">App's host context (including environment and configuration)</param> /// <param name="loggingBuilder">The ILoggingBuilde to add providers to</param> public static void InitializeDatabase(IWebHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { using (var context = services.GetRequiredService <ReservationApiDbContext>()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); IEnumerable <FlightRequest> results; var configurationService = services.GetService <IConfiguration>(); var seedDataFile = configurationService["Settings:SeedDataFile"]; using (StreamReader r = new StreamReader(seedDataFile)) { string json = r.ReadToEnd(); results = JsonConvert.DeserializeObject <IEnumerable <FlightRequest> >(json); foreach (var item in results) { FlightEntity flight = new FlightEntity { FlightKey = item.key, Origin = item.origin, Destination = item.destination, Time = item.time, }; context.Flights.Add(flight); } } context.SaveChanges(); } } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the database."); } } }
public FlightEntity UpdateFlightEntity(FlightEntity flight) { using (var context = new TUIAssessmentDALContext(_options)) { var flightInDB = context.Flights.Single(f => f.Id == flight.Id); if (flightInDB != null) { flightInDB.ArrivalAirportId = flight.ArrivalAirportId; flightInDB.DepartureAirportId = flight.DepartureAirportId; flightInDB.Distance = flight.Distance; flightInDB.FuelQuantity = flight.FuelQuantity; flightInDB.TimeOfFlight = flight.TimeOfFlight; flightInDB.Update = DateTime.Now; } context.SaveChanges(); } return(GetFlightEntityByID(flight.Id)); }
public DefaultAvailabilityServiceTests() { // Configure an instance of the FlightsDBContext and 'in memory' database. // NOTE : Ensure that the name passed to UseInMemoryDatabase is unique to this test class! var optionsBuilder = new DbContextOptionsBuilder <FlightsDBContext>(); optionsBuilder.UseInMemoryDatabase("DefaultAvailabilityServiceTests"); _context = new FlightsDBContext(optionsBuilder.Options); // Create test data before any calls var flights = FlightEntity.GenerateTestData(); _context.Flights.AddRange(flights); var bookings = BookingEntity.GenerateTestData(); _context.Bookings.AddRange(bookings); _context.SaveChanges(); // Call the helper class to initialise AutoMapper since it handles multithreading. AutoMapperHelper.Initialize(); }
public async Task <int> AddAsync(FlightEntity flight) { using SqlConnection db = new SqlConnection(_dalSettings.ConnectionString); return(await db.QuerySingleOrDefaultAsync <int>( "AddFlight", new { FromAirportId = flight.FromAirportId, ToAirportId = flight.ToAirportId, DepartureTime = flight.DepartureTime, ArrivalTime = flight.ArrivalTime, AirplaneId = flight.AirplaneId, SuitcaseMassKg = flight.SuitcaseMassKg, SuitcaseCount = flight.SuitcaseCount, HandLuggageMassKg = flight.HandLuggageMassKg, HandLuggageCount = flight.HandLuggageCount, MassOverloadKgCost = flight.MassOverloadKgCost }, commandType : CommandType.StoredProcedure)); }
public async Task UpdateAsync(FlightEntity newFlight) { using SqlConnection db = new SqlConnection(_dalSettings.ConnectionString); await db.ExecuteAsync( "UpdateFlight", new { FlightId = newFlight.Id, FromAirportId = newFlight.FromAirportId, ToAirportId = newFlight.ToAirportId, DepartureTime = newFlight.DepartureTime, ArrivalTime = newFlight.ArrivalTime, AirplaneId = newFlight.AirplaneId, SuitcaseMassKg = newFlight.SuitcaseMassKg, SuitcaseCount = newFlight.SuitcaseCount, HandLuggageMassKg = newFlight.HandLuggageMassKg, HandLuggageCount = newFlight.HandLuggageCount, MassOverloadKgCost = newFlight.MassOverloadKgCost }, commandType : CommandType.StoredProcedure); }
public async Task <ResultTypes> UpdateFlightSeatTypeCostAsync(FlightSeatTypeCost newSeatTypeCost) { FlightSeatTypeCostEntity seatTypeCostDal = _mapper.Map <FlightSeatTypeCostEntity>(newSeatTypeCost); FlightEntity flight = await _flightRepository.GetByIdAsync(seatTypeCostDal.FlightId); if (flight == null) { return(ResultTypes.NotFound); } AirplaneSeatTypeEntity seatType = await _airplaneRepository.GetSeatTypeById(seatTypeCostDal.SeatTypeId); if (seatType == null) { return(ResultTypes.NotFound); } await _flightRepository.UpdateFlightSeatTypeCostAsync(seatTypeCostDal); return(ResultTypes.Ok); }
public static void InsertFlight(FlightEntity flight) { using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { try { sqlConnection.Open(); SqlCommand sqlCommand = new SqlCommand("SP_FLIGHT_ADD", sqlConnection); sqlCommand.CommandType = CommandType.StoredProcedure; SqlParameter param = new SqlParameter("@FLIGHTNAME", flight.FlightName); sqlCommand.Parameters.Add(param); param = new SqlParameter("@FLIGHTNUMBER", flight.FlightNumber); sqlCommand.Parameters.Add(param); sqlCommand.ExecuteNonQuery(); } catch (Exception) { } finally { sqlConnection.Close(); } } }
public static Flight ToModel(this FlightEntity model) => Mapper.Map <Flight>(model);
public FlightRepository() { flightEntity = new FlightEntity(); }