private async void AddLoadMoreProducts(EstateResultDto productResults) { switch (ProductFilters.Instance.ProductType) { case ProductType.None: await AddLoadMoreProducts(productResults, AllProductListView, Products); break; case ProductType.WillBeExpired: await AddLoadMoreProducts(productResults, OnExpiringListView, WillBeExpiredProducts); break; case ProductType.Expired: await AddLoadMoreProducts(productResults, ExpiredListView, ExpiredProducts); break; case ProductType.Deleted: await AddLoadMoreProducts(productResults, DeletedListView, DeletedProducts); break; } }
private void UpdateCanLoadMore(EstateResultDto productResults) { switch (ProductFilters.Instance.ProductType) { case ProductType.None: CanLoadMoreProduct = (productResults != null && productResults.EstateResults.Any() && productResults.TotalRecord > ProductFilters.Instance.PageIndex * ProductFilters.Instance.PageLimit); break; case ProductType.WillBeExpired: CanLoadMoreOnExpringProduct = (productResults != null && productResults.EstateResults.Any() && productResults.TotalRecord > ProductFilters.Instance.PageIndex * ProductFilters.Instance.PageLimit); break; case ProductType.Expired: CanLoadMoreExpiredProduct = (productResults != null && productResults.EstateResults.Any() && productResults.TotalRecord > ProductFilters.Instance.PageIndex * ProductFilters.Instance.PageLimit); break; case ProductType.Deleted: CanLoadMoreDeletedProduct = (productResults != null && productResults.EstateResults.Any() && productResults.TotalRecord > ProductFilters.Instance.PageIndex * ProductFilters.Instance.PageLimit); break; } }
private async Task <int> AddProducts(EstateResultDto productResults) { switch (ProductFilters.Instance.ProductType) { case ProductType.None: return(await AddProducts(productResults, AllProductListView, Products)); case ProductType.WillBeExpired: return(await AddProducts(productResults, OnExpiringListView, WillBeExpiredProducts)); case ProductType.Expired: return(await AddProducts(productResults, ExpiredListView, ExpiredProducts)); case ProductType.Deleted: return(await AddProducts(productResults, DeletedListView, DeletedProducts)); default: return(await AddProducts(productResults, AllProductListView, Products)); } }
private async Task <int> AddProducts(EstateResultDto productResults, SfListView targetListView, ObservableCollection <ProductItemViewModel> targetDataSource) { TaskCompletionSource <int> taskCompletionSource = new TaskCompletionSource <int>(); Device.BeginInvokeOnMainThread(() => { if (productResults != null && productResults.EstateResults != null) { targetListView.DataSource.BeginInit(); var products = productResults.EstateResults.Select(x => new ProductItemViewModel { Id = x.Id, ProductName = x.EstateCode, SalePrice = x.SalePrice ?? 0, SaleUnitId = x.SaleUnit != null ? x.SaleUnit.SaleUnitId ?? 0 : 0, SaleUnit = x.SaleUnit?.Name, RentPrice = x.RentPrice ?? 0, RentUnitId = x.RentUnit != null ? x.RentUnit.RentUnitId ?? 0 : 0, RentUnit = x.RentUnit?.Name, TownId = x.Town != null ? x.Town.TownId ?? 0 : 0, TownName = x.Town?.Name, ListingTypeId = x.Estate_TypeId ?? 0, ListingName = x.NameEstate_Type, HouseNumber = x.HouseNumber, StaffInfo = new StaffInfoViewModel { Name = $"{x.Account?.FirstName} {x.Account?.LastName}", Mobile = x.Account?.Mobile }, OwnerInfo = new OwnerInfoViewModel { Name = x.OwnerName, Mobile = x.Phone }, Area = x.Area, Notes = x.Note, CreatedDate = x.CreatedDate, UpdatedDate = x.ModifiedDate, IsDeleted = x.IsDelete ?? false, IsHot = x.IsHot ?? false, Lat = x.Lat, Long = x.Long, MainPinText = x.MainPinText, Address = x.Address, ImageUrls = x.ImageUrls, CreatorId = (int)(x.Account != null ? x.Account.AccountId ?? 0 : 0) }).ToList(); targetDataSource.Clear(); foreach (var item in products) { targetDataSource.Add(item); } targetListView.DataSource.EndInit(); taskCompletionSource.SetResult(1); } else { targetDataSource.Clear(); taskCompletionSource.SetResult(0); } UpdateCanLoadMore(productResults); }); return(await taskCompletionSource.Task); }
private async Task <int> AddLoadMoreProducts(EstateResultDto productResults) { TaskCompletionSource <int> taskCompletionSource = new TaskCompletionSource <int>(); Device.BeginInvokeOnMainThread(() => { try { if (productResults != null && productResults.EstateResults != null) { var items = productResults.EstateResults.Select(x => new ProductItemViewModel { Id = x.Id, ProductName = x.EstateCode, SalePrice = x.SalePrice ?? 0, SaleUnitId = x.SaleUnit != null ? x.SaleUnit.SaleUnitId ?? 0 : 0, SaleUnit = x.SaleUnit?.Name, RentPrice = x.RentPrice ?? 0, RentUnitId = x.RentUnit != null ? x.RentUnit.RentUnitId ?? 0 : 0, RentUnit = x.RentUnit?.Name, TownId = x.Town != null ? x.Town.TownId ?? 0 : 0, TownName = x.Town?.Name, ListingTypeId = x.Estate_TypeId ?? 0, ListingName = x.NameEstate_Type, HouseNumber = x.HouseNumber, StaffInfo = new StaffInfoViewModel { Name = $"{x.Account?.FirstName} {x.Account?.LastName}", Mobile = x.Account?.Mobile }, OwnerInfo = new OwnerInfoViewModel { Name = x.OwnerName, Mobile = x.Phone }, Area = x.Area, Notes = x.Note, CreatedDate = x.CreatedDate, UpdatedDate = x.ModifiedDate, IsDeleted = x.IsDelete ?? false, IsHot = x.IsHot ?? false, Lat = x.Lat, Long = x.Long, MainPinText = x.MainPinText, Address = x.Address, ImageUrls = x.ImageUrls, CreatorId = (int)(x.Account != null ? x.Account.AccountId ?? 0 : 0) }); foreach (var item in items) { Products.Add(item); } var indexTo = Products.Count - ProductFilters.Instance.PageLimit; ProductListView.LayoutManager.ScrollToRowIndex(indexTo, Syncfusion.ListView.XForms.ScrollToPosition.End, true); ProductListView.ScrollTo(indexTo, Syncfusion.ListView.XForms.ScrollToPosition.End, true); taskCompletionSource.SetResult(1); } CanLoadMore = CheckCanLoadMore(productResults); } catch (Exception ex) { taskCompletionSource.SetResult(0); } }); return(await taskCompletionSource.Task); }
private bool CheckCanLoadMore(EstateResultDto productResults) { return(productResults != null && productResults.EstateResults.Any() && productResults.TotalRecord > ProductFilters.Instance.PageIndex * ProductFilters.Instance.PageLimit); }