|
|
|
@ -2,53 +2,135 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using ToolKit;
|
|
|
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
|
|
|
|
|
|
namespace VMWrapper
|
|
|
|
|
{
|
|
|
|
|
public class FilterViewModel
|
|
|
|
|
public class FilterViewModel: BaseViewModel
|
|
|
|
|
{
|
|
|
|
|
private readonly ILibraryManager data;
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<Author> authorList { get; private set; } =
|
|
|
|
|
public ObservableCollection<Author> AuthorList { get; private set; } =
|
|
|
|
|
new ObservableCollection<Author>();
|
|
|
|
|
public ObservableCollection<Book> bookList { get; private set; } =
|
|
|
|
|
public ObservableCollection<Book> BookList { get; private set; } =
|
|
|
|
|
new ObservableCollection<Book>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private long _totalBooks;
|
|
|
|
|
public long TotalBooks
|
|
|
|
|
{
|
|
|
|
|
get { return _totalBooks; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_totalBooks = value;
|
|
|
|
|
OnPropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _searchQuery;
|
|
|
|
|
public string SearchQuery
|
|
|
|
|
{
|
|
|
|
|
get => _searchQuery;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_searchQuery != value)
|
|
|
|
|
{
|
|
|
|
|
_searchQuery = value;
|
|
|
|
|
OnPropertyChanged(nameof(SearchQuery));
|
|
|
|
|
_ = SearchAuthors(SearchQuery);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ICommand _searchCommand;
|
|
|
|
|
public ICommand SearchCommand =>
|
|
|
|
|
_searchCommand ??= new CommandPersonnal<string>(
|
|
|
|
|
async (query) => await SearchAuthors(query)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
public FilterViewModel(ILibraryManager data)
|
|
|
|
|
{
|
|
|
|
|
this.data = data;
|
|
|
|
|
GetAuthors();
|
|
|
|
|
_ = GetAuthorsAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void GetDatePublish()
|
|
|
|
|
private async Task GetDatePublish()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var books = data.GetBooksByAuthor("", 0, 5).Result.Item2;
|
|
|
|
|
var result = await data.GetBooksByAuthor("", 0, 5);
|
|
|
|
|
var books = result.Item2;
|
|
|
|
|
|
|
|
|
|
BookList.Clear();
|
|
|
|
|
foreach (Book book in books)
|
|
|
|
|
{
|
|
|
|
|
bookList.Add(book);
|
|
|
|
|
BookList.Add(book);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task GetAuthorsAsync()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var result = await data.GetAuthorsByName("", 0, 10);
|
|
|
|
|
var authors = result.Item2;
|
|
|
|
|
|
|
|
|
|
AuthorList.Clear();
|
|
|
|
|
foreach (var author in authors)
|
|
|
|
|
{
|
|
|
|
|
AuthorList.Add(author);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
System.Diagnostics.Debug.WriteLine(ex.Message);
|
|
|
|
|
Debug.WriteLine(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GetAuthors()
|
|
|
|
|
|
|
|
|
|
private async Task SearchAuthors(string query)
|
|
|
|
|
{
|
|
|
|
|
var objet = data.GetAuthorsByName("", 0, 10).Result.Item2;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(query))
|
|
|
|
|
{
|
|
|
|
|
TotalBooks = 0;
|
|
|
|
|
|
|
|
|
|
var (total, authors) = await data.GetAuthorsByName(query, 0, 10);
|
|
|
|
|
|
|
|
|
|
AuthorList.Clear();
|
|
|
|
|
foreach (Author author in authors)
|
|
|
|
|
{
|
|
|
|
|
var (totalB, books) = data.GetBooksByAuthor(author.Name, 0, 10).Result;
|
|
|
|
|
TotalBooks += totalB;
|
|
|
|
|
|
|
|
|
|
authorList.Clear();
|
|
|
|
|
foreach (var author in objet)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var author in authors)
|
|
|
|
|
{
|
|
|
|
|
AuthorList.Add(author);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_ = GetAuthorsAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
authorList.Add(author);
|
|
|
|
|
Debug.WriteLine(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|