using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Model { public class Manager { private ILibraryManager LibraryManager { get; set; } private IUserLibraryManager UserLibraryManager { get; set; } public ReadOnlyCollection Books { get; private set; } private List books = new(); public Manager(ILibraryManager libMgr, IUserLibraryManager userLibMgr) { LibraryManager = libMgr; UserLibraryManager = userLibMgr; Books = new ReadOnlyCollection(books); } public async Task GetBookById(string id) => await LibraryManager.GetBookById(id); public async Task GetBookByISBN(string isbn) => await LibraryManager.GetBookByISBN(isbn); public async Task<(long count, IEnumerable books)> GetBooksByTitle(string title, int index, int count, string sort = "") { var result = await LibraryManager.GetBooksByTitle(title, index, count, sort); return (result.Item1, result.Item2); } public async Task<(long count, IEnumerable books)> GetBooksByAuthorId(string authorId, int index, int count, string sort = "") { var result = await LibraryManager.GetBooksByAuthorId(authorId, index, count, sort); return (result.Item1, result.Item2); } public async Task<(long count, IEnumerable books)> GetBooksByAuthor(string author, int index, int count, string sort = "") { var result = await LibraryManager.GetBooksByAuthor(author, index, count, sort); return (result.Item1, result.Item2); } public async Task GetAuthorById(string id) => await LibraryManager.GetAuthorById(id); public async Task<(long count, IEnumerable authors)> GetAuthorsByName(string substring, int index, int count, string sort = "") { var result = await LibraryManager.GetAuthorsByName(substring, index, count, sort); return (result.Item1, result.Item2); } public Task AddBookToCollection(string id) { return UserLibraryManager.AddBook(id); } public async Task GetBookByIdFromCollection(string id) => await UserLibraryManager.GetBookById(id); public Task UpdateBook(Book book) { return UserLibraryManager.UpdateBook(book); } public Task<(long count, IEnumerable books)> GetBooksFromCollection(int index, int count, string sort = "") { var result = UserLibraryManager.GetBooksFromCollection(index, count, sort).Result; return Task.FromResult((result.Item1, result.Item2)); } public Task<(long count, IEnumerable contacts)> GetContacts(int index, int count) { var result = UserLibraryManager.GetContacts(index, count).Result; return Task.FromResult((result.Item1, result.Item2)); } public Task<(long count, IEnumerable loans)> GetCurrentLoans(int index, int count) { var result = UserLibraryManager.GetCurrentLoans(index, count).Result; return Task.FromResult((result.Item1, result.Item2)); } public Task<(long count, IEnumerable loans)> GetPastLoans(int index, int count) { var result = UserLibraryManager.GetPastLoans(index, count).Result; return Task.FromResult((result.Item1, result.Item2)); } public Task<(long count, IEnumerable borrowings)> GetCurrentBorrowings(int index, int count) { var result = UserLibraryManager.GetCurrentBorrowings(index, count).Result; return Task.FromResult((result.Item1, result.Item2)); } public Task<(long count, IEnumerable borrowings)> GetPastBorrowings(int index, int count) { var result = UserLibraryManager.GetPastBorrowings(index, count).Result; return Task.FromResult((result.Item1, result.Item2)); } } }