Пример #1
0
        protected async override void OnAppearing()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            ViewModel.ErrorMessage = "";
            base.OnAppearing();
            IProgressDialog progress = null;

            try
            {
                progress = UserDialogs.Instance.Loading(TranslateServices.GetResourceString(CommonConstants.DialogLoading), maskType: MaskType.Clear);
                progress.Show();

                InitContributionType();
                await BindContributionAreas();

                BindingSelectors();
            }
            catch (Exception ex)
            {
                await UserDialogs.Instance.AlertAsync(string.Format(CommonConstants.DialogDescriptionForCheckNetworkFormat, ex.Message), TranslateServices.GetResourceString(CommonConstants.DialogOK));
            }
            finally
            {
                progress?.Hide();
                IsBusy = false;
            }
        }
Пример #2
0
 private async void ButtonLearnMore_Clicked(object sender, EventArgs e)
 {
     try
     {
         await Plugin.Share.CrossShare.Current.OpenBrowser(CommonConstants.LearnMoreUrl, new Plugin.Share.Abstractions.BrowserOptions
         {
             ChromeShowTitle    = true,
             ChromeToolbarColor = new Plugin.Share.Abstractions.ShareColor {
                 R = 3, G = 169, B = 244, A = 255
             },
             SafariBarTintColor = new Plugin.Share.Abstractions.ShareColor {
                 R = 3, G = 169, B = 244, A = 255
             },
             UseSafariWebViewController = true,
             SafariControlTintColor     = new Plugin.Share.Abstractions.ShareColor {
                 R = 255, G = 255, B = 255, A = 255
             },
             UseSafariReaderMode = false
         });
     }
     catch (Exception ex)
     {
         await DisplayAlert(TranslateServices.GetResourceString(CommonConstants.DialogTitleForError), TranslateServices.GetResourceString(CommonConstants.DialogDescriptionForError), TranslateServices.GetResourceString(CommonConstants.DialogOK));
     }
 }
