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 authorList { get; private set; } = new ObservableCollection(); public ObservableCollection bookList { get; private set; } = new ObservableCollection(); public ObservableCollection AuteurGroups { get; private set; } = new ObservableCollection(); 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(books); AuteurGroups.Add(new AuteurGroup(author.Name, observableBooks)); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } public class AuteurGroup : ObservableCollection { public string Name { get; private set; } public AuteurGroup(string name, ObservableCollection 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); } } } }