Beispiel #1
0
        /// <summary>
        /// FindCursor
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="filter"></param>
        /// <returns>A cursor for the query</returns>
        public IFindFluent <TEntity, TEntity> FindCursor <TEntity>(FilterDefinition <TEntity> filter) where TEntity : class, new()
        {
            var res        = new GetManyResult <TEntity>();
            var collection = GetCollection <TEntity>();
            var cursor     = collection.Find(filter);

            return(cursor);
        }
Beispiel #2
0
        /// <summary>
        /// A generic get many method
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="ids"></param>
        /// <returns></returns>
        public async Task <GetManyResult <TEntity> > GetMany <TEntity>(IEnumerable <string> ids) where TEntity : class, new()
        {
            try
            {
                var collection = GetCollection <TEntity>();
                var filter     = Builders <TEntity> .Filter.Eq("Id", ids);

                return(await GetManyAsync <TEntity>(filter));
            }
            catch (Exception ex)
            {
                var res = new GetManyResult <TEntity>();
                res.Message = HelperService.NotifyException("GetMany", "Exception getting many " + typeof(TEntity).Name + "s", ex);
                return(res);
            }
        }
Beispiel #3
0
        /// <summary>
        /// A generic get all method
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <returns></returns>
        public GetManyResult <TEntity> GetAll <TEntity>() where TEntity : class, new()
        {
            var res = new GetManyResult <TEntity>();

            try
            {
                var collection = GetCollection <TEntity>();
                var entities   = collection.Find(new BsonDocument()).ToList();
                if (entities != null)
                {
                    res.Entities = entities;
                }
                res.Success = true;
                return(res);
            }
            catch (Exception ex)
            {
                res.Message = HelperService.NotifyException("GetAll", "Exception getting all " + typeof(TEntity).Name + "s", ex);
                return(res);
            }
        }
Beispiel #4
0
        /// <summary>
        /// A generic get many method with filter
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="ids"></param>
        /// <returns></returns>
        public async Task <GetManyResult <TEntity> > GetManyAsync <TEntity>(FilterDefinition <TEntity> filter) where TEntity : class, new()
        {
            var res = new GetManyResult <TEntity>();

            try
            {
                var collection = GetCollection <TEntity>();
                var entities   = await collection.Find(filter).ToListAsync();

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