Exemplo n.º 1
0
        public async Task <IActionResult> Index(TreeSearchViewModel searchModel)
        {
            var model = await _treeRepository.LoadAsyncCount(
                this.CurrentPage,
                this.PageSize,
                searchModel);

            this.TotalNumber = model.Item1;

            ViewBag.SearchModel = searchModel;

            return(View(model.Item2));
        }
Exemplo n.º 2
0
        public async Task <Tuple <int, List <TreeDTO> > > LoadAsyncCount(
            int skip = -1,
            int take = -1,
            TreeSearchViewModel model = null)
        {
            var query = Entities.Include(x => x.User).ProjectTo <TreeDTO>();

            if (!string.IsNullOrEmpty(model.NameFamily))
            {
                query = query.Where(x => x.User.FirstName.Contains(model.NameFamily) || x.User.LastName.Contains(model.NameFamily));
            }

            if (model.TreeNumber != null)
            {
                query = query.Where(x => x.TreeNumber == model.TreeNumber);
            }

            if (model.IsPlanted != null)
            {
                query = query.Where(x => x.IsPlanted == model.IsPlanted);
            }


            int Count = query.Count();

            query = query.OrderByDescending(x => x.Id);


            if (skip != -1)
            {
                query = query.Skip((skip - 1) * take);
            }

            if (take != -1)
            {
                query = query.Take(take);
            }

            return(new Tuple <int, List <TreeDTO> >(Count, await query.ToListAsync()));
        }