public async void LoadData() { Utils.IReloadPageCurrent = this; this.IsBusy = true; mFistLoad = false; ColonyConcierge.APIData.Data.User userModel = null; try { if (Shared.IsLoggedIn) { userModel = await Shared.APIs.IUsers.GetCurrentUser_Async(); } } catch (Exception ex) { if (!this.IsErrorPage && Utils.IReloadPageCurrent == this) { Device.BeginInvokeOnMainThread(() => { Utils.ShowErrorMessage(ex); }); } } if (Utils.IReloadPageCurrent == this) { Utils.IReloadPageCurrent = null; } if (userModel != null) { EntryFullName.Text = userModel.FirstName + " " + userModel.LastName; EntryEmail.Text = userModel.EmailAddress; mId = userModel.ID; } this.IsBusy = false; }
public void LoadCard() { UserFacade userFacade = new UserFacade(); Device.BeginInvokeOnMainThread(() => { this.IsBusy = true; Task.Run(() => { Utils.IReloadPageCurrent = this; try { UserModel = Shared.APIs.IUsers.GetCurrentUser(); var zipCode = mServiceAddress.BasicAddress.ZipCode; if (Shared.IsLoggedIn) { Services = Shared.APIs.IServices.GetAvailableServicesForUser(Shared.UserId, null, null, zipCode); } else { Services = Shared.APIs.IServices.GetAvailableServices(zipCode); } if (Services != null) { var serviceKind = ColonyConcierge.APIData.Data.ServiceKindCodes.Restaurant_Delivery; if (RestaurantDetailPage.GroupedDeliveryDestination != null) { if (RestaurantDetailPage.GroupedService != null) { Services = Services.Where(s => s.ServiceType == ColonyConcierge.APIData.Data.ServiceTypes.Restaurant) .Where(s => s.ServiceKind == ServiceKindCodes.Restaurant_GroupedDelivery) .Where(s => s.DisplayName == RestaurantDetailPage.GroupedService.DisplayName) .ToList(); } else { Services = Services.Where(s => s.ServiceType == ColonyConcierge.APIData.Data.ServiceTypes.Restaurant) .Where(s => s.ServiceKind == ServiceKindCodes.Restaurant_GroupedDelivery) .ToList(); } } else { Services = Services.Where(s => s.ServiceType == ColonyConcierge.APIData.Data.ServiceTypes.Restaurant) .Where(s => s.ServiceKind == serviceKind) .ToList(); } if (Services.FirstOrDefault() != null) { var service = Shared.APIs.IServices.GetService(Services.FirstOrDefault().ID); if (service != null) { Services.FirstOrDefault().AllowedTipRates = service.AllowedTipRates; } } } } catch (Exception ex) { if (!this.IsErrorPage && Utils.IReloadPageCurrent == this) { Device.BeginInvokeOnMainThread(async() => { await Utils.ShowErrorMessage(string.IsNullOrEmpty(ex.Message) ? AppResources.SomethingWentWrong : ex.Message); }); } } if (Utils.IReloadPageCurrent == this) { Utils.IReloadPageCurrent = null; } ; }).ContinueWith((t) => { if (Services != null) { ServiceFee = Services.SelectMany(s => s.Fees).Sum(s => s.Amount); LabelServiceFee.Text = "$" + Math.Round(ServiceFee, 2).ToString("0.00"); PickerTips.Items.Clear(); var service = Services.FirstOrDefault(); if (service != null && service.AllowedTipRates != null && service.AllowedTipRates.Count > 0) { PickerTips.IsVisible = true; var allowedTipRates = service.AllowedTipRates.OrderByDescending((arg) => arg).ToList(); foreach (var tip in allowedTipRates) { if (tip == 0) { PickerTips.Items.Add(AppResources.Other); } else { PickerTips.Items.Add(Math.Round(tip * 100, 2).ToString("0.00") + "%"); } } if (PickerTips.Items.Count > 0) { PickerTips.SelectedIndex = 0; } } else { PickerTips.IsVisible = false; EntryServiceTips.IsEnabled = false; } UpdatePrice(); } this.IsBusy = false; }, TaskScheduler.FromCurrentSynchronizationContext()); }); }