You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
PocketBook/Sources/VMWrapper/BookViewModel.cs

71 lines
2.1 KiB

using Model;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Xml.Linq;
namespace VMWrapper
{
// All the code in this file is included in all platforms.
public class BookViewModel
{
private readonly ILibraryManager data;
public ObservableCollection<Author> authorList { get; private set; } =
new ObservableCollection<Author>();
public ObservableCollection<Book> bookList { get; private set; } =
new ObservableCollection<Book>();
public ObservableCollection<AuteurGroup> AuteurGroups { get; private set; } =
new ObservableCollection<AuteurGroup>();
public BookViewModel(ILibraryManager data)
{
this.data = data;
GetAuthors();
LoadBooksAsync();
}
private async void LoadBooksAsync()
{
try
{
var (totalA, authors) = await data.GetAuthorsByName("", 0, 5);
foreach (Author author in authors)
{
var books = data.GetBooksByAuthor(author.Name, 0, 5).Result.Item2;
var observableBooks = new ObservableCollection<Book>(books);
AuteurGroups.Add(new AuteurGroup(author.Name, observableBooks));
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
}
public class AuteurGroup : ObservableCollection<Book>
{
public string Name { get; private set; }
public AuteurGroup(string name, ObservableCollection<Book> books)
: base(books)
{
Name = name;
}
}
public void GetAuthors()
{
var objet = data.GetAuthorsByName("", 0, 10).Result.Item2;
authorList.Clear();
foreach (var author in objet)
{
authorList.Add(author);
}
}
}
}