コード例 #1
0
        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());
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: BlogClient.cs プロジェクト: Ratomir/MSNETWORK-18
        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);
            }
        }
コード例 #5
0
 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());
 }
コード例 #6
0
 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()));
 }
コード例 #7
0
 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));
 }
コード例 #8
0
 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()));
 }
コード例 #9
0
 public async Task InsertOneAsync <TModel>(BlogClient client, TModel insertModel) where TModel : BaseDocumentModel
 {
     await client.GetCollection <TModel>().InsertOneAsync(insertModel);
 }
コード例 #10
0
        public async Task DeleteOneAsync <TModel>(BlogClient client, string documentId) where TModel : BaseDocumentModel
        {
            IMongoCollection <TModel> collection = client.GetCollection <TModel>();

            await collection.FindOneAndDeleteAsync(documentId.DocumentWithObjectId());
        }
コード例 #11
0
        public async Task <string> InsertOneGetIdAsync <TModel>(BlogClient client, TModel insertModel) where TModel : BaseDocumentModel
        {
            await client.GetCollection <TModel>().InsertOneAsync(insertModel);

            return(insertModel.DocumentId.ToString());
        }
コード例 #12
0
        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);
        }