public void LendBook(ObjectId userId, ObjectId bookId, DateTime startDateUtc, DateTime endDateUtc) { // Check if dates are logical. if (startDateUtc > endDateUtc) { return; } // Check if lending time is not exceeding maximum. var lendTime = endDateUtc.Subtract(startDateUtc); if (lendTime.TotalDays > _maximumLendingTimeInDays) { return; } // Check if book exists. if (_database.FindOneById <Book>(Book.CollectionName, bookId) == null) { return; } // Check if book is currently lent out. if (GetCurrentLendingBook(bookId) != null) { return; } // Create a new lending. var lending = new Lending(userId, bookId, startDateUtc, endDateUtc); _database.Create(lending, Lending.CollectionName); }
public ActionResult Details(string id) { var objectId = new ObjectId(id); var book = _database.FindOneById <Book>(Book.CollectionName, objectId); return(View(new BookViewModel { Id = book.Id.ToString(), Author = book.Author, Title = book.Title })); }
// TODO: return position. public void CreateReservation(ObjectId userId, ObjectId bookId) { // Check if book exists. if (_database.FindOneById <Book>(Book.CollectionName, bookId) == null) { return; } // Check for active lending. var lending = _lendService.GetCurrentLendingBook(bookId); if (lending == null) { // Book can be lend, so no need to create reservation. // TODO: Maybe return useful message? return; } var reservation = new Reservation(userId, bookId, DateTime.UtcNow); _database.Create(reservation, Reservation.CollectionName); }