/* Function: loadSales * This function load sales from local database to the local variable (i.e. SalesList) that is binded to the MvxListView */ public async Task loadSales() { ObservableCollection <Sales> salestmp = new ObservableCollection <Sales>(); if (!string.IsNullOrEmpty(GlobalVars.myDetail.SalesmanId)) { var mySales = await salesDb.GetAllSalesWhere(GlobalVars.myDetail.SalesmanId); var tmp = mySales.OrderByDescending(s => s.DateCreated).ToList(); var customertmp = new Models.Customer(); //var countCustomer = await customerDb.Count(); //if (countCustomer == 0) if (CrossConnectivity.Current.IsConnected) { if (await CrossConnectivity.Current.IsRemoteReachable(ServerDatabaseApi.ipAddress, int.Parse(ServerDatabaseApi.port))) { await downloadCustomers(); } } foreach (SalesTable s in tmp) { customertmp = await customerDb.GetCustomerWhere(s.CustomerId); salestmp.Add(new Sales(s.DocumentNo, s.DateCreated, s.Location, s.TotalDiscountAmount, s.Total, s.CustomerId, customertmp.Name, customertmp.Address, s.isTransferred, s.isGPSEnabled)); } SalesList = salestmp; RaisePropertyChanged(() => SalesList); GlobalVars.salesListIsLoaded = true; } }