diff --git a/LivreLand/View/TousView.xaml b/LivreLand/View/TousView.xaml
index a35965d..7defc8a 100644
--- a/LivreLand/View/TousView.xaml
+++ b/LivreLand/View/TousView.xaml
@@ -109,11 +109,11 @@
Style="{StaticResource MasterTitleBookText}"
Grid.Column="2"
Grid.Row="0"/>
-
-
diff --git a/Model/Author.cs b/Model/Author.cs
index bc6dfba..cb6f361 100644
--- a/Model/Author.cs
+++ b/Model/Author.cs
@@ -1,6 +1,6 @@
namespace Model
{
- public class Author
+ public class Author : IEquatable
{
public string Id { get; set; }
public string Name { get; set; }
@@ -12,5 +12,19 @@
public List Links { get; set; }
public DateTime? BirthDate { get; set; }
public DateTime? DeathDate { get; set; }
+
+ public bool Equals(Author? other)
+ => Id == other.Id;
+
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(obj, null)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (GetType() != obj.GetType()) return false;
+ return Equals(obj as Author);
+ }
+
+ public override int GetHashCode()
+ => Id.GetHashCode();
}
}
\ No newline at end of file
diff --git a/Model/Book.cs b/Model/Book.cs
index 825d42a..9cc4c07 100644
--- a/Model/Book.cs
+++ b/Model/Book.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Model
{
- public class Book
+ public class Book : IEquatable
{
public string Id { get; set; }
public string Title { get; set; }
@@ -23,5 +23,23 @@ namespace Model
public string ImageLarge => $"https://covers.openlibrary.org/b/isbn/{ISBN13}-L.jpg";
public List Works { get; set; } = new List();
public List Authors { get; set; } = new List();
+ public Status Status { get; set; }
+ public List UserTags { get; set; } = new List();
+ public float? UserRating { get; set; }
+ public string UserNote { get; set; }
+
+ public bool Equals(Book? other)
+ => Id == other.Id;
+
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(obj, null)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (GetType() != obj.GetType()) return false;
+ return Equals(obj as Book);
+ }
+
+ public override int GetHashCode()
+ => Id.GetHashCode();
}
}
diff --git a/Model/Borrowing.cs b/Model/Borrowing.cs
new file mode 100644
index 0000000..14c98b1
--- /dev/null
+++ b/Model/Borrowing.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Model
+{
+ public class Borrowing : IEquatable
+ {
+ public string Id { get; set; }
+ public Book Book { get; set; }
+ public Contact Owner { get; set; }
+ public DateTime BorrowedAt { get; set; }
+ public DateTime? ReturnedAt { get; set; }
+
+ public bool Equals(Borrowing? other)
+ => Id == other.Id;
+
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(obj, null)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (GetType() != obj.GetType()) return false;
+ return Equals(obj as Borrowing);
+ }
+
+ public override int GetHashCode()
+ => Id.GetHashCode();
+ }
+}
diff --git a/Model/Contact.cs b/Model/Contact.cs
new file mode 100644
index 0000000..7e3f482
--- /dev/null
+++ b/Model/Contact.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Model
+{
+ public class Contact : IEquatable
+ {
+ public string Id { get; set; }
+ public string FirstName { get; set; }
+ public string LastName { get; set; }
+
+ public bool Equals(Contact? other)
+ => Id == other.Id;
+
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(obj, null)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (GetType() != obj.GetType()) return false;
+ return Equals(obj as Contact);
+ }
+
+ public override int GetHashCode()
+ => Id.GetHashCode();
+ }
+}
diff --git a/Model/IUserLibraryManager.cs b/Model/IUserLibraryManager.cs
new file mode 100644
index 0000000..d39c82b
--- /dev/null
+++ b/Model/IUserLibraryManager.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Model
+{
+ public interface IUserLibraryManager : ILibraryManager
+ {
+ Task>> GetBooksFromCollection(int index, int count, string sort = "");
+
+ Task AddBook(Book book);
+ Task AddBook(string id);
+ Task AddBookByIsbn(string isbn);
+ Task RemoveBook(Book book);
+ Task RemoveBook(string id);
+ Task RemoveBookByIsbn(string isbn);
+
+ Task AddToFavorites(Book book);
+ Task AddToFavorites(string bookId);
+ Task RemoveFromFavorites(Book book);
+ Task RemoveFromFavorites(string bookId);
+
+ Task UpdateBook(Book updatedBook);
+
+ Task AddContact(Contact contact);
+ Task RemoveContact(Contact contact);
+
+ Task LendBook(Book book, Contact contact, DateTime? loanDate);
+ Task GetBackBook(Book book, DateTime? returnedDate);
+ Task BorrowBook(Book book, Contact owner, DateTime? borrowedDate);
+ Task GiveBackBook(Book book, DateTime? returnedDate);
+
+ Task>> GetCurrentLoans(int index, int count);
+ Task>> GetPastLoans(int index, int count);
+
+ Task>> GetCurrentBorrowings(int index, int count);
+ Task>> GetPastBorrowings(int index, int count);
+
+ Task>> GetContacts(int index, int count);
+ }
+}
diff --git a/Model/Loan.cs b/Model/Loan.cs
new file mode 100644
index 0000000..266dd6d
--- /dev/null
+++ b/Model/Loan.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Model
+{
+ public class Loan : IEquatable
+ {
+ public string Id { get; set; }
+ public Book Book { get; set; }
+ public Contact Loaner { get; set; }
+ public DateTime LoanedAt { get; set; }
+ public DateTime? ReturnedAt { get; set; }
+
+ public bool Equals(Loan? other)
+ => Id == other.Id;
+
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(obj, null)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (GetType() != obj.GetType()) return false;
+ return Equals(obj as Loan);
+ }
+
+ public override int GetHashCode()
+ => Id.GetHashCode();
+ }
+}
diff --git a/Model/Manager.cs b/Model/Manager.cs
index c992fe8..b2e1714 100644
--- a/Model/Manager.cs
+++ b/Model/Manager.cs
@@ -10,13 +10,15 @@ namespace Model
public class Manager
{
private ILibraryManager LibraryManager { get; set; }
+ private IUserLibraryManager UserLibraryManager { get; set; }
public ReadOnlyCollection Books { get; private set; }
private List books = new();
- public Manager(ILibraryManager libMgr)
+ public Manager(ILibraryManager libMgr, IUserLibraryManager userLibMgr)
{
LibraryManager = libMgr;
+ UserLibraryManager = userLibMgr;
Books = new ReadOnlyCollection(books);
}
@@ -52,5 +54,54 @@ namespace Model
var result = await LibraryManager.GetAuthorsByName(substring, index, count, sort);
return (result.Item1, result.Item2);
}
+
+ public Task AddBookToCollection(string id)
+ {
+ return UserLibraryManager.AddBook(id);
+ }
+
+ public async Task GetBookByIdFromCollection(string id)
+ => await UserLibraryManager.GetBookById(id);
+
+ public Task UpdateBook(Book book)
+ {
+ return UserLibraryManager.UpdateBook(book);
+ }
+
+ public Task<(long count, IEnumerable books)> GetBooksFromCollection(int index, int count, string sort = "")
+ {
+ var result = UserLibraryManager.GetBooksFromCollection(index, count, sort).Result;
+ return Task.FromResult((result.Item1, result.Item2));
+ }
+
+ public Task<(long count, IEnumerable contacts)> GetContacts(int index, int count)
+ {
+ var result = UserLibraryManager.GetContacts(index, count).Result;
+ return Task.FromResult((result.Item1, result.Item2));
+ }
+
+ public Task<(long count, IEnumerable loans)> GetCurrentLoans(int index, int count)
+ {
+ var result = UserLibraryManager.GetCurrentLoans(index, count).Result;
+ return Task.FromResult((result.Item1, result.Item2));
+ }
+
+ public Task<(long count, IEnumerable loans)> GetPastLoans(int index, int count)
+ {
+ var result = UserLibraryManager.GetPastLoans(index, count).Result;
+ return Task.FromResult((result.Item1, result.Item2));
+ }
+
+ public Task<(long count, IEnumerable borrowings)> GetCurrentBorrowings(int index, int count)
+ {
+ var result = UserLibraryManager.GetCurrentBorrowings(index, count).Result;
+ return Task.FromResult((result.Item1, result.Item2));
+ }
+
+ public Task<(long count, IEnumerable borrowings)> GetPastBorrowings(int index, int count)
+ {
+ var result = UserLibraryManager.GetPastBorrowings(index, count).Result;
+ return Task.FromResult((result.Item1, result.Item2));
+ }
}
}
diff --git a/Model/Status.cs b/Model/Status.cs
new file mode 100644
index 0000000..14d29e8
--- /dev/null
+++ b/Model/Status.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Model
+{
+ public enum Status
+ {
+ Unknown,
+ Finished,
+ Reading,
+ NotRead,
+ ToBeRead
+ }
+}
diff --git a/Model/Work.cs b/Model/Work.cs
index 316eb6b..1f3d81e 100644
--- a/Model/Work.cs
+++ b/Model/Work.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Model
{
- public class Work
+ public class Work : IEquatable
{
public string Id { get; set; }
public string Description { get; set; }
@@ -14,5 +14,19 @@ namespace Model
public List Subjects { get; set; } = new List();
public List Authors { get; set; } = new List();
public Ratings Ratings { get; set; }
+
+ public bool Equals(Work? other)
+ => Id == other.Id;
+
+ public override bool Equals(object? obj)
+ {
+ if (ReferenceEquals(obj, null)) return false;
+ if (ReferenceEquals(this, obj)) return true;
+ if (GetType() != obj.GetType()) return false;
+ return Equals(obj as Work);
+ }
+
+ public override int GetHashCode()
+ => Id.GetHashCode();
}
}
diff --git a/Stub/UserLibraryStub.cs b/Stub/UserLibraryStub.cs
new file mode 100644
index 0000000..3547f49
--- /dev/null
+++ b/Stub/UserLibraryStub.cs
@@ -0,0 +1,425 @@
+using Model;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Stub
+{
+ public class UserLibraryStub : IUserLibraryManager
+ {
+ public ReadOnlyCollection Favorites { get; private set; }
+ private List favorites = new List();
+
+ public ReadOnlyCollection Books { get; private set; }
+ private List books = new List();
+
+ public ReadOnlyCollection Contacts { get; private set; }
+ private List contacts = new List();
+
+ public ReadOnlyCollection Loans { get; private set; }
+ private List loans = new List();
+
+ public ReadOnlyCollection Borrowings { get; private set; }
+ private List borrowings = new List();
+
+ public ILibraryManager LibraryMgr { get; private set; }
+
+ public UserLibraryStub(ILibraryManager libraryMgr)
+ {
+ LibraryMgr = libraryMgr;
+ Favorites = new ReadOnlyCollection(favorites);
+ Books = new ReadOnlyCollection(books);
+ Borrowings = new ReadOnlyCollection(borrowings);
+ Loans = new ReadOnlyCollection(loans);
+ Contacts = new ReadOnlyCollection(contacts);
+
+ contacts.AddRange(new Contact[]
+ {
+ new Contact { Id = "/contacts/01", FirstName = "Audrey", LastName = "Pouclet" },
+ new Contact { Id = "/contacts/02", FirstName = "Malika", LastName = "More" },
+ new Contact { Id = "/contacts/03", FirstName = "Antoine" },
+ });
+ books.AddRange(new Book[]
+ {
+ LibraryMgr.GetBookById("/books/OL25910297M").Result,
+ LibraryMgr.GetBookById("/books/OL26210208M").Result,
+ LibraryMgr.GetBookById("/books/OL27258011M").Result,
+ LibraryMgr.GetBookById("/books/OL28294024M").Result,
+ LibraryMgr.GetBookById("/books/OL28639494M").Result,
+ LibraryMgr.GetBookById("/books/OL35699439M").Result,
+ LibraryMgr.GetBookById("/books/OL37758347M").Result,
+ LibraryMgr.GetBookById("/books/OL38218739M").Result,
+ LibraryMgr.GetBookById("/books/OL38586212M").Result,
+ LibraryMgr.GetBookById("/books/OL8839071M").Result,
+ LibraryMgr.GetBookById("/books/OL8198056M").Result,
+ });
+ books[0].Status = Status.Finished;
+ books[0].UserNote = "Super bouquin de SF !";
+ books[0].UserRating = 4.5f;
+ loans.Add(new Loan { Id = "/loans/01", Book = books[0], Loaner = contacts[0], LoanedAt = new DateTime(2022, 7, 12), ReturnedAt = new DateTime(2023, 9, 1) });
+ books[1].Status = Status.ToBeRead;
+ books[2].Status = Status.Finished;
+ books[2].UserNote = "Des nouvelles de SF. Super auteur à découvrir !";
+ books[2].UserRating = 4.8f;
+ books[3].Status = Status.Finished;
+ books[3].UserRating = 4.0f;
+ loans.Add(new Loan { Id = "/loans/02", Book = books[3], Loaner = contacts[2], LoanedAt = new DateTime(2020, 12, 23), ReturnedAt = new DateTime(2021, 8, 13) });
+ books[4].Status = Status.Finished;
+ books[4].UserNote = "Déjà moins connu que le premier, et pourtant...";
+ books[4].UserRating = 4.2f;
+ books[5].Status = Status.Finished;
+ books[5].UserNote = "Coup de coeur. Poétique, anarchique, philosophique... + SF. Du Deleuze et du Foucault chez Damasio";
+ books[5].UserRating = 4.9f;
+ books[6].Status = Status.NotRead;
+ books[7].Status = Status.Finished;
+ books[7].UserRating = 4.9f;
+ books[7].UserNote = "Chef d'oeuvre";
+ books[8].Status = Status.Finished;
+ books[8].UserRating = 4.2f;
+ books[8].UserNote = "Des nouvelles très réussies dont Rapport Minoritaire";
+ books[9].Status = Status.ToBeRead;
+ books[9].Status = Status.Reading;
+
+ borrowings.Add(new Borrowing
+ {
+ Id = "/borrowing/01",
+ Owner = contacts[0],
+ Book = LibraryMgr.GetBookById("/books/OL27328194M").Result,
+ BorrowedAt = new DateTime(2023, 9, 7)
+ });
+ borrowings.Add(new Borrowing
+ {
+ Id = "/borrowing/02",
+ Owner = contacts[1],
+ Book = LibraryMgr.GetBookById("/books/OL27989051M").Result,
+ BorrowedAt = new DateTime(2022, 7, 7),
+ ReturnedAt = new DateTime(2023, 3, 1)
+ });
+ borrowings.Add(new Borrowing
+ {
+ Id = "/borrowing/03",
+ Owner = contacts[1],
+ Book = LibraryMgr.GetBookById("/books/OL35698073M").Result,
+ BorrowedAt = new DateTime(2022, 7, 7),
+ ReturnedAt = new DateTime(2022, 9, 1)
+ });
+ borrowings.Add(new Borrowing
+ {
+ Id = "/borrowing/04",
+ Owner = contacts[1],
+ Book = LibraryMgr.GetBookById("/books/OL35698083M").Result,
+ BorrowedAt = new DateTime(2022, 7, 7),
+ ReturnedAt = new DateTime(2023, 8, 30)
+ });
+ }
+
+ public Task AddBook(Book book)
+ {
+ if (Books.Contains(book))
+ {
+ return Task.FromResult(null);
+ }
+ books.Add(book);
+ return Task.FromResult(book);
+ }
+
+ public async Task AddBook(string id)
+ {
+ if (Books.SingleOrDefault(b => b.Id == id) != null)
+ {
+ return null;
+ }
+ var book = await LibraryMgr.GetBookById(id);
+ books.Add(book);
+ return book;
+ }
+
+ public async Task AddBookByIsbn(string isbn)
+ {
+ if (Books.SingleOrDefault(b => b.ISBN13 == isbn) != null)
+ {
+ return null;
+ }
+ var book = await LibraryMgr.GetBookByISBN(isbn);
+ books.Add(book);
+ return book;
+ }
+
+ public Task RemoveBook(Book book)
+ {
+ return Task.FromResult(books.Remove(book));
+ }
+
+ public Task RemoveBook(string id)
+ {
+ return Task.FromResult(books.RemoveAll(b => b.Id == id) >= 0);
+ }
+
+ public Task RemoveBookByIsbn(string isbn)
+ {
+ return Task.FromResult(books.RemoveAll(b => b.ISBN13 == isbn) >= 0);
+ }
+
+ public Task AddToFavorites(Book book)
+ {
+ if (Favorites.Contains(book))
+ {
+ return Task.FromResult(false);
+ }
+ var bookToAdd = Books.SingleOrDefault(b => b.Id == book.Id);
+ if (bookToAdd == null)
+ {
+ return Task.FromResult(false);
+ }
+ favorites.Add(bookToAdd);
+ return Task.FromResult(true);
+ }
+
+ public Task AddToFavorites(string bookId)
+ {
+ if (Favorites.SingleOrDefault(b => b.Id == bookId) != null)
+ {
+ return Task.FromResult(false);
+ }
+ var book = Books.SingleOrDefault(b => b.Id == bookId);
+ if (book == null)
+ {
+ return Task.FromResult(false);
+ }
+ favorites.Add(book);
+ return Task.FromResult(true);
+ }
+
+ public Task RemoveFromFavorites(Book book)
+ {
+ return Task.FromResult(favorites.Remove(book));
+ }
+
+ public Task RemoveFromFavorites(string bookId)
+ {
+ return Task.FromResult(favorites.RemoveAll(b => b.Id == bookId) >= 0);
+ }
+
+ public Task AddContact(Contact contact)
+ {
+ if (Contacts.Contains(contact))
+ {
+ return Task.FromResult(null);
+ }
+ contacts.Add(contact);
+ return Task.FromResult(contact);
+ }
+
+ public Task RemoveContact(Contact contact)
+ {
+ return Task.FromResult(contacts.Remove(contact));
+ }
+
+ public Task LendBook(Book book, Contact contact, DateTime? loanDate = null)
+ {
+ if (!Books.Contains(book))
+ return Task.FromResult(false);
+ if (!Contacts.Contains(contact))
+ AddContact(contact);
+ Loan loan = new Loan { Book = book, Loaner = contact, LoanedAt = loanDate.GetValueOrDefault(DateTime.Now) };
+ if (Loans.Contains(loan))
+ return Task.FromResult(false);
+ loans.Add(loan);
+ return Task.FromResult(true);
+ }
+
+ public Task GetBackBook(Book book, DateTime? returnedDate = null)
+ {
+ if (!Books.Contains(book))
+ return Task.FromResult(false);
+ var loan = loans.SingleOrDefault(l => l.Book == book);
+ if (loan == null)
+ return Task.FromResult(false);
+ loan.ReturnedAt = returnedDate.GetValueOrDefault(DateTime.Now);
+ return Task.FromResult(true);
+ }
+
+ public Task BorrowBook(Book book, Contact owner, DateTime? borrowedDate = null)
+ {
+ if (!Books.Contains(book))
+ return Task.FromResult(false);
+ if (!Contacts.Contains(owner))
+ AddContact(owner);
+ Borrowing borrow = new Borrowing { Book = book, Owner = owner, BorrowedAt = borrowedDate.GetValueOrDefault(DateTime.Now) };
+ if (Borrowings.Contains(borrow))
+ return Task.FromResult(false);
+ borrowings.Add(borrow);
+ return Task.FromResult(true);
+ }
+
+ public Task GiveBackBook(Book book, DateTime? returnedDate = null)
+ {
+ if (!Books.Contains(book))
+ return Task.FromResult(false);
+ var borrow = borrowings.SingleOrDefault(b => b.Book == book);
+ if (borrow == null)
+ return Task.FromResult(false);
+ borrow.ReturnedAt = returnedDate.GetValueOrDefault(DateTime.Now);
+ return Task.FromResult(true);
+ }
+
+ public Task GetBookById(string id)
+ {
+ return Task.FromResult(Books.SingleOrDefault(b => b.Id == id));
+ }
+
+ public Task GetBookByISBN(string isbn)
+ {
+ return Task.FromResult(Books.SingleOrDefault(b => b.ISBN13 == isbn));
+ }
+
+ public Task>> GetBooksByTitle(string title, int index, int count, string sort = "")
+ {
+ var foundBooks = Books.Where(b => b.Title.Contains(title, StringComparison.InvariantCultureIgnoreCase));
+ return OrderBooks(foundBooks, index, count, sort);
+ }
+
+ public Task>> GetBooksByAuthorId(string authorId, int index, int count, string sort = "")
+ {
+ var foundBooks = Books.Where(b => b.Authors.Exists(a => a.Id.Contains(authorId))
+ || b.Works.Exists(w => w.Authors.Exists(a => a.Id.Contains(authorId))));
+ return OrderBooks(books, index, count, sort);
+ }
+
+ public Task>> GetBooksByAuthor(string author, int index, int count, string sort = "")
+ {
+ var foundBooks = Books.Where(b => ContainsAuthorName(b, author));
+ return OrderBooks(books, index, count, sort);
+ }
+
+ public IEnumerable Authors
+ {
+ get
+ {
+ var bookAuthors = Books.SelectMany(b => b.Authors);
+ var workAuthors = Books.SelectMany(b => b.Works).SelectMany(w => w.Authors);
+ return bookAuthors.Union(workAuthors).Distinct();
+ }
+ }
+
+ public Task GetAuthorById(string id)
+ {
+ return Task.FromResult(Authors.SingleOrDefault(a => a.Id == id));
+ }
+
+ private Task>> OrderAuthors(IEnumerable authors, int index, int count, string sort = "")
+ {
+ switch (sort)
+ {
+ case "name":
+ authors = authors.OrderBy(a => a.Name);
+ break;
+ case "name_reverse":
+ authors = authors.OrderByDescending(a => a.Name);
+ break;
+ }
+ return Task.FromResult(Tuple.Create((long)authors.Count(), authors.Skip(index * count).Take(count)));
+ }
+
+ public Task>> GetAuthorsByName(string substring, int index, int count, string sort = "")
+ {
+ var foundAuthors = Authors.Where(a => a.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase)
+ || a.AlternateNames.Exists(alt => alt.Contains(substring, StringComparison.InvariantCultureIgnoreCase)));
+ return OrderAuthors(foundAuthors, index, count, sort);
+ }
+
+ public Task UpdateBook(Book updatedBook)
+ {
+ if (!books.Contains(updatedBook))
+ {
+ return Task.FromResult(null);
+ }
+ books.Remove(updatedBook);
+ books.Add(updatedBook);
+ return Task.FromResult(updatedBook);
+ }
+
+ private Task>> OrderBooks(IEnumerable books, int index, int count, string sort = "")
+ {
+ switch (sort)
+ {
+ case "title":
+ books = books.OrderBy(b => b.Title);
+ break;
+ case "title_reverse":
+ books = books.OrderByDescending(b => b.Title);
+ break;
+ case "new":
+ books = books.OrderByDescending(b => b.PublishDate);
+ break;
+ case "old":
+ books = books.OrderBy(b => b.PublishDate);
+ break;
+
+ }
+ return Task.FromResult(Tuple.Create(books.LongCount(), books.Skip(index * count).Take(count)));
+ }
+
+ private bool ContainsAuthorName(Book book, string name)
+ {
+ IEnumerable authors = new List();
+
+ if (book.Authors != null && book.Authors.Count > 0)
+ {
+ authors = authors.Union(book.Authors);
+ }
+ if (book.Works != null)
+ {
+ var worksAuthors = book.Works.SelectMany(w => w.Authors).ToList();
+ if (worksAuthors.Count > 0)
+ authors = authors.Union(worksAuthors);
+ }
+ foreach (var author in authors)
+ {
+ if (author.Name.Contains(name, StringComparison.OrdinalIgnoreCase)
+ || author.AlternateNames.Exists(alt => alt.Contains(name, StringComparison.OrdinalIgnoreCase)))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public Task>> GetBooksFromCollection(int index, int count, string sort = "")
+ {
+ return OrderBooks(Books, index, count, sort);
+ }
+
+ public Task>> GetCurrentLoans(int index, int count)
+ {
+ var currentLoans = Loans.Where(l => !l.ReturnedAt.HasValue);
+ return Task.FromResult(Tuple.Create(currentLoans.LongCount(), currentLoans.Skip(index * count).Take(count)));
+ }
+
+ public Task>> GetPastLoans(int index, int count)
+ {
+ var currentLoans = Loans.Where(l => l.ReturnedAt.HasValue);
+ return Task.FromResult(Tuple.Create(currentLoans.LongCount(), currentLoans.Skip(index * count).Take(count)));
+ }
+
+ public Task>> GetCurrentBorrowings(int index, int count)
+ {
+ var currentBorrowings = Borrowings.Where(l => !l.ReturnedAt.HasValue);
+ return Task.FromResult(Tuple.Create(currentBorrowings.LongCount(), currentBorrowings.Skip(index * count).Take(count)));
+ }
+
+ public Task>> GetPastBorrowings(int index, int count)
+ {
+ var currentBorrowings = Borrowings.Where(l => l.ReturnedAt.HasValue);
+ return Task.FromResult(Tuple.Create(currentBorrowings.LongCount(), currentBorrowings.Skip(index * count).Take(count)));
+ }
+
+ public Task>> GetContacts(int index, int count)
+ {
+ return Task.FromResult(Tuple.Create(Contacts.LongCount(), Contacts.Skip(index * count).Take(count)));
+ }
+ }
+}
diff --git a/StubbedDTO/Stub.cs b/StubbedDTO/Stub.cs
index d586c28..bef031e 100644
--- a/StubbedDTO/Stub.cs
+++ b/StubbedDTO/Stub.cs
@@ -122,7 +122,7 @@ namespace StubbedDTO
break;
}
- return Task.FromResult(Tuple.Create((long)books.Count(), books.Skip(index * count).Take(count)));
+ return Task.FromResult(Tuple.Create(books.LongCount(), books.Skip(index * count).Take(count)));
}
public async Task>> GetBooks(int index, int count, string sort = "")
diff --git a/ViewModels/ManagerVM.cs b/ViewModels/ManagerVM.cs
index 32f3d7f..993eb4b 100644
--- a/ViewModels/ManagerVM.cs
+++ b/ViewModels/ManagerVM.cs
@@ -1,7 +1,6 @@
using Model;
using System.Collections.ObjectModel;
using System.Windows.Input;
-using ViewModels.LivreLand.ViewModel;
namespace ViewModels
{