public WizardAdditionalTechnologyPageModel(MvpApiService mvpApiService) { _mvpApiService = mvpApiService; BackCommand = new AsyncCommand(() => Back()); NextCommand = new AsyncCommand(() => Next()); SelectionChangedCommand = new Command <IList <object> >((list) => SelectionChanged(list)); }
public ContributionDetailsPageModel(MvpApiService mvpApiService) { _mvpApiService = mvpApiService; BackCommand = new AsyncCommand(() => Back()); DeleteContributionCommand = new AsyncCommand(() => DeleteContribution()); EditContributionCommand = new AsyncCommand(() => EditContribution(), (x) => CanBeEdited); }
async Task LoadContributionAreas() { if (Connectivity.NetworkAccess == NetworkAccess.Internet) { var categories = await MvpApiService.GetContributionAreasAsync().ConfigureAwait(false); if (categories != null) { var result = new List <MvvmHelpers.Grouping <string, ContributionTechnology> >(); foreach (var item in categories.SelectMany(x => x.ContributionAreas)) { result.Add(new MvvmHelpers.Grouping <string, ContributionTechnology>(item.AwardName, item.ContributionTechnology)); } GroupedContributionTechnologies = result; // Editing mode if (contribution.AdditionalTechnologies != null && contribution.AdditionalTechnologies.Any()) { var selectedValues = contribution.AdditionalTechnologies.Select(x => x.Id).ToList(); SelectedContributionTechnologies = result .SelectMany(x => x) .Where(x => selectedValues.Contains(x.Id)) .ToList(); RaisePropertyChanged(nameof(SelectedContributionTechnologies)); } } } }
/// <summary> /// Loads the contribution areas for the contribution. /// </summary> async Task LoadContributionAreas(bool force = false) { try { State = LayoutState.Loading; allCategories = await MvpApiService.GetContributionAreasAsync(force).ConfigureAwait(false); if (allCategories == null) { State = LayoutState.Error; return; } PopulateList(); } catch (Exception ex) { State = LayoutState.Error; AnalyticsService.Report(ex); } finally { if (State != LayoutState.Error) { State = GroupedContributionTechnologies.Count > 0 ? LayoutState.None : LayoutState.Empty; } } }
public ContributionsPageModel(MvpApiService mvpApiService) { _mvpApiService = mvpApiService; OpenProfileCommand = new AsyncCommand(OpenProfile); OpenContributionCommand = new AsyncCommand <Contribution>(OpenContribution); OpenAddContributionCommand = new AsyncCommand(OpenAddContribution); RefreshDataCommand = new AsyncCommand(RefreshContributions); LoadMoreCommand = new AsyncCommand(LoadMoreContributions); }
public void Instantiation() { // Arrange MvpApiService client = null; // Act client = new MvpApiService("12345"); // Assert Assert.IsNotNull(client); }
/// <summary> /// Deletes a contribution. /// </summary> async Task DeleteContribution() { try { // Shouldn't be getting here anyway, so no need for a message. if (!CanBeEdited) { return; } if (!await VerifyInternetConnection()) { return; } // Ask for confirmation before deletion. var confirm = await DialogService.ConfirmAsync(Translations.contributiondetail_deleteconfirmation, Translations.warning_title, Translations.ok, Translations.cancel).ConfigureAwait(false); if (!confirm) { return; } State = LayoutState.Loading; var isDeleted = await MvpApiService.DeleteContributionAsync(Contribution); if (isDeleted) { // TODO: Pass back true to indicate it needs to refresh. // TODO: Be a bit more sensible with muh threads plz. MainThread.BeginInvokeOnMainThread(() => HapticFeedback.Perform(HapticFeedbackType.LongPress)); AnalyticsService.Track("Contribution Deleted"); await MainThread.InvokeOnMainThreadAsync(() => BackAsync()); //MessagingService.Current.SendMessage(MessageKeys.HardRefreshNeeded); MessagingService.Current.SendMessage(MessageKeys.HardRefreshNeeded); } else { await DialogService.AlertAsync(Translations.contributiondetail_notdeleted, Translations.error_title, Translations.ok).ConfigureAwait(false); } } catch (Exception ex) { AnalyticsService.Report(ex); await DialogService.AlertAsync(Translations.error_unexpected, Translations.error_title, Translations.ok).ConfigureAwait(false); } finally { State = LayoutState.None; } }
async Task RefreshContributions() { Contributions.Clear(); contributions.Clear(); var contributionsList = await MvpApiService.GetContributionsAsync(0, pageSize).ConfigureAwait(false); if (contributionsList == null) { return; } Contributions = contributionsList.Contributions; }
/// <summary> /// Loads more contributions when scrolled to the bottom. /// </summary> async Task LoadMore() { if (IsLoadingMore) { return; } if (!await VerifyInternetConnection()) { return; } try { IsLoadingMore = true; var contributionsList = await MvpApiService.GetContributionsAsync(Contributions.Count, pageSize).ConfigureAwait(false); if (contributionsList == null) { await DialogService.AlertAsync(Translations.error_couldntloadmorecontributions, Translations.error_title, Translations.ok).ConfigureAwait(false); return; } foreach (var item in contributionsList.Contributions.OrderByDescending(x => x.StartDate)) { Contributions.Add(item); } AnalyticsService.Track("More Contributions Loaded"); // If we've reached the end, change the threshold. if (!contributionsList.Contributions.Any()) { ItemThreshold = -1; return; } } catch (Exception ex) { AnalyticsService.Report(ex); await DialogService.AlertAsync(Translations.error_couldntloadmorecontributions, Translations.error_title, Translations.ok).ConfigureAwait(false); } finally { IsLoadingMore = false; } }
public AwardQuestionsDialog(MvpApiService service) { this.apiService = service; this.InitializeComponent(); if (DesignMode.DesignModeEnabled || DesignMode.DesignMode2Enabled) { Items = DesignTimeHelpers.GenerateQuestionnaireItems(); } ItemsListView.ItemsSource = Items; Loaded += AwardQuestionsDialog_Loaded; }
public async Task InitializeMvpService() { // Grab the auth token and set it to the MVP service. var token = await SecureStorage.GetAsync("AccessToken").ConfigureAwait(false); var service = new MvpApiService(token); if (MvpApiService != null) { MvpApiService.AccessTokenExpired -= MvpApiService_AccessTokenExpired; MvpApiService.RequestErrorOccurred -= MvpApiService_RequestErrorOccurred; } service.AccessTokenExpired += MvpApiService_AccessTokenExpired; service.RequestErrorOccurred += MvpApiService_RequestErrorOccurred; MvpApiService = service; }
/// <summary> /// Loads the contribution areas for the contribution. /// </summary> async Task LoadContributionAreas(bool force = false) { try { State = LayoutState.Loading; allCategories = await MvpApiService.GetContributionAreasAsync(force).ConfigureAwait(false); if (allCategories == null) { State = LayoutState.Error; return; } PopulateList(); // Gather suggestions var suggestions = await SuggestionService.GetContributionTechnologySuggestions(); var items = allCategories .SelectMany(x => x.Contributions) .SelectMany(y => y.ContributionArea) .Where(x => suggestions.Contains(x.Id ?? Guid.Empty)); Suggestions = new List <ContributionTechnologyViewModel>(items .Select(x => new ContributionTechnologyViewModel { ContributionTechnology = x })); } catch (Exception ex) { State = LayoutState.Error; AnalyticsService.Report(ex); } finally { if (State != LayoutState.Error) { State = GroupedContributionTechnologies.Count > 0 ? LayoutState.None : LayoutState.Empty; } } }
private async void GetProfileInfoButton_OnClick(object sender, RoutedEventArgs e) { try { if (mvpApiService == null) { mvpApiService = new MvpApiService(Constants.SubscriptionKey, LoadToken("access_token")); } await LoadProfileAsync(); await LoadProfileImageAsync(); await LoadLatestContributionsAsync(); } catch (Exception exception) { Debug.WriteLine(exception); } }
/// <summary> /// Loads the contribution types from cache. /// </summary> /// <param name="force"></param> /// <returns></returns> async Task LoadContributionTypes(bool force = false) { try { State = LayoutState.Loading; var types = await MvpApiService.GetContributionTypesAsync(force).ConfigureAwait(false); if (types == null) { State = LayoutState.Error; return; } ContributionTypes = types .OrderBy(x => x.Name) .Select(x => new ContributionTypeViewModel { ContributionType = x }).ToList(); // Editing mode if (contribution.ContributionType.Value != null) { var selected = ContributionTypes.FirstOrDefault(x => x.ContributionType.Id == contribution.ContributionType.Value.Id); selected.IsSelected = true; } } catch (Exception ex) { State = LayoutState.Error; AnalyticsService.Report(ex); } finally { if (State != LayoutState.Error) { State = ContributionTypes.Count > 0 ? LayoutState.None : LayoutState.Empty; } } }
/// <summary> /// Refreshes the list of contributions. /// </summary> async Task RefreshContributions(bool refresh = false) { ItemThreshold = 2; if (Connectivity.NetworkAccess != NetworkAccess.Internet) { State = LayoutState.Custom; CustomStateKey = StateKeys.Offline; return; } try { State = LayoutState.Loading; var contributionsList = await MvpApiService.GetContributionsAsync(0, pageSize).ConfigureAwait(false); if (contributionsList == null) { State = LayoutState.Error; return; } Contributions = new ObservableCollection <Contribution>(contributionsList.Contributions.OrderByDescending(x => x.StartDate).ToList()); } catch (Exception ex) { AnalyticsService.Report(ex); State = LayoutState.Error; } finally { IsRefreshing = false; if (State != LayoutState.Error) { State = Contributions.Count > 0 ? LayoutState.None : LayoutState.Empty; } } }
/// <summary> /// Loads visibilities from cache. /// </summary> async Task LoadVisibilities(bool force = false) { try { State = LayoutState.Loading; var visibilities = await MvpApiService.GetVisibilitiesAsync(force).ConfigureAwait(false); if (visibilities == null) { State = LayoutState.Error; return; } Visibilities = visibilities.Select(x => new VisibilityViewModel() { Visibility = x }).ToList(); // Editing mode if (contribution.Visibility.Value != null) { var selectedVisibility = Visibilities.FirstOrDefault(x => x.Visibility.Id == contribution.Visibility.Value.Id); selectedVisibility.IsSelected = true; } } catch (Exception ex) { State = LayoutState.Error; AnalyticsService.Report(ex); } finally { if (State != LayoutState.Error) { State = Visibilities.Count > 0 ? LayoutState.None : LayoutState.Empty; } } }
public async void RequestAccessTokenAsync(string requestUrl, string authCode) { using (var client = new HttpClient()) { var content = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("client_id", Constants.ClientId), new KeyValuePair <string, string>("grant_type", "authorization_code"), new KeyValuePair <string, string>("code", authCode.Split('&')[0]), new KeyValuePair <string, string>("redirect_uri", RedirectUrl), }; var postContent = new FormUrlEncodedContent(content); using (var response = await client.PostAsync(new Uri(requestUrl), postContent)) { var responseTxt = await response.Content.ReadAsStringAsync(); var tokenData = JsonConvert.DeserializeObject <Dictionary <string, string> >(responseTxt); if (tokenData.ContainsKey("access_token")) { SaveToken("access_token", tokenData["access_token"]); SaveToken("refresh_token", tokenData["refresh_token"]); var cleanAccessToken = tokenData["access_token"].Split('&')[0]; mvpApiService = new MvpApiService(Constants.SubscriptionKey, cleanAccessToken); isLoggedIn = true; GetProfileInfoButton.IsEnabled = true; GetProfileInfoButton.Foreground = new SolidColorBrush(Colors.LimeGreen); LoginLogOutButton.Content = "logout"; } } } }
async Task DeleteContribution() { try { // Shouldn't be getting here anyway, so no need for a message. if (!Contribution.StartDate.IsWithinCurrentAwardPeriod()) { return; } // Ask for confirmation before deletion. var confirm = await DialogService.ConfirmAsync("Are you sure you want to delete this contribution? You cannot undo this.", Alerts.HoldOn, Alerts.OK, Alerts.Cancel); if (!confirm) { return; } var isDeleted = await MvpApiService.DeleteContributionAsync(Contribution); if (isDeleted) { // TODO: Pass back true to indicate it needs to refresh. await NavigationHelper.BackAsync().ConfigureAwait(false); } else { await DialogService.AlertAsync("Your contribution could not be deleted. Perhaps it was already deleted, or it took place in the previous award period?", Alerts.Error, Alerts.OK); } } catch (Exception ex) { AnalyticsService.Report(ex); await DialogService.AlertAsync(Alerts.UnexpectedError, Alerts.Error, Alerts.OK).ConfigureAwait(false); } }
/// <summary> /// Saves a contribution. /// </summary> async Task SaveContribution() { try { if (!await VerifyInternetConnection()) { return; } if (!Contribution.IsValid()) { IsContributionValid = false; return; } IsContributionValid = true; State = LayoutState.Saving; if (IsEditing) { var result = await MvpApiService.UpdateContributionAsync(Contribution.ToContribution()); if (!result) { await DialogService.AlertAsync(Translations.error_couldntsavecontribution, Translations.error_title, Translations.ok).ConfigureAwait(false); return; } MainThread.BeginInvokeOnMainThread(() => HapticFeedback.Perform(HapticFeedbackType.LongPress)); AnalyticsService.Track("Contribution Added"); await CloseModalAsync().ConfigureAwait(false);; await BackAsync().ConfigureAwait(false); MessagingService.Current.SendMessage(MessageKeys.RefreshNeeded); } else { var result = await MvpApiService.SubmitContributionAsync(Contribution.ToContribution()); if (result == null) { await DialogService.AlertAsync(Translations.error_couldntsavecontribution, Translations.error_title, Translations.ok).ConfigureAwait(false); return; } AnalyticsService.Track("Contribution Edited"); MainThread.BeginInvokeOnMainThread(() => HapticFeedback.Perform(HapticFeedbackType.LongPress)); await CloseModalAsync().ConfigureAwait(false); MessagingService.Current.SendMessage(MessageKeys.RefreshNeeded); } } catch (Exception ex) { AnalyticsService.Report(ex); await DialogService.AlertAsync(Translations.error_couldntsavecontribution, Translations.error_title, Translations.ok).ConfigureAwait(false); } finally { State = LayoutState.None; } }