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); }
// 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); }
public bool Register(UserRegistrationModel model) { var filterBuilder = Builders <User> .Filter; var filter = filterBuilder.Eq(x => x.UserName, model.Username) | filterBuilder.Eq(x => x.Email, model.Email); var duplicateEntity = _database.FindOneByFilter(User.CollectionName, filter); // TODO: Return message that there is a duplicate and which one is duplicate. if (duplicateEntity != null) { return(false); } string plainPassword = model.Password; string hashedPassword = HashHelp.GetSha512Hash(plainPassword); var user = new User(model.Username, hashedPassword, model.Email); _database.Create(user, User.CollectionName); return(true); }
public void Create(string title, string author) { var book = new Book(title, author); _database.Create(book, Book.CollectionName); }