public bool Borrow(string isbn, string cnp) { var searchedBookIndex = AvailableBooks.FindIndex(item => item.Book.ISBN == isbn); if (searchedBookIndex != -1 && AvailableBooks[searchedBookIndex].Quantity > 0 && _dependencyService.Get <IValidationService>().IsValidCNP(cnp)) { AvailableBooks[searchedBookIndex].Quantity--; var currentDate = DateTimeOffset.UtcNow; BorrowedBooks.Add(new Borrowing { CNP = cnp, ISBN = isbn, BorrowingPrice = AvailableBooks[searchedBookIndex].BorrowPrice, BorrowingStartDate = currentDate.ToUnixTimeMilliseconds().ToString(), BorrowingEndDate = currentDate.AddDays(AppConstants.MAX_LOAN_DAYS).ToUnixTimeMilliseconds().ToString() }); return(true); } else { return(false); } }
public bool AddExistingBook(string isbn, int quantity = 1) { var bookIndex = AvailableBooks.FindIndex(item => item.Book.ISBN == isbn); if ((bookIndex != -1) && _dependencyService.Get <IValidationService>().IsValidQuantity(quantity)) { AvailableBooks[bookIndex].Quantity += quantity; return(true); } return(false); }
public bool AddNewBook(Book book, double price, int quantity = 1) { var validationService = _dependencyService.Get <IValidationService>(); if (validationService.isValidBook(book) && validationService.IsValidPrice(price) && validationService.IsValidQuantity(quantity)) { var searchedIndex = AvailableBooks.FindIndex(item => item.Book.ISBN == book.ISBN); if (searchedIndex == -1) { AvailableBooks.Add(new BookProductInfo { Book = book, BorrowPrice = price, Quantity = quantity }); return(true); } } return(false); }