示例#1
0
        public Task <CollectionOfEntities <TEntity> > Get(int start, int count, EntitySortingEnum sort, params Func <TEntity, bool>[] filters)
        {
            var result = new CollectionOfEntities <TEntity>();
            IEnumerable <TEntity> collection = null;

            if (filters != null && filters.Length > 0)
            {
                collection = _entities.Where(filters[0]);

                for (int i = 1; i < filters.Length; i++)
                {
                    collection = collection.Where(filters[i]);
                }
            }
            else
            {
                collection = _entities.ToList();
            }

            result.Total         = collection.Count();
            result.Start         = start;
            result.EntitySorting = sort;

            var x = count == 0 ? result.Total - start : count;

            result.Entities = GetSorting(collection, sort).Skip(start).Take(x);
            result.Count    = result.Entities.Count();

            return(Task.FromResult(result));
        }
示例#2
0
        public virtual async Task <PaginationResponseApiModel <IBaseApiModel <TKey>, TSorting> > GetAsync(int start, int count,
                                                                                                          List <TSorting> sortings, TypeModelResponseEnum modelResponseType, int?langId = null, string query = null)
        {
            CollectionOfEntities <TEntity, TSorting> pagination = null;
            var type = typeof(TEntity);
            List <Expression <Func <TEntity, bool> > > filters = new List <Expression <Func <TEntity, bool> > >();

            if (type.GetInterface(typeof(IBaseLanguageEntity <TKey>).Name) != null && langId != null)
            {
                filters.Add(x => ((IBaseLanguageEntity <TKey>)x).LanguageId.Equals(langId));
            }
            if (!string.IsNullOrEmpty(query) && type.GetInterface(typeof(IBaseManualEntity <TKey>).Name) != null)
            {
                var q = query.ToLower();
                filters.Add(x => ((IBaseManualEntity <TKey>)x).Title != null && ((IBaseManualEntity <TKey>)x).Title.ToLower().Contains(q));
            }

            if (filters.Count > 0)
            {
                pagination = await _repository.GetAsync(start, count, sortings, filters?.ToArray());
            }
            else
            {
                pagination = await _repository.GetAsync(start, count, sortings);
            }

            var result = GetParsedPaginationResult(pagination.Entities, modelResponseType, pagination.Total, pagination.Start,
                                                   pagination.Count, pagination.EntitySortings);

            return(result);
        }
示例#3
0
        public async Task <CollectionOfEntities <User, UserSortingEnum> > GetManagersAsync(int start, int count,
                                                                                           List <UserSortingEnum> sortings, int langId)
        {
            var         result   = new CollectionOfEntities <User, UserSortingEnum>();
            List <User> entities = null;

            var models = (await _userRoleRepository.WhereAsync(x => x.RoleId != RoleHelper.Current.User.Id &&
                                                               x.RoleId != RoleHelper.Current.Customer.Id))?.ToList();

            if (models != null && models.Count > 0)
            {
                entities = models.Select(x => x.User)?.ToList()
                           .Where(y => y.UserProfile.LanguageId == langId)?.ToList();
            }

            entities = entities?.Distinct().ToList();

            result.Total          = entities?.Count() ?? 0;
            result.Start          = start;
            result.EntitySortings = sortings;

            var x = count == 0 ? result.Total - start : count;

            result.Entities = SortCollection(entities ?? new List <User>(), sortings).Skip(start).Take(x);
            result.Count    = result.Entities.Count();

            return(result);
        }
示例#4
0
        public async Task <CollectionOfEntities <User> > GetUsers(int start, int count, EntitySortingEnum sort)
        {
            var         result     = new CollectionOfEntities <User>();
            List <User> collection = null;

            var models = (await _userRoleRepository.WhereAsync(x => x.RoleId == RoleHelper.Current.User.Id)).ToList();

            if (models != null && models.Count > 0)
            {
                collection = models.Select(x => x.User).ToList()
                             .Where(y => y.UserProfile.Id != null).ToList();
            }

            collection = collection.Distinct().ToList();

            result.Total         = collection.Count();
            result.Start         = start;
            result.EntitySorting = sort;

            var x = count == 0 ? result.Total - start : count;

            result.Entities = GetSorting(collection, sort).Skip(start).Take(x);
            result.Count    = result.Entities.Count();

            return(result);
        }
示例#5
0
        public Task <CollectionOfEntities <TEntity> > Get(int start, int count, EntitySortingEnum sort)
        {
            var result = new CollectionOfEntities <TEntity>();

            result.Total         = _entities.Count();
            result.Start         = start;
            result.EntitySorting = sort;

            var x = count == 0 ? result.Total - start : count;

            result.Entities = GetSorting(_entities, sort).Skip(start).Take(x);
            result.Count    = result.Entities.Count();

            return(Task.FromResult(result));
        }
示例#6
0
        public virtual async Task <CollectionOfEntities <TEntity, TSorting> > GetAsync(int start, int count, List <TSorting> sortings)
        {
            var result   = new CollectionOfEntities <TEntity, TSorting>();
            var entities = await _repository.GetAsync();

            result.Total          = entities?.Count() ?? 0;
            result.Start          = start;
            result.EntitySortings = sortings;

            var x = count == 0 ? result.Total - start : count;

            result.Entities = SortCollection(entities, sortings).Skip(start).Take(x);
            result.Count    = result.Entities.Count();

            return(result);
        }