예제 #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
        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);
        }