ProjectLib/ProjectLibrary/Repositores/Implementations/OrderRepository.cs

48 lines
1.2 KiB
C#
Raw Normal View History

2024-11-12 23:13:20 +04:00
using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
using ProjectLibrary.Repositories;
using System.Collections.Generic;
using System.Linq;
namespace ProjectLibrary.Repositories.Implementations
{
public class OrderRepository : IOrderRepository
{
private readonly List<Orders> _orders = new List<Orders>();
public void CreateOrder(Orders order)
{
_orders.Add(order);
}
public void DeleteOrder(int id)
{
var order = _orders.FirstOrDefault(o => o.Id == id);
if (order != null)
{
_orders.Remove(order);
}
}
public Orders ReadOrderById(int id)
{
return _orders.FirstOrDefault(o => o.Id == id) ?? Orders.CreateEntity(id, 0, 0, 0);
}
public IEnumerable<Orders> ReadOrders()
{
return _orders;
}
public void UpdateOrder(Orders order)
{
var existingOrder = _orders.FirstOrDefault(o => o.Id == order.Id);
if (existingOrder != null)
{
_orders.Remove(existingOrder);
_orders.Add(order);
}
}
}
}