|
|
@ -74,6 +74,10 @@ namespace ViewModels
|
|
|
|
|
|
|
|
|
|
|
|
public AuthorVM SelectedAuthor { get; private set; }
|
|
|
|
public AuthorVM SelectedAuthor { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PublishDateVM SelectedDate { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public RatingsVM SelectedRating { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public string SearchTitle { get; private set; }
|
|
|
|
public string SearchTitle { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public int Index
|
|
|
|
public int Index
|
|
|
@ -107,6 +111,8 @@ namespace ViewModels
|
|
|
|
|
|
|
|
|
|
|
|
public ICommand GetAllAuthorsCommand { get; private set; }
|
|
|
|
public ICommand GetAllAuthorsCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ICommand GetBooksByDateCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public ICommand GetAllPublishDatesCommand { get; private set; }
|
|
|
|
public ICommand GetAllPublishDatesCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public ICommand GetAllRatingsCommand { get; private set; }
|
|
|
|
public ICommand GetAllRatingsCommand { get; private set; }
|
|
|
@ -121,6 +127,8 @@ namespace ViewModels
|
|
|
|
|
|
|
|
|
|
|
|
public ICommand GetPastBorrowingsCommand { get; private set; }
|
|
|
|
public ICommand GetPastBorrowingsCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ICommand GetBooksByRatingCommand { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
#region Constructor
|
|
|
@ -132,7 +140,9 @@ namespace ViewModels
|
|
|
|
GetBooksFromCollectionCommand = new RelayCommand(() => GetBooksFromCollection());
|
|
|
|
GetBooksFromCollectionCommand = new RelayCommand(() => GetBooksFromCollection());
|
|
|
|
GetBooksByAuthorCommand = new RelayCommand(() => GetBooksByAuthor());
|
|
|
|
GetBooksByAuthorCommand = new RelayCommand(() => GetBooksByAuthor());
|
|
|
|
GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors());
|
|
|
|
GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors());
|
|
|
|
|
|
|
|
GetBooksByDateCommand = new RelayCommand(() => GetBooksByDate());
|
|
|
|
GetAllPublishDatesCommand = new RelayCommand(() => GetAllPublishDates());
|
|
|
|
GetAllPublishDatesCommand = new RelayCommand(() => GetAllPublishDates());
|
|
|
|
|
|
|
|
GetBooksByRatingCommand = new RelayCommand(() => GetBooksByRating());
|
|
|
|
GetAllRatingsCommand = new RelayCommand(() => GetAllRatings());
|
|
|
|
GetAllRatingsCommand = new RelayCommand(() => GetAllRatings());
|
|
|
|
GetToBeReadBooksCommand = new RelayCommand(() => GetToBeReadBooks());
|
|
|
|
GetToBeReadBooksCommand = new RelayCommand(() => GetToBeReadBooks());
|
|
|
|
GetCurrentLoansCommand = new RelayCommand(() => GetCurrentLoans());
|
|
|
|
GetCurrentLoansCommand = new RelayCommand(() => GetCurrentLoans());
|
|
|
@ -171,6 +181,7 @@ namespace ViewModels
|
|
|
|
var result = await Model.GetBooksFromCollection(Index, Count);
|
|
|
|
var result = await Model.GetBooksFromCollection(Index, Count);
|
|
|
|
NbBooks = result.count;
|
|
|
|
NbBooks = result.count;
|
|
|
|
IEnumerable<Book> someBooks = result.books;
|
|
|
|
IEnumerable<Book> someBooks = result.books;
|
|
|
|
|
|
|
|
someBooks = someBooks.OrderBy(b => b.Status);
|
|
|
|
books.Clear();
|
|
|
|
books.Clear();
|
|
|
|
foreach (var b in someBooks.Select(b => new BookVM(b)))
|
|
|
|
foreach (var b in someBooks.Select(b => new BookVM(b)))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -209,6 +220,22 @@ namespace ViewModels
|
|
|
|
OnPropertyChanged(nameof(AllAuthors));
|
|
|
|
OnPropertyChanged(nameof(AllAuthors));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task GetBooksByDate()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var result = await Model.GetBooksFromCollection(Index, Count);
|
|
|
|
|
|
|
|
NbBooks = result.count;
|
|
|
|
|
|
|
|
IEnumerable<Book> someBooks = result.books;
|
|
|
|
|
|
|
|
books.Clear();
|
|
|
|
|
|
|
|
foreach (var b in someBooks.Select(b => new BookVM(b)))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (b.PublishDate == SelectedDate.PublishDate)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
books.Add(b);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OnPropertyChanged(nameof(AllBooks));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task GetAllPublishDates()
|
|
|
|
private async Task GetAllPublishDates()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var result = await Model.GetBooksFromCollection(0, 20);
|
|
|
|
var result = await Model.GetBooksFromCollection(0, 20);
|
|
|
@ -232,29 +259,59 @@ namespace ViewModels
|
|
|
|
OnPropertyChanged(nameof(AllPublishDates));
|
|
|
|
OnPropertyChanged(nameof(AllPublishDates));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task GetBooksByRating()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var result = await Model.GetBooksFromCollection(Index, Count);
|
|
|
|
|
|
|
|
NbBooks = result.count;
|
|
|
|
|
|
|
|
IEnumerable<Book> someBooks = result.books;
|
|
|
|
|
|
|
|
books.Clear();
|
|
|
|
|
|
|
|
var filteredBooks = someBooks.Where(b => b.UserRating.HasValue && Math.Floor(b.UserRating.Value) == SelectedRating.Average);
|
|
|
|
|
|
|
|
foreach (var book in filteredBooks)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
books.Add(new BookVM(book));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OnPropertyChanged(nameof(AllBooks));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async Task GetAllRatings()
|
|
|
|
private async Task GetAllRatings()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var result = await Model.GetBooksFromCollection(0, 20);
|
|
|
|
var result = await Model.GetBooksFromCollection(0, 20);
|
|
|
|
IEnumerable<Book> someBooks = result.books;
|
|
|
|
IEnumerable<Book> someBooks = result.books;
|
|
|
|
books.Clear();
|
|
|
|
books.Clear();
|
|
|
|
ratings.Clear();
|
|
|
|
ratings.Clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<string, List<BookVM>> groupedBooks = new Dictionary<string, List<BookVM>>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var b in someBooks.Select(b => new BookVM(b)))
|
|
|
|
foreach (var b in someBooks.Select(b => new BookVM(b)))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var rating = new RatingsVM { Average = b.UserRating};
|
|
|
|
var rating = new RatingsVM { Average = b.UserRating };
|
|
|
|
if (rating.Average != null)
|
|
|
|
if (rating.Average != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
rating.NbBooksWritten++;
|
|
|
|
string noteKey = Math.Floor(rating.Average.Value).ToString("0");
|
|
|
|
ratings.Add(rating);
|
|
|
|
|
|
|
|
foreach (var r in ratings)
|
|
|
|
if (!groupedBooks.ContainsKey(noteKey))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (rating.Average == r.Average && !rating.Equals(r))
|
|
|
|
groupedBooks[noteKey] = new List<BookVM>();
|
|
|
|
{
|
|
|
|
|
|
|
|
r.NbBooksWritten++;
|
|
|
|
|
|
|
|
ratings.Remove(rating);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
groupedBooks[noteKey].Add(b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var entry in groupedBooks)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var noteKey = entry.Key;
|
|
|
|
|
|
|
|
var booksWithSameRating = entry.Value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rating = new RatingsVM
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Average = float.Parse(noteKey),
|
|
|
|
|
|
|
|
NbBooksWritten = booksWithSameRating.Count
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ratings.Add(rating);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OnPropertyChanged(nameof(AllRatings));
|
|
|
|
OnPropertyChanged(nameof(AllRatings));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|