diff --git a/LivreLand/View/FiltrageDateView.xaml b/LivreLand/View/FiltrageDateView.xaml
index a731aac..c52e4ff 100644
--- a/LivreLand/View/FiltrageDateView.xaml
+++ b/LivreLand/View/FiltrageDateView.xaml
@@ -35,8 +35,9 @@
+ SelectionChangedCommandParameter="{Binding FiltrageDateVM.Manager.SelectedDate}">
diff --git a/LivreLand/View/StatutLectureView.xaml b/LivreLand/View/StatutLectureView.xaml
index 158870a..d2a67a8 100644
--- a/LivreLand/View/StatutLectureView.xaml
+++ b/LivreLand/View/StatutLectureView.xaml
@@ -28,7 +28,7 @@
SelectionMode="Single"
SelectionChanged="OnSelectionChanged"
Grid.Row="2">
-
+
+
-
+
@@ -121,7 +122,7 @@
+ Margin="0,0,5,0"/>
diff --git a/ViewModels/ManagerVM.cs b/ViewModels/ManagerVM.cs
index 76df72e..a7020ae 100644
--- a/ViewModels/ManagerVM.cs
+++ b/ViewModels/ManagerVM.cs
@@ -74,6 +74,10 @@ namespace ViewModels
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 int Index
@@ -107,6 +111,8 @@ namespace ViewModels
public ICommand GetAllAuthorsCommand { get; private set; }
+ public ICommand GetBooksByDateCommand { get; private set; }
+
public ICommand GetAllPublishDatesCommand { get; private set; }
public ICommand GetAllRatingsCommand { get; private set; }
@@ -121,6 +127,8 @@ namespace ViewModels
public ICommand GetPastBorrowingsCommand { get; private set; }
+ public ICommand GetBooksByRatingCommand { get; private set; }
+
#endregion
#region Constructor
@@ -132,7 +140,9 @@ namespace ViewModels
GetBooksFromCollectionCommand = new RelayCommand(() => GetBooksFromCollection());
GetBooksByAuthorCommand = new RelayCommand(() => GetBooksByAuthor());
GetAllAuthorsCommand = new RelayCommand(() => GetAllAuthors());
+ GetBooksByDateCommand = new RelayCommand(() => GetBooksByDate());
GetAllPublishDatesCommand = new RelayCommand(() => GetAllPublishDates());
+ GetBooksByRatingCommand = new RelayCommand(() => GetBooksByRating());
GetAllRatingsCommand = new RelayCommand(() => GetAllRatings());
GetToBeReadBooksCommand = new RelayCommand(() => GetToBeReadBooks());
GetCurrentLoansCommand = new RelayCommand(() => GetCurrentLoans());
@@ -171,6 +181,7 @@ namespace ViewModels
var result = await Model.GetBooksFromCollection(Index, Count);
NbBooks = result.count;
IEnumerable someBooks = result.books;
+ someBooks = someBooks.OrderBy(b => b.Status);
books.Clear();
foreach (var b in someBooks.Select(b => new BookVM(b)))
{
@@ -209,6 +220,22 @@ namespace ViewModels
OnPropertyChanged(nameof(AllAuthors));
}
+ private async Task GetBooksByDate()
+ {
+ var result = await Model.GetBooksFromCollection(Index, Count);
+ NbBooks = result.count;
+ IEnumerable 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()
{
var result = await Model.GetBooksFromCollection(0, 20);
@@ -232,29 +259,59 @@ namespace ViewModels
OnPropertyChanged(nameof(AllPublishDates));
}
+ private async Task GetBooksByRating()
+ {
+ var result = await Model.GetBooksFromCollection(Index, Count);
+ NbBooks = result.count;
+ IEnumerable 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()
{
var result = await Model.GetBooksFromCollection(0, 20);
IEnumerable someBooks = result.books;
books.Clear();
ratings.Clear();
+
+ Dictionary> groupedBooks = new Dictionary>();
+
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)
- {
- rating.NbBooksWritten++;
- ratings.Add(rating);
- foreach (var r in ratings)
+ {
+ string noteKey = Math.Floor(rating.Average.Value).ToString("0");
+
+ if (!groupedBooks.ContainsKey(noteKey))
{
- if (rating.Average == r.Average && !rating.Equals(r))
- {
- r.NbBooksWritten++;
- ratings.Remove(rating);
- }
+ groupedBooks[noteKey] = new List();
}
+
+ 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));
}