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

88 lines
2.5 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 : INotifyPropertyChanged
{
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 event PropertyChangedEventHandler PropertyChanged;
public BookViewModel(ILibraryManager data)
{
this.data = data;
GetAuthors();
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public class AuteurGroup : ObservableCollection<Book>
{
public string Name { get; private set; }
public AuteurGroup(string name, ObservableCollection<Book> books): base(books)
{
Name = name;
}
}
public void GetBooks()
{
var objet = data.GetBooksByAuthor("", 0, 8);
var ojb = objet.Result.Item2;
/*foreach (Book Book in ojb)
{
AuteurGroups.Add(new AuteurGroup(Book.Authors.Name, auteur.Books));
}
ObservableCollection<Auteur> auteurs = new Stub().CreateStubData();
foreach (Auteur auteur in auteurs)
{
AuteurGroups.Add(new AuteurGroup(auteur.Name, auteur.Books));
}
*/
}
public void GetAuthors()
{
var objet = data.GetAuthorsByName("",0,10);
var ojb = objet.Result.Item2;
authorList.Clear();
foreach (var author in ojb)
{
authorList.Add(author);
}
}
public async Task<ObservableCollection<Book>> GetBooksByTitle()
{
var objet = await data.GetBooksByTitle("", 0, 9);
var ojb = objet.Item2;
return new ObservableCollection<Book>(ojb);
}
}
}