ProjectLib/ProjectLibrary/Repositores/Implementations/BookOrdersRepository.cs

39 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using ProjectLibrary.Entites;
using ProjectLibrary.Entities;
using ProjectLibrary.Repositories;
using System.Collections.Generic;
using System.Linq;
namespace ProjectLibrary.Repositories.Implementations
{
public class BookOrdersRepository : IBookOrdersRepository
{
// Эмулируем базу данных в виде списка
private readonly List<BookOrders> _bookOrders = new List<BookOrders>();
public void CreateBookOrder(BookOrders bookOrder)
{
// Логика для добавления связи книги и заказа
_bookOrders.Add(bookOrder);
}
public void DeleteBookOrder(int bookId, int orderId)
{
// Логика для удаления связи книги и заказа по идентификаторам
var bookOrder = _bookOrders.FirstOrDefault(bo => bo.BookID == bookId && bo.OrderID == orderId);
if (bookOrder != null)
{
_bookOrders.Remove(bookOrder);
}
}
public IEnumerable<BookOrders> ReadBookOrders(int? bookId = null, int? orderId = null)
{
// Логика для получения всех связей книг и заказов с возможностью фильтрации по bookId и orderId
return _bookOrders.Where(bo =>
(!bookId.HasValue || bo.BookID == bookId) &&
(!orderId.HasValue || bo.OrderID == orderId));
}
}
}