|
|
@ -7,8 +7,8 @@ using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace StubLib
|
|
|
|
namespace StubLib
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class UserLibraryStub : IUserLibraryManager
|
|
|
|
public class UserLibraryStub : IUserLibraryManager
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public ReadOnlyCollection<Book> Favorites { get; private set; }
|
|
|
|
public ReadOnlyCollection<Book> Favorites { get; private set; }
|
|
|
|
private List<Book> favorites = new List<Book>();
|
|
|
|
private List<Book> favorites = new List<Book>();
|
|
|
|
|
|
|
|
|
|
|
@ -26,8 +26,8 @@ namespace StubLib
|
|
|
|
|
|
|
|
|
|
|
|
public ILibraryManager LibraryMgr { get; private set; }
|
|
|
|
public ILibraryManager LibraryMgr { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public UserLibraryStub(ILibraryManager libraryMgr)
|
|
|
|
public UserLibraryStub(ILibraryManager libraryMgr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LibraryMgr = libraryMgr;
|
|
|
|
LibraryMgr = libraryMgr;
|
|
|
|
Favorites = new ReadOnlyCollection<Book>(favorites);
|
|
|
|
Favorites = new ReadOnlyCollection<Book>(favorites);
|
|
|
|
Books = new ReadOnlyCollection<Book>(books);
|
|
|
|
Books = new ReadOnlyCollection<Book>(books);
|
|
|
@ -35,42 +35,75 @@ namespace StubLib
|
|
|
|
Loans = new ReadOnlyCollection<Loan>(loans);
|
|
|
|
Loans = new ReadOnlyCollection<Loan>(loans);
|
|
|
|
Contacts = new ReadOnlyCollection<Contact>(contacts);
|
|
|
|
Contacts = new ReadOnlyCollection<Contact>(contacts);
|
|
|
|
|
|
|
|
|
|
|
|
contacts.AddRange(new Contact[]
|
|
|
|
contacts.AddRange(
|
|
|
|
{
|
|
|
|
new Contact[]
|
|
|
|
new Contact { Id = "/contacts/01", FirstName = "Audrey", LastName = "Pouclet" },
|
|
|
|
{
|
|
|
|
new Contact { Id = "/contacts/02", FirstName = "Malika", LastName = "More" },
|
|
|
|
new Contact
|
|
|
|
new Contact { Id = "/contacts/03", FirstName = "Antoine" },
|
|
|
|
{
|
|
|
|
});
|
|
|
|
Id = "/contacts/01",
|
|
|
|
books.AddRange(new Book[]
|
|
|
|
FirstName = "Audrey",
|
|
|
|
{
|
|
|
|
LastName = "Pouclet"
|
|
|
|
LibraryMgr.GetBookById("/books/OL25910297M").Result,
|
|
|
|
},
|
|
|
|
LibraryMgr.GetBookById("/books/OL26210208M").Result,
|
|
|
|
new Contact
|
|
|
|
LibraryMgr.GetBookById("/books/OL27258011M").Result,
|
|
|
|
{
|
|
|
|
LibraryMgr.GetBookById("/books/OL28294024M").Result,
|
|
|
|
Id = "/contacts/02",
|
|
|
|
LibraryMgr.GetBookById("/books/OL28639494M").Result,
|
|
|
|
FirstName = "Malika",
|
|
|
|
LibraryMgr.GetBookById("/books/OL35699439M").Result,
|
|
|
|
LastName = "More"
|
|
|
|
LibraryMgr.GetBookById("/books/OL37758347M").Result,
|
|
|
|
},
|
|
|
|
LibraryMgr.GetBookById("/books/OL38218739M").Result,
|
|
|
|
new Contact { Id = "/contacts/03", FirstName = "Antoine" },
|
|
|
|
LibraryMgr.GetBookById("/books/OL38586212M").Result,
|
|
|
|
}
|
|
|
|
LibraryMgr.GetBookById("/books/OL8839071M").Result,
|
|
|
|
);
|
|
|
|
LibraryMgr.GetBookById("/books/OL8198056M").Result,
|
|
|
|
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].Status = Status.Finished;
|
|
|
|
books[0].UserNote = "Super bouquin de SF !";
|
|
|
|
books[0].UserNote = "Super bouquin de SF !";
|
|
|
|
books[0].UserRating = 4.5f;
|
|
|
|
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) });
|
|
|
|
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[1].Status = Status.ToBeRead;
|
|
|
|
books[2].Status = Status.Finished;
|
|
|
|
books[2].Status = Status.Finished;
|
|
|
|
books[2].UserNote = "Des nouvelles de SF. Super auteur à découvrir !";
|
|
|
|
books[2].UserNote = "Des nouvelles de SF. Super auteur à découvrir !";
|
|
|
|
books[2].UserRating = 4.8f;
|
|
|
|
books[2].UserRating = 4.8f;
|
|
|
|
books[3].Status = Status.Finished;
|
|
|
|
books[3].Status = Status.Finished;
|
|
|
|
books[3].UserRating = 4.0f;
|
|
|
|
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) } );
|
|
|
|
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].Status = Status.Finished;
|
|
|
|
books[4].UserNote = "Déjà moins connu que le premier, et pourtant...";
|
|
|
|
books[4].UserNote = "Déjà moins connu que le premier, et pourtant...";
|
|
|
|
books[4].UserRating = 4.2f;
|
|
|
|
books[4].UserRating = 4.2f;
|
|
|
|
books[5].Status = Status.Finished;
|
|
|
|
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].UserNote =
|
|
|
|
|
|
|
|
"Coup de coeur. Poétique, anarchique, philosophique... + SF. Du Deleuze et du Foucault chez Damasio";
|
|
|
|
books[5].UserRating = 4.9f;
|
|
|
|
books[5].UserRating = 4.9f;
|
|
|
|
books[6].Status = Status.NotRead;
|
|
|
|
books[6].Status = Status.NotRead;
|
|
|
|
books[7].Status = Status.Finished;
|
|
|
|
books[7].Status = Status.Finished;
|
|
|
@ -82,38 +115,50 @@ namespace StubLib
|
|
|
|
books[9].Status = Status.ToBeRead;
|
|
|
|
books[9].Status = Status.ToBeRead;
|
|
|
|
books[9].Status = Status.Reading;
|
|
|
|
books[9].Status = Status.Reading;
|
|
|
|
|
|
|
|
|
|
|
|
borrowings.Add(new Borrowing
|
|
|
|
borrowings.Add(
|
|
|
|
{
|
|
|
|
new Borrowing
|
|
|
|
Id = "/borrowing/01", Owner = contacts[0],
|
|
|
|
{
|
|
|
|
Book = LibraryMgr.GetBookById("/books/OL27328194M").Result,
|
|
|
|
Id = "/borrowing/01",
|
|
|
|
BorrowedAt = new DateTime(2023, 9, 7)
|
|
|
|
Owner = contacts[0],
|
|
|
|
});
|
|
|
|
Book = LibraryMgr.GetBookById("/books/OL27328194M").Result,
|
|
|
|
borrowings.Add(new Borrowing
|
|
|
|
BorrowedAt = new DateTime(2023, 9, 7)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
Id = "/borrowing/02", Owner = contacts[1],
|
|
|
|
);
|
|
|
|
Book = LibraryMgr.GetBookById("/books/OL27989051M").Result,
|
|
|
|
borrowings.Add(
|
|
|
|
BorrowedAt = new DateTime(2022, 7, 7),
|
|
|
|
new Borrowing
|
|
|
|
ReturnedAt = new DateTime(2023, 3, 1)
|
|
|
|
{
|
|
|
|
});
|
|
|
|
Id = "/borrowing/02",
|
|
|
|
borrowings.Add(new Borrowing
|
|
|
|
Owner = contacts[1],
|
|
|
|
{
|
|
|
|
Book = LibraryMgr.GetBookById("/books/OL27989051M").Result,
|
|
|
|
Id = "/borrowing/03", Owner = contacts[1],
|
|
|
|
BorrowedAt = new DateTime(2022, 7, 7),
|
|
|
|
Book = LibraryMgr.GetBookById("/books/OL35698073M").Result,
|
|
|
|
ReturnedAt = new DateTime(2023, 3, 1)
|
|
|
|
BorrowedAt = new DateTime(2022, 7, 7),
|
|
|
|
}
|
|
|
|
ReturnedAt = new DateTime(2022, 9, 1)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
borrowings.Add(
|
|
|
|
borrowings.Add(new Borrowing
|
|
|
|
new Borrowing
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Id = "/borrowing/04", Owner = contacts[1],
|
|
|
|
Id = "/borrowing/03",
|
|
|
|
Book = LibraryMgr.GetBookById("/books/OL35698083M").Result,
|
|
|
|
Owner = contacts[1],
|
|
|
|
BorrowedAt = new DateTime(2022, 7, 7),
|
|
|
|
Book = LibraryMgr.GetBookById("/books/OL35698073M").Result,
|
|
|
|
ReturnedAt = new DateTime(2023, 8, 30)
|
|
|
|
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<Book> AddBook(Book book)
|
|
|
|
public Task<Book> AddBook(Book book)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(Books.Contains(book))
|
|
|
|
if (Books.Contains(book))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Task.FromResult<Book>(null);
|
|
|
|
return Task.FromResult<Book>(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -123,7 +168,7 @@ namespace StubLib
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<Book> AddBook(string id)
|
|
|
|
public async Task<Book> AddBook(string id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(Books.SingleOrDefault(b => b.Id == id) != null)
|
|
|
|
if (Books.SingleOrDefault(b => b.Id == id) != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -134,7 +179,7 @@ namespace StubLib
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<Book> AddBookByIsbn(string isbn)
|
|
|
|
public async Task<Book> AddBookByIsbn(string isbn)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(Books.SingleOrDefault(b => b.ISBN13 == isbn) != null)
|
|
|
|
if (Books.SingleOrDefault(b => b.ISBN13 == isbn) != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -160,12 +205,12 @@ namespace StubLib
|
|
|
|
|
|
|
|
|
|
|
|
public Task<bool> AddToFavorites(Book book)
|
|
|
|
public Task<bool> AddToFavorites(Book book)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(Favorites.Contains(book))
|
|
|
|
if (Favorites.Contains(book))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Task.FromResult(false);
|
|
|
|
return Task.FromResult(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var bookToAdd = Books.SingleOrDefault(b => b.Id == book.Id);
|
|
|
|
var bookToAdd = Books.SingleOrDefault(b => b.Id == book.Id);
|
|
|
|
if(bookToAdd == null)
|
|
|
|
if (bookToAdd == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Task.FromResult(false);
|
|
|
|
return Task.FromResult(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -175,12 +220,12 @@ namespace StubLib
|
|
|
|
|
|
|
|
|
|
|
|
public Task<bool> AddToFavorites(string bookId)
|
|
|
|
public Task<bool> AddToFavorites(string bookId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(Favorites.SingleOrDefault(b => b.Id == bookId) != null)
|
|
|
|
if (Favorites.SingleOrDefault(b => b.Id == bookId) != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Task.FromResult(false);
|
|
|
|
return Task.FromResult(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var book = Books.SingleOrDefault(b => b.Id == bookId);
|
|
|
|
var book = Books.SingleOrDefault(b => b.Id == bookId);
|
|
|
|
if(book == null)
|
|
|
|
if (book == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Task.FromResult(false);
|
|
|
|
return Task.FromResult(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -200,7 +245,7 @@ namespace StubLib
|
|
|
|
|
|
|
|
|
|
|
|
public Task<Contact> AddContact(Contact contact)
|
|
|
|
public Task<Contact> AddContact(Contact contact)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(Contacts.Contains(contact))
|
|
|
|
if (Contacts.Contains(contact))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Task.FromResult<Contact>(null);
|
|
|
|
return Task.FromResult<Contact>(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -215,12 +260,17 @@ namespace StubLib
|
|
|
|
|
|
|
|
|
|
|
|
public Task<bool> LendBook(Book book, Contact contact, DateTime? loanDate = null)
|
|
|
|
public Task<bool> LendBook(Book book, Contact contact, DateTime? loanDate = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!Books.Contains(book))
|
|
|
|
if (!Books.Contains(book))
|
|
|
|
return Task.FromResult(false);
|
|
|
|
return Task.FromResult(false);
|
|
|
|
if(!Contacts.Contains(contact))
|
|
|
|
if (!Contacts.Contains(contact))
|
|
|
|
AddContact(contact);
|
|
|
|
AddContact(contact);
|
|
|
|
Loan loan = new Loan { Book = book, Loaner = contact, LoanedAt = loanDate.GetValueOrDefault(DateTime.Now) };
|
|
|
|
Loan loan = new Loan
|
|
|
|
if(Loans.Contains(loan))
|
|
|
|
{
|
|
|
|
|
|
|
|
Book = book,
|
|
|
|
|
|
|
|
Loaner = contact,
|
|
|
|
|
|
|
|
LoanedAt = loanDate.GetValueOrDefault(DateTime.Now)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if (Loans.Contains(loan))
|
|
|
|
return Task.FromResult(false);
|
|
|
|
return Task.FromResult(false);
|
|
|
|
loans.Add(loan);
|
|
|
|
loans.Add(loan);
|
|
|
|
return Task.FromResult(true);
|
|
|
|
return Task.FromResult(true);
|
|
|
@ -228,10 +278,10 @@ namespace StubLib
|
|
|
|
|
|
|
|
|
|
|
|
public Task<bool> GetBackBook(Book book, DateTime? returnedDate = null)
|
|
|
|
public Task<bool> GetBackBook(Book book, DateTime? returnedDate = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!Books.Contains(book))
|
|
|
|
if (!Books.Contains(book))
|
|
|
|
return Task.FromResult(false);
|
|
|
|
return Task.FromResult(false);
|
|
|
|
var loan = loans.SingleOrDefault(l => l.Book == book);
|
|
|
|
var loan = loans.SingleOrDefault(l => l.Book == book);
|
|
|
|
if(loan == null)
|
|
|
|
if (loan == null)
|
|
|
|
return Task.FromResult(false);
|
|
|
|
return Task.FromResult(false);
|
|
|
|
loan.ReturnedAt = returnedDate.GetValueOrDefault(DateTime.Now);
|
|
|
|
loan.ReturnedAt = returnedDate.GetValueOrDefault(DateTime.Now);
|
|
|
|
return Task.FromResult(true);
|
|
|
|
return Task.FromResult(true);
|
|
|
@ -239,12 +289,17 @@ namespace StubLib
|
|
|
|
|
|
|
|
|
|
|
|
public Task<bool> BorrowBook(Book book, Contact owner, DateTime? borrowedDate = null)
|
|
|
|
public Task<bool> BorrowBook(Book book, Contact owner, DateTime? borrowedDate = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!Books.Contains(book))
|
|
|
|
if (!Books.Contains(book))
|
|
|
|
return Task.FromResult(false);
|
|
|
|
return Task.FromResult(false);
|
|
|
|
if(!Contacts.Contains(owner))
|
|
|
|
if (!Contacts.Contains(owner))
|
|
|
|
AddContact(owner);
|
|
|
|
AddContact(owner);
|
|
|
|
Borrowing borrow = new Borrowing { Book = book, Owner = owner, BorrowedAt = borrowedDate.GetValueOrDefault(DateTime.Now) };
|
|
|
|
Borrowing borrow = new Borrowing
|
|
|
|
if(Borrowings.Contains(borrow))
|
|
|
|
{
|
|
|
|
|
|
|
|
Book = book,
|
|
|
|
|
|
|
|
Owner = owner,
|
|
|
|
|
|
|
|
BorrowedAt = borrowedDate.GetValueOrDefault(DateTime.Now)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if (Borrowings.Contains(borrow))
|
|
|
|
return Task.FromResult(false);
|
|
|
|
return Task.FromResult(false);
|
|
|
|
borrowings.Add(borrow);
|
|
|
|
borrowings.Add(borrow);
|
|
|
|
return Task.FromResult(true);
|
|
|
|
return Task.FromResult(true);
|
|
|
@ -252,10 +307,10 @@ namespace StubLib
|
|
|
|
|
|
|
|
|
|
|
|
public Task<bool> GiveBackBook(Book book, DateTime? returnedDate = null)
|
|
|
|
public Task<bool> GiveBackBook(Book book, DateTime? returnedDate = null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!Books.Contains(book))
|
|
|
|
if (!Books.Contains(book))
|
|
|
|
return Task.FromResult(false);
|
|
|
|
return Task.FromResult(false);
|
|
|
|
var borrow = borrowings.SingleOrDefault(b => b.Book == book);
|
|
|
|
var borrow = borrowings.SingleOrDefault(b => b.Book == book);
|
|
|
|
if(borrow == null)
|
|
|
|
if (borrow == null)
|
|
|
|
return Task.FromResult(false);
|
|
|
|
return Task.FromResult(false);
|
|
|
|
borrow.ReturnedAt = returnedDate.GetValueOrDefault(DateTime.Now);
|
|
|
|
borrow.ReturnedAt = returnedDate.GetValueOrDefault(DateTime.Now);
|
|
|
|
return Task.FromResult(true);
|
|
|
|
return Task.FromResult(true);
|
|
|
@ -271,20 +326,40 @@ namespace StubLib
|
|
|
|
return Task.FromResult(Books.SingleOrDefault(b => b.ISBN13 == isbn));
|
|
|
|
return Task.FromResult(Books.SingleOrDefault(b => b.ISBN13 == isbn));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<Tuple<long, IEnumerable<Book>>> GetBooksByTitle(string title, int index, int count, string sort = "")
|
|
|
|
public Task<Tuple<long, IEnumerable<Book>>> GetBooksByTitle(
|
|
|
|
|
|
|
|
string title,
|
|
|
|
|
|
|
|
int index,
|
|
|
|
|
|
|
|
int count,
|
|
|
|
|
|
|
|
string sort = ""
|
|
|
|
|
|
|
|
)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var foundBooks = Books.Where(b => b.Title.Contains(title, StringComparison.InvariantCultureIgnoreCase));
|
|
|
|
var foundBooks = Books.Where(
|
|
|
|
|
|
|
|
b => b.Title.Contains(title, StringComparison.InvariantCultureIgnoreCase)
|
|
|
|
|
|
|
|
);
|
|
|
|
return OrderBooks(foundBooks, index, count, sort);
|
|
|
|
return OrderBooks(foundBooks, index, count, sort);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<Tuple<long, IEnumerable<Book>>> GetBooksByAuthorId(string authorId, int index, int count, string sort = "")
|
|
|
|
public Task<Tuple<long, IEnumerable<Book>>> GetBooksByAuthorId(
|
|
|
|
|
|
|
|
string authorId,
|
|
|
|
|
|
|
|
int index,
|
|
|
|
|
|
|
|
int count,
|
|
|
|
|
|
|
|
string sort = ""
|
|
|
|
|
|
|
|
)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var foundBooks = Books.Where(b => b.Authors.Exists(a => a.Id.Contains(authorId))
|
|
|
|
var foundBooks = Books.Where(
|
|
|
|
|| b.Works.Exists(w => w.Authors.Exists(a => a.Id.Contains(authorId))));
|
|
|
|
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);
|
|
|
|
return OrderBooks(books, index, count, sort);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<Tuple<long, IEnumerable<Book>>> GetBooksByAuthor(string author, int index, int count, string sort = "")
|
|
|
|
public Task<Tuple<long, IEnumerable<Book>>> GetBooksByAuthor(
|
|
|
|
|
|
|
|
string author,
|
|
|
|
|
|
|
|
int index,
|
|
|
|
|
|
|
|
int count,
|
|
|
|
|
|
|
|
string sort = ""
|
|
|
|
|
|
|
|
)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var foundBooks = Books.Where(b => ContainsAuthorName(b, author));
|
|
|
|
var foundBooks = Books.Where(b => ContainsAuthorName(b, author));
|
|
|
|
return OrderBooks(books, index, count, sort);
|
|
|
|
return OrderBooks(books, index, count, sort);
|
|
|
@ -305,9 +380,14 @@ namespace StubLib
|
|
|
|
return Task.FromResult(Authors.SingleOrDefault(a => a.Id == id));
|
|
|
|
return Task.FromResult(Authors.SingleOrDefault(a => a.Id == id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Task<Tuple<long, IEnumerable<Author>>> OrderAuthors(IEnumerable<Author> authors, int index, int count, string sort = "")
|
|
|
|
private Task<Tuple<long, IEnumerable<Author>>> OrderAuthors(
|
|
|
|
|
|
|
|
IEnumerable<Author> authors,
|
|
|
|
|
|
|
|
int index,
|
|
|
|
|
|
|
|
int count,
|
|
|
|
|
|
|
|
string sort = ""
|
|
|
|
|
|
|
|
)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch(sort)
|
|
|
|
switch (sort)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case "name":
|
|
|
|
case "name":
|
|
|
|
authors = authors.OrderBy(a => a.Name);
|
|
|
|
authors = authors.OrderBy(a => a.Name);
|
|
|
@ -316,19 +396,31 @@ namespace StubLib
|
|
|
|
authors = authors.OrderByDescending(a => a.Name);
|
|
|
|
authors = authors.OrderByDescending(a => a.Name);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Task.FromResult(Tuple.Create((long)authors.Count(), authors.Skip(index*count).Take(count)));
|
|
|
|
return Task.FromResult(
|
|
|
|
}
|
|
|
|
Tuple.Create((long)authors.Count(), authors.Skip(index * count).Take(count))
|
|
|
|
|
|
|
|
);
|
|
|
|
public Task<Tuple<long, IEnumerable<Author>>> GetAuthorsByName(string substring, int index, int count, string sort = "")
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
var foundAuthors = Authors.Where(a => a.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase)
|
|
|
|
public Task<Tuple<long, IEnumerable<Author>>> GetAuthorsByName(
|
|
|
|
|| a.AlternateNames.Exists(alt => alt.Contains(substring, StringComparison.InvariantCultureIgnoreCase)));
|
|
|
|
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);
|
|
|
|
return OrderAuthors(foundAuthors, index, count, sort);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<Book> UpdateBook(Book updatedBook)
|
|
|
|
public Task<Book> UpdateBook(Book updatedBook)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!books.Contains(updatedBook))
|
|
|
|
if (!books.Contains(updatedBook))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Task.FromResult<Book>(null);
|
|
|
|
return Task.FromResult<Book>(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -337,9 +429,14 @@ namespace StubLib
|
|
|
|
return Task.FromResult(updatedBook);
|
|
|
|
return Task.FromResult(updatedBook);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Task<Tuple<long, IEnumerable<Book>>> OrderBooks(IEnumerable<Book> books, int index, int count, string sort = "")
|
|
|
|
private Task<Tuple<long, IEnumerable<Book>>> OrderBooks(
|
|
|
|
|
|
|
|
IEnumerable<Book> books,
|
|
|
|
|
|
|
|
int index,
|
|
|
|
|
|
|
|
int count,
|
|
|
|
|
|
|
|
string sort = ""
|
|
|
|
|
|
|
|
)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch(sort)
|
|
|
|
switch (sort)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
case "title":
|
|
|
|
case "title":
|
|
|
|
books = books.OrderBy(b => b.Title);
|
|
|
|
books = books.OrderBy(b => b.Title);
|
|
|
@ -353,29 +450,34 @@ namespace StubLib
|
|
|
|
case "old":
|
|
|
|
case "old":
|
|
|
|
books = books.OrderBy(b => b.PublishDate);
|
|
|
|
books = books.OrderBy(b => b.PublishDate);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Task.FromResult(Tuple.Create(books.LongCount(), books.Skip(index*count).Take(count)));
|
|
|
|
return Task.FromResult(
|
|
|
|
|
|
|
|
Tuple.Create(books.LongCount(), books.Skip(index * count).Take(count))
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool ContainsAuthorName(Book book, string name)
|
|
|
|
private bool ContainsAuthorName(Book book, string name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IEnumerable<Author> authors = new List<Author>();
|
|
|
|
IEnumerable<Author> authors = new List<Author>();
|
|
|
|
|
|
|
|
|
|
|
|
if(book.Authors != null && book.Authors.Count > 0)
|
|
|
|
if (book.Authors != null && book.Authors.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
authors = authors.Union(book.Authors);
|
|
|
|
authors = authors.Union(book.Authors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(book.Works != null)
|
|
|
|
if (book.Works != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var worksAuthors = book.Works.SelectMany(w => w.Authors).ToList();
|
|
|
|
var worksAuthors = book.Works.SelectMany(w => w.Authors).ToList();
|
|
|
|
if(worksAuthors.Count > 0)
|
|
|
|
if (worksAuthors.Count > 0)
|
|
|
|
authors = authors.Union(worksAuthors);
|
|
|
|
authors = authors.Union(worksAuthors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach(var author in authors)
|
|
|
|
foreach (var author in authors)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(author.Name.Contains(name, StringComparison.OrdinalIgnoreCase)
|
|
|
|
if (
|
|
|
|
|| author.AlternateNames.Exists(alt => alt.Contains(name, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
author.Name.Contains(name, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
|
|
|
|| author.AlternateNames.Exists(
|
|
|
|
|
|
|
|
alt => alt.Contains(name, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -383,7 +485,11 @@ namespace StubLib
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<Tuple<long, IEnumerable<Book>>> GetBooksFromCollection(int index, int count, string sort = "")
|
|
|
|
public Task<Tuple<long, IEnumerable<Book>>> GetBooksFromCollection(
|
|
|
|
|
|
|
|
int index,
|
|
|
|
|
|
|
|
int count,
|
|
|
|
|
|
|
|
string sort = ""
|
|
|
|
|
|
|
|
)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return OrderBooks(Books, index, count, sort);
|
|
|
|
return OrderBooks(Books, index, count, sort);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -391,31 +497,46 @@ namespace StubLib
|
|
|
|
public Task<Tuple<long, IEnumerable<Loan>>> GetCurrentLoans(int index, int count)
|
|
|
|
public Task<Tuple<long, IEnumerable<Loan>>> GetCurrentLoans(int index, int count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var currentLoans = Loans.Where(l => !l.ReturnedAt.HasValue);
|
|
|
|
var currentLoans = Loans.Where(l => !l.ReturnedAt.HasValue);
|
|
|
|
return Task.FromResult(Tuple.Create(currentLoans.LongCount(), currentLoans.Skip(index*count).Take(count)));
|
|
|
|
return Task.FromResult(
|
|
|
|
|
|
|
|
Tuple.Create(currentLoans.LongCount(), currentLoans.Skip(index * count).Take(count))
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<Tuple<long, IEnumerable<Loan>>> GetPastLoans(int index, int count)
|
|
|
|
public Task<Tuple<long, IEnumerable<Loan>>> GetPastLoans(int index, int count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var currentLoans = Loans.Where(l => l.ReturnedAt.HasValue);
|
|
|
|
var currentLoans = Loans.Where(l => l.ReturnedAt.HasValue);
|
|
|
|
return Task.FromResult(Tuple.Create(currentLoans.LongCount(), currentLoans.Skip(index*count).Take(count)));
|
|
|
|
return Task.FromResult(
|
|
|
|
|
|
|
|
Tuple.Create(currentLoans.LongCount(), currentLoans.Skip(index * count).Take(count))
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<Tuple<long, IEnumerable<Borrowing>>> GetCurrentBorrowings(int index, int count)
|
|
|
|
public Task<Tuple<long, IEnumerable<Borrowing>>> GetCurrentBorrowings(int index, int count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var currentBorrowings = Borrowings.Where(l => !l.ReturnedAt.HasValue);
|
|
|
|
var currentBorrowings = Borrowings.Where(l => !l.ReturnedAt.HasValue);
|
|
|
|
return Task.FromResult(Tuple.Create(currentBorrowings.LongCount(), currentBorrowings.Skip(index*count).Take(count)));
|
|
|
|
return Task.FromResult(
|
|
|
|
|
|
|
|
Tuple.Create(
|
|
|
|
|
|
|
|
currentBorrowings.LongCount(),
|
|
|
|
|
|
|
|
currentBorrowings.Skip(index * count).Take(count)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<Tuple<long, IEnumerable<Borrowing>>> GetPastBorrowings(int index, int count)
|
|
|
|
public Task<Tuple<long, IEnumerable<Borrowing>>> GetPastBorrowings(int index, int count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var currentBorrowings = Borrowings.Where(l => l.ReturnedAt.HasValue);
|
|
|
|
var currentBorrowings = Borrowings.Where(l => l.ReturnedAt.HasValue);
|
|
|
|
return Task.FromResult(Tuple.Create(currentBorrowings.LongCount(), currentBorrowings.Skip(index*count).Take(count)));
|
|
|
|
return Task.FromResult(
|
|
|
|
|
|
|
|
Tuple.Create(
|
|
|
|
|
|
|
|
currentBorrowings.LongCount(),
|
|
|
|
|
|
|
|
currentBorrowings.Skip(index * count).Take(count)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<Tuple<long, IEnumerable<Contact>>> GetContacts(int index, int count)
|
|
|
|
public Task<Tuple<long, IEnumerable<Contact>>> GetContacts(int index, int count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Task.FromResult(Tuple.Create(Contacts.LongCount(), Contacts.Skip(index*count).Take(count)));
|
|
|
|
return Task.FromResult(
|
|
|
|
|
|
|
|
Tuple.Create(Contacts.LongCount(), Contacts.Skip(index * count).Take(count))
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|