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.
145 lines
4.0 KiB
145 lines
4.0 KiB
using ToolKit;
|
|
using Model;
|
|
using System.Collections.ObjectModel;
|
|
using System.Windows.Input;
|
|
using System.Data.Common;
|
|
|
|
namespace Wrapper
|
|
{
|
|
public class BooksViewModel : BaseViewModel
|
|
{
|
|
public Manager Manager { get; set; }
|
|
|
|
public RelayCommand<string> LoadBooks { get; private set; }
|
|
|
|
/*
|
|
public ReadOnlyObservableCollection<Book> Books
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
private readonly List<Book> books;*/
|
|
|
|
|
|
public ObservableCollection<Book> Books = new ObservableCollection<Book>();
|
|
public ObservableCollection<GroupBooks> GroupBooks { get; private set; } = new ObservableCollection<GroupBooks>();
|
|
|
|
|
|
|
|
public BooksViewModel(ILibraryManager libraryManager,IUserLibraryManager userLibraryManager)
|
|
{
|
|
Manager = new Manager(libraryManager, userLibraryManager);
|
|
LoadBooks = new RelayCommand<string>(o => LoadBooksFromManager());
|
|
|
|
Count = 7;
|
|
LoadBooksFromManager();
|
|
}
|
|
|
|
|
|
private void UpdateGroupBooks()
|
|
{
|
|
GroupBooks.Clear();
|
|
foreach (Book book in Books)
|
|
{
|
|
if (book.Authors.Count != 0)
|
|
{
|
|
foreach (Author author in book.Authors)
|
|
{
|
|
Console.WriteLine(author.Name);
|
|
int find = -1;
|
|
for (int i = 0; i < GroupBooks.Count(); i++)
|
|
{
|
|
if (GroupBooks[i].Author == author.Name)
|
|
{
|
|
find = i;
|
|
break;
|
|
}
|
|
}
|
|
Console.WriteLine("l - 55");
|
|
if (find != -1)
|
|
{
|
|
Console.WriteLine("l - 58");
|
|
GroupBooks[find].Add(book);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("l - 63");
|
|
GroupBooks.Add(new GroupBooks(author.Name, new List<Book> { book }));
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int index = -1;
|
|
for ( int i = 0; i < GroupBooks.Count(); i++)
|
|
{
|
|
if (GroupBooks[i].Author == "Inconnu")
|
|
{
|
|
index = i;
|
|
break;
|
|
}
|
|
}
|
|
if (index == -1)
|
|
{
|
|
GroupBooks.Add(new GroupBooks("Inconnu", new List<Book> { book }));
|
|
} else
|
|
{
|
|
GroupBooks[index].Add(book);
|
|
}
|
|
}
|
|
}
|
|
Console.WriteLine(GroupBooks.Count);
|
|
}
|
|
|
|
|
|
|
|
private void LoadBooksFromManager()
|
|
{
|
|
var result = Manager.GetBooksFromCollection(index,count,"");
|
|
if (result.Result.books.Count() == 0 ) { return ; }
|
|
Books.Clear();
|
|
foreach (Book book in result.Result.books)
|
|
{
|
|
Books.Add(book);
|
|
}
|
|
NbBook = result.Result.count;
|
|
|
|
UpdateGroupBooks();
|
|
}
|
|
|
|
public int Index {
|
|
get { return index; }
|
|
private set
|
|
{
|
|
setProperty(ref index, value);
|
|
}
|
|
|
|
}
|
|
private int index ;
|
|
|
|
|
|
|
|
public int Count
|
|
{
|
|
get { return count; }
|
|
private set
|
|
{
|
|
setProperty(ref count, value);
|
|
}
|
|
|
|
}
|
|
private int count;
|
|
|
|
|
|
public long NbBook
|
|
{
|
|
get { return nbBook; }
|
|
private set
|
|
{
|
|
setProperty(ref nbBook, value);
|
|
}
|
|
|
|
}
|
|
private long nbBook;
|
|
}
|
|
} |