49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using YourNamespace.Entities;
|
|
using YourNamespace.Repositories;
|
|
|
|
namespace YourNamespace.Repositories.Implementations
|
|
{
|
|
public class FlightRepository : IFlightRepository
|
|
{
|
|
private readonly List<Flight> _flights = new List<Flight>();
|
|
private int _nextId = 1;
|
|
|
|
public IEnumerable<Flight> ReadFlights()
|
|
{
|
|
return _flights;
|
|
}
|
|
|
|
public Flight ReadFlightById(int id)
|
|
{
|
|
return _flights.FirstOrDefault(f => f.Id == id);
|
|
}
|
|
|
|
public void CreateFlight(Flight flight)
|
|
{
|
|
var newFlight = Flight.CreateEntity(_nextId++, flight.FlightNumber, flight.DepartureDateTime, flight.ArrivalDateTime, flight.PlaneId, flight.AirportId);
|
|
_flights.Add(newFlight);
|
|
}
|
|
|
|
public void UpdateFlight(Flight flight)
|
|
{
|
|
var existingFlight = _flights.FirstOrDefault(f => f.Id == flight.Id);
|
|
if (existingFlight != null)
|
|
{
|
|
var updatedFlight = Flight.CreateEntity(existingFlight.Id, flight.FlightNumber, flight.DepartureDateTime, flight.ArrivalDateTime, flight.PlaneId, flight.AirportId);
|
|
_flights.Remove(existingFlight);
|
|
_flights.Add(updatedFlight);
|
|
}
|
|
}
|
|
|
|
public void DeleteFlight(int id)
|
|
{
|
|
var flightToRemove = _flights.FirstOrDefault(f => f.Id == id);
|
|
if (flightToRemove != null)
|
|
{
|
|
_flights.Remove(flightToRemove);
|
|
}
|
|
}
|
|
}
|
|
} |