50 lines
2.1 KiB
C#
50 lines
2.1 KiB
C#
using ProjectLibrary.Entites;
|
||
using ProjectLibrary.Entities;
|
||
using ProjectLibrary.Repositories;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
|
||
namespace ProjectLibrary.Repositories.Implementations
|
||
{
|
||
public class BookLibraryRepository : IBookLibraryRepository
|
||
{
|
||
// Эмулируем базу данных в виде списка
|
||
private readonly List<BookLibrary> _bookLibraries = new List<BookLibrary>();
|
||
|
||
public void CreateBookLibrary(BookLibrary bookLibrary)
|
||
{
|
||
// Логика для добавления связи книги и библиотеки
|
||
_bookLibraries.Add(bookLibrary);
|
||
}
|
||
|
||
public void DeleteBookLibrary(int bookId, int libraryId)
|
||
{
|
||
// Логика для удаления связи книги и библиотеки по идентификаторам
|
||
var bookLibrary = _bookLibraries.FirstOrDefault(bl => bl.BookID == bookId && bl.LibraryID == libraryId);
|
||
if (bookLibrary != null)
|
||
{
|
||
_bookLibraries.Remove(bookLibrary);
|
||
}
|
||
}
|
||
|
||
public IEnumerable<BookLibrary> ReadBookLibraries(int? bookId = null, int? libraryId = null)
|
||
{
|
||
// Логика для получения всех связей книг и библиотек с возможностью фильтрации по bookId и libraryId
|
||
return _bookLibraries.Where(bl =>
|
||
(!bookId.HasValue || bl.BookID == bookId) &&
|
||
(!libraryId.HasValue || bl.LibraryID == libraryId));
|
||
}
|
||
|
||
public void UpdateBookLibrary(BookLibrary bookLibrary)
|
||
{
|
||
// Логика для обновления информации о связи книги и библиотеки
|
||
var existingBookLibrary = _bookLibraries.FirstOrDefault(bl => bl.BookID == bookLibrary.BookID && bl.LibraryID == bookLibrary.LibraryID);
|
||
if (existingBookLibrary != null)
|
||
{
|
||
_bookLibraries.Remove(existingBookLibrary);
|
||
_bookLibraries.Add(bookLibrary);
|
||
}
|
||
}
|
||
}
|
||
}
|