public FindResponse FindRoles(FindRequest request) { var response = new FindResponse(); using (var db = DbContext) { var query = db.Roles.AsQueryable(); if (!string.IsNullOrWhiteSpace(request.Name)) { request.Name = request.Name.ToStr().Trim().ToLower(); query = query.Where(i => i.Name.ToLower().Contains(request.Name) || i.Description.ToLower().Contains(request.Name)); } query = request.IsSortingValid ? request.ApplySortOption(query) : request.ApplyPageOption(query.OrderBy(q => q.Name)); var pagingResult = request.ApplyPageOption(query).ToList(); response.TotalRecords = query.Count(); response.Results = pagingResult.MapList<Role>(); } return response; }
public ActionResult Index(RoleIndexModel model) { model.InitSortInfo(); if (string.IsNullOrWhiteSpace(model.SortBy)) { model.SortBy = "Name"; } var filter = new FindRequest { Name = model.Name, SortOption = new SortOption(new[] { new SortItem(model.SortBy, model.SortDirection.Value) }), PageOption = new PageOption { PageSize = model.Pagination.PageSize, PageNumber = model.Pagination.CurrentPageIndex } }; var response = ServiceHelper.Role.ExecuteDispose(s => s.FindRoles(filter)); model.Results = response.Results.MapList<RoleModel>(); model.Pagination.TotalRecords = response.TotalRecords; return View(model); }
public FindResponse FindRoles(FindRequest request) { return Execute(_repository, r => r.FindRoles(request)); }