public async Task <TModel> ReadOneByIdAsync <TModel>(BlogClient client, string documentId) where TModel : BaseDocumentModel { IAsyncCursor <TModel> filterFind = await client.GetCollection <TModel>().FindAsync(documentId.DocumentWithObjectId()); filterFind.MoveNext(); return(filterFind.Current.Single()); }
public async Task <bool> MarkDocumentAsValidAsync <TModel>(BlogClient client, string documentId) where TModel : BaseDocumentModel { UpdateDefinition <TModel> updateDefinition = Builders <TModel> .Update.Set("IsInvalid", false); UpdateResult result = await client.GetCollection <TModel>().UpdateOneAsync(documentId.DocumentWithObjectId(), updateDefinition); return(result.ModifiedCount == 1); }
public async Task <bool> DeleteOneWithResultAsync <TModel>(BlogClient client, string documentId) where TModel : BaseDocumentModel { IMongoCollection <TModel> collection = client.GetCollection <TModel>(); DeleteResult result = await collection.DeleteOneAsync(documentId.DocumentWithObjectId()); return(result.DeletedCount == 1); }
public BlogClient(IConfiguration configuration) { Database = configuration.GetSection("Database").Value; if (_connection.IsObjectNull()) { MongoClientSettings settings = MongoClientSettings.FromUrl(new MongoUrl(configuration.GetConnectionString("mongoazure"))); settings.SslSettings = new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 }; _connection = new BlogClient(settings); } }
public TSelect ReadOneAsync <TModel, TSelect>(BlogClient client, Func <TModel, bool> where, Func <TModel, TSelect> select) where TModel : BaseDocumentModel { return(client.GetCollection <TModel>().AsQueryable().Where(where).Select(select).First()); }
public async Task <TModel> ReadOneAsync <TModel>(BlogClient client, Func <TModel, bool> func) where TModel : BaseDocumentModel { return(await Task.Run(() => client.GetCollection <TModel>().AsQueryable().Where(func).First())); }
public IEnumerable <TModel> ReadAll <TModel>(BlogClient client, Func <TModel, bool> func, ReadModeEnum mode = ReadModeEnum.Valid) where TModel : BaseDocumentModel { return(client.GetCollection <TModel>().BaseQueryAsParallel(mode).Where(func)); }
public async Task <List <TModel> > ReadAllAsync <TModel>(BlogClient client, ReadModeEnum mode = ReadModeEnum.Valid) where TModel : BaseDocumentModel { return(await Task.Run(() => client.GetCollection <TModel>().BaseQueryAsParallel(mode).ToList())); }
public async Task InsertOneAsync <TModel>(BlogClient client, TModel insertModel) where TModel : BaseDocumentModel { await client.GetCollection <TModel>().InsertOneAsync(insertModel); }
public async Task DeleteOneAsync <TModel>(BlogClient client, string documentId) where TModel : BaseDocumentModel { IMongoCollection <TModel> collection = client.GetCollection <TModel>(); await collection.FindOneAndDeleteAsync(documentId.DocumentWithObjectId()); }
public async Task <string> InsertOneGetIdAsync <TModel>(BlogClient client, TModel insertModel) where TModel : BaseDocumentModel { await client.GetCollection <TModel>().InsertOneAsync(insertModel); return(insertModel.DocumentId.ToString()); }
public async Task <bool> UpdateOneAsync <TModel>(BlogClient client, string documentId, UpdateDefinition <TModel> update) where TModel : BaseDocumentModel { UpdateResult result = await client.GetCollection <TModel>().UpdateOneAsync(documentId.DocumentWithObjectId(), update); return(result.ModifiedCount == 1); }