/// <summary> /// Indexes this instance. /// </summary> /// <param name="parametersSearch">The parameters search.</param> /// <param name="pageSizeString">The page size string.</param> /// <param name="page">The page.</param> /// <returns></returns> public async Task <IActionResult> Index(string parametersSearch, string pageSizeString, int page) { int pageSize = 20; page = page > 0 ? page : 1; if (!string.IsNullOrEmpty(pageSizeString)) { pageSize = int.Parse(pageSizeString); } BaseRequest request = new BaseRequest() { Page = new PagingRequest() { PageIndex = page - 1, PageSize = pageSize } }; try { ProductListViewModel model = null; if (!string.IsNullOrEmpty(parametersSearch)) { request = JsonConvert.DeserializeObject <BaseRequest>(parametersSearch); } request.Page = new PagingRequest() { PageIndex = page - 1, PageSize = pageSize }; var result = await this.PostAsync <BaseModel <Product> >(HttpUriFactory.GetProductsRequest(this.options.Value.APIUrl), request); if (result != null) { int pageCount = (result.TotalCount + pageSize - 1) / pageSize; var nextPage = page == pageCount ? page : (page + 1); var previousPage = page > 1 ? (page - 1) : page; model = this.CreateDefaultVM <ProductListViewModel, BaseRequest>(request, parametersSearch, page, pageSize, nextPage, previousPage, pageCount, "Product", "Index"); model.Templates = result.Models; } else { model = this.CreateDefaultVM <ProductListViewModel, BaseRequest>(request, parametersSearch, page, pageSize, 1, 1, 1, "Product", "Index"); } if (TempData["Message"] != null) { ViewBag.Message = TempData["Message"]; } return(View(model)); } catch (Exception ex) { ViewBag.Message = ex.Message; Utilities.LogAppError(this.logger, ex); return(View(this.CreateDefaultVM <ProductListViewModel, BaseRequest>(request, parametersSearch, page, pageSize, 1, 1, 1, "Product", "Index"))); } }
/// <summary> /// Gets the roles. /// </summary> /// <param name="roles">The roles.</param> /// <returns></returns> private IEnumerable <SelectListItem> GetProducts() { var result = this.PostAsync <BaseModel <Product> >(HttpUriFactory.GetProductsRequest(this.options.Value.APIUrl), new BaseRequest()).Result; if (result != null) { return(result.Models.Select(r => new SelectListItem { Text = r.Name, Value = r.Id.ToString(), })); } return(null); }