49 lines
1.4 KiB
C#
Raw Normal View History

2024-11-27 00:03:35 +04:00
using System.Collections.Generic;
using System.Linq;
using YourNamespace.Entities;
using YourNamespace.Repositories;
namespace YourNamespace.Repositories.Implementations
{
public class PlaneRepository : IPlaneRepository
{
private readonly List<Plane> _planes = new List<Plane>();
private int _nextId = 1;
public IEnumerable<Plane> ReadPlanes()
{
return _planes;
}
public Plane ReadPlaneById(int id)
{
return _planes.FirstOrDefault(p => p.Id == id);
}
public void CreatePlane(Plane plane)
{
var newPlane = Plane.CreateEntity(_nextId++, plane.Model, plane.Capacity);
_planes.Add(newPlane);
}
public void UpdatePlane(Plane plane)
{
var existingPlane = _planes.FirstOrDefault(p => p.Id == plane.Id);
if (existingPlane != null)
{
var updatedPlane = Plane.CreateEntity(existingPlane.Id, plane.Model, plane.Capacity);
_planes.Remove(existingPlane);
_planes.Add(updatedPlane);
}
}
public void DeletePlane(int id)
{
var planeToRemove = _planes.FirstOrDefault(p => p.Id == id);
if (planeToRemove != null)
{
_planes.Remove(planeToRemove);
}
}
}
}