Exemple #1
0
        public async Task <IPagination <BanCanMiaModel> > GetPagingAsync(int index, int size, string keyword = null, string orderCol = null, string orderType = null)
        {
            var predicate = new List <Expression <Func <BanCanMia, bool> > > {
                x => true
            };


            if (!string.IsNullOrEmpty(keyword))
            {
                keyword = keyword.Trim();
                var keywords = keyword.Split(" ").ToList().Where(x => !string.IsNullOrEmpty(x));
                if (keywords.Count() > 0)
                {
                    foreach (var i in keywords)
                    {
                        predicate.Add(x =>
                                      x.Ma_Cttv.Equals(i) ||
                                      x.Ma_SoCa.Equals(i));
                    }
                }
            }

            Func <IQueryable <BanCanMia>, IOrderedQueryable <BanCanMia> > orderBy = null;

            if (!string.IsNullOrEmpty(orderCol))
            {
                if (!string.IsNullOrEmpty(orderType))
                {
                    orderBy = OrderByHelper.GetOrderBy <BanCanMia>(orderCol, orderType);
                }
            }

            var query = _repoBanCanMia.Query(predicate.Aggregate((a, b) => a.And(b)), orderBy);

            var data = await query.ToPaginateAsync <BanCanMia, BanCanMiaModel>(mapper, index, size, 0);

            return(data);
        }