Пример #3
0
        private async void Browser_Navigating(object sender, WebNavigatingEventArgs e)
        {
            try
            {
                Uri liveUrl = new Uri(e.Url, UriKind.Absolute);
                if (liveUrl.AbsoluteUri.Contains("code="))
                {
                    if (Settings.GetSetting(CommonConstants.AuthCodeKey) != string.Empty)
                    {
                        MvpHelper.RemoveProperties();
                    }

                    var    regex     = new System.Text.RegularExpressions.Regex("code=([^&]+)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    string auth_code = regex.Match(liveUrl.AbsoluteUri).Groups[1].Value;

                    Settings.SetSetting(CommonConstants.AuthCodeKey, auth_code);
                    await LiveIdLogOnViewModel.Instance.GetAccessToken();

                    var profileTest = await MvpHelper.MvpService.GetProfile(LogOnViewModel.StoredToken);

                    if (profileTest == null || profileTest.MvpId == 0)
                    {
                        Logger.Log("Login-Invalid");
                        await DisplayAlert(string.Empty, TranslateServices.GetResourceString(CommonConstants.DialogDescriptionForInvalidCredentials), TranslateServices.GetResourceString(CommonConstants.DialogOK));

                        App.CookieHelper.ClearCookie();
                        LiveIdLogOnViewModel.Instance.SignOut();
                        await Navigation.PopModalAsync(true);
                    }
                    else
                    {
                        Logger.Log("Login-Valid");

                        switch (Device.RuntimePlatform)
                        {
                        case Device.iOS:
                            Application.Current.MainPage = new MainTabPageiOS();
                            break;

                        default:
                            Application.Current.MainPage = new MVPNavigationPage(new MainTabPage())
                            {
                                Title = "Microsoft MVP"
                            };
                            break;
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                UserDialogs.Instance.Alert(exp.Message);
                App.CookieHelper.ClearCookie();
                LiveIdLogOnViewModel.Instance.SignOut();
                await Navigation.PushModalAsync(new LogOn());
            }
        }
Пример #4
0
        public async void OnEdit(object sender, EventArgs eventArgs)
        {
            var mi = ((MenuItem)sender);

            var viewModel = new ContributionViewModel();

            viewModel.MyContribution = mi.CommandParameter as ContributionModel;
            await Navigation.PushModalAsync(new MVPNavigationPage(
                                                new ContributionDetail()
            {
                BindingContext = viewModel,
                Title = TranslateServices.GetResourceString(CommonConstants.ContributionDetailTitleForEditing)
            }));
        }
Пример #5
0
        private async void ButtonSignoutClicked(object sender, EventArgs e)
        {
            var confirm = await DisplayAlert(TranslateServices.GetResourceString(CommonConstants.DialogTitleForSignout), TranslateServices.GetResourceString(CommonConstants.DialogForSignoutConfirmTipText), TranslateServices.GetResourceString(CommonConstants.DialogForSignoutOKText), TranslateServices.GetResourceString(CommonConstants.DialogCancel));

            if (!confirm)
            {
                return;
            }


            Logger.Log("Logout");

            App.CookieHelper.ClearCookie();
            LiveIdLogOnViewModel.Instance.SignOut();

            await Navigation.PopToRootAsync();

            App.Current.MainPage = new LogOn();
        }
Пример #6
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            if (IsBusy)
            {
                return;
            }


            if (Settings.GetSetting(CommonConstants.TokenKey) != string.Empty)
            {
                IProgressDialog progress = null;
                try
                {
                    IsBusy   = true;
                    progress = UserDialogs.Instance.Loading(TranslateServices.GetResourceString(CommonConstants.RefreshTokenKey));
                    await LiveIdLogOnViewModel.GetNewAccessToken();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format(TranslateServices.GetResourceString(CommonConstants.RefreshTokenExceptionTip), ex.Message));
                }
                finally
                {
                    progress?.Hide();
                    IsBusy = false;
                }
            }

            if (LogOnViewModel.Instance.IsLoggedIn)
            {
                App.GoHome();
            }
            else
            {
                await logo.FadeTo(1, 500, Easing.CubicOut);

                await title.FadeTo(1, 1000, Easing.CubicOut);
            }
        }
Пример #7
0
        public async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (ListViewContributions.SelectedItem != null)
            {
                var viewModel = new ContributionViewModel();
                viewModel.MyContribution = e.SelectedItem as ContributionModel;
                //TODO: Check state of BugZilla bug : https://bugzilla.xamarin.com/show_bug.cgi?id=52248
                //Temporary fix for UWP - Currently ViewCell disable is not working ( cfr BugZilla link in todo )
                if (viewModel.MyContribution.ContributionEnableEditDelete)
                {
                    await Navigation.PushModalAsync(new MVPNavigationPage(
                                                        new ContributionDetail()
                    {
                        BindingContext = viewModel,
                        Title = TranslateServices.GetResourceString(CommonConstants.ContributionDetailTitleForEditing)
                    }));
                }

                ListViewContributions.SelectedItem = null;
            }
        }
Пример #8
0
        private async void ButtonSignIn_Clicked(object sender, EventArgs e)
        {
            if (CommonConstants.ClientId == "LIVE_ID")
            {
                App.GoHome();
                return;
            }


            if (LogOnViewModel.Instance.IsLoggedIn)
            {
                App.GoHome();
            }
            else if (!CrossConnectivity.Current.IsConnected)
            {
                await DisplayAlert(TranslateServices.GetResourceString(CommonConstants.DialogTitleForCheckNetwork),
                                   TranslateServices.GetResourceString(CommonConstants.DialogDescriptionForCheckNetwork),
                                   TranslateServices.GetResourceString(CommonConstants.DialogOK));
            }
            else
            {
                await Navigation.PushModalAsync(new NavigationPage(new LiveIdLogOn()));
            }
        }
Пример #9
0
        public void OnContributionTypeSelectedIndexChanged(object sender, EventArgs e)
        {
            if (contributionTypeSelector.SelectedIndex != -1)
            {
                //Method call every time when picker selection changed.
                var selectedValue = contributionTypeSelector.Items[contributionTypeSelector.SelectedIndex];
                ViewModel.ErrorMessageForTitle                = CommonConstants.HighlightMessageText;
                ViewModel.ErrorMessageForUrl                  = CommonConstants.HighlightMessageText;
                ViewModel.ErrorMessageForAnnualQuantity       = CommonConstants.HighlightMessageText;
                ViewModel.ErrorMessageForSecondAnnualQuantity = CommonConstants.HighlightMessageText;
                ViewModel.ErrorMessageForAnnualReach          = "";

                switch (selectedValue)
                {
                case CommonConstants.AT:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForArticle);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForArticle);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.Bsp:
                    ViewModel.IsSecondAnnualQuantityVisible = true;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForPosts);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForPosts);
                    ViewModel.SecondAnnualQuantityTipText   = TranslateServices.GetResourceString(CommonConstants.SecondAnnualQuantityTipTextForPosts);
                    ViewModel.IsNeededUrl                  = true;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.BA:
                case CommonConstants.Bca:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForBook);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForBook);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.CS:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForSamples);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForSamples);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = true;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.Cpt:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForProject);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForProject);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = true;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.Cbp:
                case CommonConstants.CO:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForConference);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForConference);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.FM:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForForumModerator);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForForumModerator);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.FP:
                    ViewModel.IsSecondAnnualQuantityVisible = true;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForForumParticipation);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForForumParticipation);
                    ViewModel.SecondAnnualQuantityTipText   = TranslateServices.GetResourceString(CommonConstants.SecondAnnualQuantityTipTextForumParticipation);
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = false;
                    ViewModel.IsNeededSecondAnnualQuantity = true;
                    break;

                case CommonConstants.Fpmf:
                    ViewModel.IsSecondAnnualQuantityVisible = true;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForForumParticipation);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForForumParticipation);
                    ViewModel.SecondAnnualQuantityTipText   = TranslateServices.GetResourceString(CommonConstants.SecondAnnualQuantityTipTextForumParticipation);
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.MS:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForMentorship);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForMentorship);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.Osp:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForOpenSource);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForOpenSource);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.OT:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForOther);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForOther);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.Pcf:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForFeedback);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForFeedback);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.Pgf:
                case CommonConstants.Pgfg:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForFeedback);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForFeedback);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.Pgi:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForFeedback);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForFeedback);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.Ptdp:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForFeedback);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForFeedback);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.SO:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForSiteOwner);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForSiteOwner);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.SC:
                case CommonConstants.SL:
                case CommonConstants.Sug:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForSpeaking);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForSpeaking);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.Tsm:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForSocialMedia);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForSocialMedia);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = true;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.Trfe:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForTranslationReviewFeedbackEditing);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForTranslationReviewFeedbackEditing);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.Ugo:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForUserGroupOwner);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForUserGroupOwner);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.VD:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForVideo);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForVideo);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = true;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.WB:
                    ViewModel.IsSecondAnnualQuantityVisible = false;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForVideo);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForVideo);
                    ViewModel.SecondAnnualQuantityTipText   = string.Empty;
                    ViewModel.IsNeededUrl                  = false;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                case CommonConstants.WP:
                    ViewModel.IsSecondAnnualQuantityVisible = true;
                    ViewModel.AnnualQuantityTipText         = TranslateServices.GetResourceString(CommonConstants.AnnualQuantityTipTextForWebsitePosts);
                    ViewModel.AnnualReachTipText            = TranslateServices.GetResourceString(CommonConstants.AnnualReachTipTextForWebsitePosts);
                    ViewModel.SecondAnnualQuantityTipText   = TranslateServices.GetResourceString(CommonConstants.SecondAnnualQuantityTipTextForWebsitePosts);
                    ViewModel.IsNeededUrl                  = true;
                    ViewModel.IsNeededAnnualQuantity       = true;
                    ViewModel.IsNeededSecondAnnualQuantity = false;
                    break;

                default:
                    break;
                }
            }
        }
