/// <summary> /// Renders the filter item. /// </summary> public async Task <IViewComponentResult> InvokeAsync(string url, ListRequestVM request, string propName, string title) { if (request == null || propName == null || title == null) { throw new ArgumentNullException(); } var prop = request.GetType().GetProperty(propName); if (prop == null) { throw new ArgumentException($"Request of type '{request.GetType().Name}' does not have a property '{propName}'."); } var cloneRequest = ListRequestVM.Clone(request); prop.SetValue(cloneRequest, prop.PropertyType.IsValueType ? Activator.CreateInstance(prop.PropertyType) : null); var vm = new ListItemFilterVM { Title = title, CancelUrl = ListRequestHelper.GetUrl(url, cloneRequest) }; return(View("~/Areas/Admin/Views/Components/ListItemFilter.cshtml", vm)); }
/// <summary> /// Renders the pagination control. /// </summary> public async Task <IViewComponentResult> InvokeAsync(string url, ListRequestVM request, int pageCount) { var result = new List <ListPaginatorPageVM>(); var pages = GetPageNumbers(request.Page, pageCount); var prevPage = (int?)null; foreach (var page in pages) { if (prevPage != null && prevPage != page - 1) { result.Add(new ListPaginatorPageVM { Title = "..." }); } var clone = ListRequestVM.Clone(request); clone.Page = page; var cloneUrl = ListRequestHelper.GetUrl(url, clone); result.Add(new ListPaginatorPageVM { Url = cloneUrl, Title = (page + 1).ToString(), IsCurrent = page == request.Page }); prevPage = page; } return(View("~/Areas/Admin/Views/Components/ListPaginator.cshtml", result)); }
/// <summary> /// Renders the sortable header. /// </summary> public async Task <IViewComponentResult> InvokeAsync(string url, ListRequestVM request, string propName, string title) { var vm = new ListHeaderVM { Title = title }; var cloneRequest = ListRequestVM.Clone(request); cloneRequest.Page = 0; if (cloneRequest.OrderBy == propName) { cloneRequest.OrderDescending = !cloneRequest.OrderDescending; vm.IsDescending = cloneRequest.OrderDescending; } else { cloneRequest.OrderBy = propName; cloneRequest.OrderDescending = false; } vm.Url = ListRequestHelper.GetUrl(url, cloneRequest); return(View("~/Areas/Admin/Views/Components/ListHeader.cshtml", vm)); }