Exemplo n.º 1
0
        public ActionResult Grid(PagingOptions paging, SortOptions sorting, [ModelBinder(typeof(GridFilterModelBinder))]GridFilter filter)
        {
            var query = UnitOfWork.Repository<UserRequest>().Query().Include(x => x.User);

            if (!string.IsNullOrEmpty(filter.PropertyFilter.PropertyName) && filter.PropertyFilter.PropertyValue != string.Empty)
            {
                query = query.WhereFilter(x => _queryTranslater.PropertyFilter(x, filter.PropertyFilter.PropertyName, filter.PropertyFilter.PropertyValue));
            }

            int total;

            var userRequests = query.OrderBy(x => _queryTranslater.OrderByPropName(x, sorting.SortBy ?? "FirstName", sorting.Asc))
                .GetPage(paging.Page, paging.ItemsPerPage, out  total).ToList();

            paging.Total = total;
            if (string.IsNullOrEmpty(filter.PropertyFilter.PropertyName))
            {
                filter.PropertyFilter.PropertyName = "FirstName";
            }

            ViewBag.GridOptions = new GridOptions(false);
            // Temp solution. Just test purposes.
            ViewBag.PropertyValue = new List<SelectListItem>()
                {
                    new SelectListItem() {Text = "all" ,Value = ""},
                    new SelectListItem() {Text = "ccc", Value = "ccc"},
                    new SelectListItem() { Text = "nnn", Value = "nnn"}
                };

            var mappedResult = AutoMapper.Mapper.Map<IEnumerable<UserRequestItemModel>>(userRequests);

            return View(new ListModel(paging, sorting, filter, mappedResult));
        }
Exemplo n.º 2
0
 public ListModel(PagingOptions paging, SortOptions sorting, GridFilter filter, IEnumerable<IGridItem> list)
 {
     Paging = paging;
     List = list;
     Sort = sorting;
     Filter = filter;
 }
Exemplo n.º 3
0
        public ActionResult Grid(PagingOptions paging, SortOptions sorting, [ModelBinder(typeof(GridFilterModelBinder))]GridFilter filter)
        {
            var query = UnitOfWork.Repository<User>().Query().Include(x => x.Role);
            if (!string.IsNullOrEmpty(filter.AlphaFilter.AlphaPropName) && !string.IsNullOrEmpty(filter.AlphaFilter.BeginFrom))
            {
                query = query.WhereFilter(x => _queryTranslater.AlphaFilter(x, filter.AlphaFilter.AlphaPropName, filter.AlphaFilter.BeginFrom));
            }

            int total = 0;

            var users = query.OrderBy(x => _queryTranslater.OrderByPropName(x, sorting.SortBy ?? "UserName", sorting.Asc))
                .GetPage(paging.Page, paging.ItemsPerPage, out  total).ToList();

            paging.Total = total;
            if (string.IsNullOrEmpty(filter.AlphaFilter.AlphaPropName))
            {
                filter.AlphaFilter.AlphaPropName = "UserName";
            }

            var mappedResult = AutoMapper.Mapper.Map<IEnumerable<UserItemModel>>(users);
            return View(new ListModel(paging, sorting, filter, mappedResult));
        }
Exemplo n.º 4
0
 //NOTE: Just test purposes!
 //        [HttpGet]
 //        [AllowAnonymous]
 //        public ActionResult Grid(PagingOptions paging, SortOptions sorting)
 //        {
 //            IList<TestModel> list = new List<TestModel>();
 //            for (int i = 0; i < 15; i++)
 //            {
 //                list.Add(new TestModel()
 //                    {
 //                        Description = paging.Page.ToString() + "sd" + (15 - i).ToString(),
 //                        Id = i,
 //                        Name = paging.Page.ToString() + "sad" + (15 - i).ToString()
 //                    });
 //            }
 //            paging.Total = list.Count();
 //            ViewBag.Paging = paging;
 //
 //
 //            var propInfo = typeof (TestModel).GetProperty(sorting.SortBy ?? "Name");
 //            var orderedList = sorting.Asc
 //                                  ? list.OrderByPropName(x => propInfo.GetValue(x, null))
 //                                  : list.OrderByDescending(x => propInfo.GetValue(x, null));
 //            return
 //                View(new ListModel(paging, sorting,
 //                                   orderedList.Skip((paging.Page - 1)*paging.ItemsPerPage).Take(paging.ItemsPerPage)));
 //        }
 public ActionResult Grid(PagingOptions paging, SortOptions sorting, GridFilter filter)
 {
     throw new NotImplementedException();
 }