Пример #1
0
        public async Task <GetManyResult <TEntity> > GetAll()
        {
            var res = new GetManyResult <TEntity>();

            try
            {
                var collection = GetCollection();
                var entities   = await collection.Find(new BsonDocument()).ToListAsync();

                if (entities != null)
                {
                    res.Entities   = entities;
                    res.TotalCount = entities.Count;
                }

                res.Success = true;
                return(res);
            }
            catch (Exception ex)
            {
                res.Message = ExceptionHelper.NotifyException("GetAll",
                                                              string.Concat("Exception getting all ", typeof(TEntity).Name, "s"), ex);
                return(res);
            }
        }
Пример #2
0
        public async Task <GetManyResult <TEntity> > GetMany(IEnumerable <ObjectId> ids, int skip, int limit)
        {
            try
            {
                //var collection = GetCollection<TEntity>();
                var filter = Builders <TEntity> .Filter.Eq("_id", ids);

                return(await GetMany(filter, skip, limit));
            }
            catch (Exception ex)
            {
                var res = new GetManyResult <TEntity>
                {
                    Message = ExceptionHelper.NotifyException("GetMany",
                                                              string.Concat("Exception getting many ", typeof(TEntity).Name, "s"), ex)
                };
                return(res);
            }
        }
Пример #3
0
        public async Task <GetManyResult <TEntity> > GetMany(FilterDefinition <TEntity> filter, int skip, int limit)
        {
            var res = new GetManyResult <TEntity>();

            try
            {
                var collection = GetCollection();
                var entities   = await collection.Find(filter).Skip(skip).Limit(limit).ToListAsync();

                if (entities != null)
                {
                    res.Entities   = entities;
                    res.TotalCount = entities.Count;
                }
                res.Success = true;
                return(res);
            }
            catch (Exception ex)
            {
                res.Message = ExceptionHelper.NotifyException("GetMany",
                                                              string.Concat("Exception getting many ", typeof(TEntity).Name, "s"), ex);
                return(res);
            }
        }