Пример #10
0
        private bool CheckData()
        {
            var isValid = true;

            var title                = entryTitle.Text;
            var url                  = entryURL.Text;
            var annualQuantity       = entryAnnualQuantity.Text;
            var secondAnnualQuantity = entrySecondAnnualQuantity.Text;
            var annualReach          = entryAnnualReach.Text;

            if (string.IsNullOrEmpty(title))
            {
                ViewModel.ErrorMessageForTitle = string.Format(System.Globalization.CultureInfo.InvariantCulture, " {0} {1}", CommonConstants.HighlightMessageText, TranslateServices.GetResourceString(CommonConstants.RequiredFieldMessageText));
                isValid = false;
            }
            if (ViewModel.IsNeededUrl)
            {
                if (string.IsNullOrEmpty(url))
                {
                    ViewModel.ErrorMessageForUrl = string.Format(System.Globalization.CultureInfo.InvariantCulture, " {0} {1}", CommonConstants.HighlightMessageText, TranslateServices.GetResourceString(CommonConstants.InvalidUrlMessageText));
                    isValid = false;
                }
                else if (!Regex.IsMatch(url, CommonConstants.UrlPattern))
                {
                    ViewModel.ErrorMessageForUrl = string.Format(System.Globalization.CultureInfo.InvariantCulture, " {0} {1}", CommonConstants.HighlightMessageText, TranslateServices.GetResourceString(CommonConstants.InvalidUrlMessageText));
                    isValid = false;
                }
            }
            if (ViewModel.IsNeededAnnualQuantity)
            {
                if (annualQuantity != null)
                {
                    if (!Regex.IsMatch(annualQuantity, CommonConstants.NumberPattern))
                    {
                        ViewModel.ErrorMessageForAnnualQuantity = string.Format(System.Globalization.CultureInfo.InvariantCulture, " {0} {1}", CommonConstants.HighlightMessageText, TranslateServices.GetResourceString(CommonConstants.FieldMustbeNumberMessageText));
                        isValid = false;
                    }
                }
                else
                {
                    ViewModel.ErrorMessageForAnnualQuantity = string.Format(System.Globalization.CultureInfo.InvariantCulture, " {0} {1}", CommonConstants.HighlightMessageText, TranslateServices.GetResourceString(CommonConstants.RequiredFieldMessageText));
                    isValid = false;
                }
            }
            if (ViewModel.IsNeededSecondAnnualQuantity)
            {
                if (secondAnnualQuantity != null)
                {
                    if (!Regex.IsMatch(secondAnnualQuantity, CommonConstants.NumberPattern))
                    {
                        ViewModel.ErrorMessageForSecondAnnualQuantity = string.Format(System.Globalization.CultureInfo.InvariantCulture, " {0} {1}", CommonConstants.HighlightMessageText, TranslateServices.GetResourceString(CommonConstants.FieldMustbeNumberMessageText));
                        isValid = false;
                    }
                }
                else
                {
                    ViewModel.ErrorMessageForSecondAnnualQuantity = string.Format(System.Globalization.CultureInfo.InvariantCulture, " {0} {1}", CommonConstants.HighlightMessageText, TranslateServices.GetResourceString(CommonConstants.RequiredFieldMessageText));
                    isValid = false;
                }
            }
            if (annualReach != null)
            {
                if (!Regex.IsMatch(annualReach, CommonConstants.NumberPattern))
                {
                    ViewModel.ErrorMessageForAnnualReach = TranslateServices.GetResourceString(CommonConstants.FieldMustbeNumberMessageText);
                    isValid = false;
                }
            }

            return(isValid);
        }
