Exemplo n.º 1
0
        public ActionResult Info(FilterModel model)
        {
            const int size  = 20;
            var       param = "Id";

            var query = _context.Emloyees
                        .Select(q => new TableViewModel
            {
                Id               = q.Id,
                FirstName        = q.FirstName,
                Name             = q.Name,
                LastName         = q.LastName,
                Salary           = q.Salary,
                Language         = q.Language,
                DateOfEmployment = q.DateOfEmployment,
                DateOfDismissal  = q.DateOfDismissal,
                DateOfBirth      = q.DateOfBirth,
                Sex              = q.Sex,
                Citizenship      = new CitizenshipModel
                {
                    Id   = q.CitizenshipDescription.Id,
                    Name = q.CitizenshipDescription.Name
                },
                IsReadyForBusinessTrip = q.IsReadyForBusinessTrip,
                IsReadyForMoving       = q.IsReadyForMoving,
                DepartamentTitle       = q.Departament.Name
            });

            query = model.GetFilters()
                    .Aggregate(query, (current, filter) => current.Where(filter));

            var count = query.Count();

            param = (model.SortId != null) ? param = model.SortId : param;


            var sortedData = query.OrderBy(param, model.IsDesc)
                             .Skip((model.CurrentPage - 1) * size)
                             .Take(size)
                             .ToList();

            var page = (count % size == 0)
                ? count / size
                : count / size + 1;

            return(Json(new
            {
                list = sortedData,
                pages = page,
                currentPage = model.CurrentPage,
                paginator = GetPagesNums(model.CurrentPage, page),
                sortColumn = param
            }));
        }