ProjectLib/ProjectLibrary/Repositores/Implementations/BookLibraryRepository.cs

50 lines
2.1 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 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);
}
}
}
}