public ProvidersListModel PrepareProvidersListModel(ProvidersSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } var direction = searchModel.Sort.Equals("asc") ? false : true; var providers = _customerService.GetProviders(searchQuery: searchModel.Query, sortField: searchModel.Field, pageIndex: searchModel.Page - 1, pageSize: searchModel.Perpage, orderByDec: direction); var model = new ProvidersListModel() { Data = providers.Select(p => p) }; model.Meta = new PageListMetadata { Page = providers.PageIndex + 1, Perpage = providers.PageSize, Pages = providers.TotalPages, Sort = searchModel.Sort, Field = searchModel.Field, Total = providers.TotalCount }; return(model); }
public IActionResult ProvidersList() { try { var formCollection = Request.Form; var searchModel = new ProvidersSearchModel(); if (!string.IsNullOrWhiteSpace(formCollection["pagination[page]"])) { searchModel.Page = int.Parse(formCollection["pagination[page]"]); } if (!string.IsNullOrWhiteSpace(formCollection["pagination[pages]"])) { searchModel.Pages = int.Parse(formCollection["pagination[pages]"]); } if (!string.IsNullOrWhiteSpace(formCollection["pagination[perpage]"])) { var pageSize = int.Parse(formCollection["pagination[perpage]"]); searchModel.Perpage = pageSize > 0 ? pageSize : 10; } if (!string.IsNullOrWhiteSpace(formCollection["pagination[total]"])) { searchModel.Total = int.Parse(formCollection["pagination[total]"]); } if (!string.IsNullOrWhiteSpace(formCollection["sort[field]"])) { searchModel.Field = formCollection["sort[field]"]; } if (!string.IsNullOrWhiteSpace(formCollection["sort[sort]"])) { searchModel.Sort = formCollection["sort[sort]"]; } if (!string.IsNullOrWhiteSpace(formCollection["query[providerSearch]"])) { searchModel.Query = formCollection["query[providerSearch]"]; } var model = _listFactory.PrepareProvidersListModel(searchModel); return(Json(model)); } catch (Exception ex) { } return(Json(new ProvidersListModel())); }