/// <summary> /// Gets the current active lending for a book. /// Returns null if there is no active lending. /// </summary> public Lending GetCurrentLendingBook(ObjectId bookId) { var filterBuilder = Builders <Lending> .Filter; var filter = filterBuilder.Eq(x => x.BookId, bookId) & filterBuilder.Lt(x => x.StartDateUtc, new BsonDateTime(DateTime.UtcNow)) & filterBuilder.Gt(x => x.EndDateUtc, new BsonDateTime(DateTime.UtcNow)); var lending = _database.FindOneByFilter(Lending.CollectionName, filter); return(lending); }
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); }