Пример #11
0
        public async void ButtonSaveClicked(object sender, EventArgs e)
        {
            IProgressDialog progress = null;

            try
            {
                bool isValid = CheckData();
                if (!isValid)
                {
                    return;
                }

                if (!CrossConnectivity.Current.IsConnected)
                {
                    await UserDialogs.Instance.AlertAsync(TranslateServices.GetResourceString(CommonConstants.DialogDescriptionForCheckNetworkFormat1), TranslateServices.GetResourceString(CommonConstants.DialogTitleForCheckNetwork), TranslateServices.GetResourceString(CommonConstants.DialogOK));

                    return;
                }

                IsBusy   = true;
                progress = UserDialogs.Instance.Loading(TranslateServices.GetResourceString(CommonConstants.DialogSaving), maskType: MaskType.Clear);
                progress.Show();


                if (ViewModel.MyContribution == null)
                {
                    var model = new ContributionModel()
                    {
                        ContributionId         = "0",
                        ContributionType       = ViewModel.ContributionTypeNames[contributionTypeSelector.SelectedIndex],
                        ContributionTechnology = ViewModel.ContributionAreas[ContributionAreaSelector.SelectedIndex],
                        Visibility             = ViewModel.PersonGroups[PersonGroupSelector.SelectedIndex],
                        StartDate            = ContributionDateSelector.Date.ToUniversalTime(),
                        Title                = entryTitle.Text,
                        ReferenceUrl         = entryURL.Text,
                        Description          = entryDescription.Text,
                        AnnualQuantity       = Convert.ToInt32(entryAnnualQuantity.Text, System.Globalization.CultureInfo.InvariantCulture),
                        AnnualReach          = Convert.ToInt32(entryAnnualReach.Text, System.Globalization.CultureInfo.InvariantCulture),
                        SecondAnnualQuantity = Convert.ToInt32(entrySecondAnnualQuantity.Text, System.Globalization.CultureInfo.InvariantCulture)
                    };
                    var result = await MvpHelper.MvpService.AddContributionModel(model, LogOnViewModel.StoredToken);

                    if (result != null && result.ContributionId != "0")
                    {
                        Logger.Log("Activity-Added");
                        MvpHelper.SetLabelTextOfContribution(result);
                        MyProfileViewModel.Instance.List.Insert(0, result);
                    }
                    else
                    {
                        throw new Exception(MyProfileViewModel.Instance.ErrorMessage);
                    }
                }
                else
                {
                    ViewModel.MyContribution.ContributionType       = ViewModel.ContributionTypeNames[contributionTypeSelector.SelectedIndex];
                    ViewModel.MyContribution.ContributionTechnology = ViewModel.ContributionAreas[ContributionAreaSelector.SelectedIndex];
                    ViewModel.MyContribution.Visibility             = ViewModel.PersonGroups[PersonGroupSelector.SelectedIndex];
                    ViewModel.MyContribution.StartDate            = ContributionDateSelector.Date.ToUniversalTime();
                    ViewModel.MyContribution.AnnualQuantity       = Convert.ToInt32(entryAnnualQuantity.Text, System.Globalization.CultureInfo.InvariantCulture);
                    ViewModel.MyContribution.AnnualReach          = Convert.ToInt32(entryAnnualReach.Text, System.Globalization.CultureInfo.InvariantCulture);
                    ViewModel.MyContribution.SecondAnnualQuantity = Convert.ToInt32(entrySecondAnnualQuantity.Text, System.Globalization.CultureInfo.InvariantCulture);
                    string result = await MvpHelper.MvpService.EditContributionModel(ViewModel.MyContribution, LogOnViewModel.StoredToken);

                    if (result == CommonConstants.OkResult)
                    {
                        Logger.Log("Activity-Edit");
                        MyProfileViewModel.Instance.List = new ObservableRangeCollection <ContributionModel>(MyProfileViewModel.Instance.List);
                    }
                    else
                    {
                        var currentContribution = MyProfileViewModel.Instance.List.Where(item => item.ContributionId == ViewModel.MyContribution.ContributionId).FirstOrDefault();
                        int index = MyProfileViewModel.Instance.List.IndexOf(currentContribution);
                        MyProfileViewModel.Instance.List.Remove(currentContribution);
                        MyProfileViewModel.Instance.List.Insert(index, ViewModel.MyContributionBackup);
                        throw new Exception(MyProfileViewModel.Instance.ErrorMessage);
                    }
                }

                ViewModel.MyContribution = null;

#if DEBUG
                await Task.Delay(3000);
#endif

                progress?.Hide();

                await UserDialogs.Instance.AlertAsync(TranslateServices.GetResourceString(CommonConstants.DialogDescriptionForSaved), TranslateServices.GetResourceString(CommonConstants.DialogTitleForSaved), TranslateServices.GetResourceString(CommonConstants.DialogOK));

                await Navigation.PopModalAsync();
            }
            catch (Exception ex)
            {
                progress?.Hide();
                ViewModel.ErrorMessage = ex.Message;
                await UserDialogs.Instance.AlertAsync(string.Format(TranslateServices.GetResourceString(CommonConstants.DialogDescriptionForUnableSave), ex.Message), TranslateServices.GetResourceString(CommonConstants.DialogOK));
            }
            finally
            {
                if (progress?.IsShowing ?? false)
                {
                    progress?.Hide();
                }
                IsBusy = false;
            }
        }