public async Task <ProductPageListModel> GetProductsAsync(ProductFilterModel criterias) { if (criterias == null) { criterias = new ProductFilterModel(); } var filterRequest = new ProductFilter() { Page = criterias.Page, PageSize = _pagerOptions.PageSize, Keyword = criterias.Search, FarmId = criterias.FarmId }; try { var productPageList = await _productService.GetAsync(filterRequest); var products = await MapProductsResultToModelAsync(productPageList.Collections); var productPage = new ProductPageListModel(products) { Filter = criterias, TotalPage = productPageList.TotalPage, TotalResult = productPageList.TotalResult }; return(productPage); } catch (Exception) { throw; } }
public async Task <ProductPageListModel> GetUserProductsAsync(ClaimsPrincipal claimsPrincipal, ProductFilterModel criterias) { if (criterias == null) { criterias = new ProductFilterModel(); } if (string.IsNullOrEmpty(criterias.UserIdentityId)) { return(new ProductPageListModel(new List <ProductModel>()) { Filter = criterias }); } var currentUserId = GetCurrentUserId(claimsPrincipal); var userId = await _userManager.DecryptUserIdAsync(criterias.UserIdentityId); var filterRequest = new ProductFilter() { Page = criterias.Page, PageSize = _pagerOptions.PageSize, Keyword = criterias.Search, CreatedById = userId, CanGetInactived = currentUserId == userId }; try { var productPageList = await _productService.GetAsync(filterRequest); var products = await MapProductsResultToModelAsync(productPageList.Collections); var productPage = new ProductPageListModel(products) { Filter = criterias, TotalPage = productPageList.TotalPage, TotalResult = productPageList.TotalResult }; return(productPage); } catch (Exception) { throw; } }