48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|