Exemple #1
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            string platformName = Device.OS.ToString();

            if (LoginViewModel.Instance.IsLoggedIn)
            {
                try
                {
                    if (string.IsNullOrEmpty(MyProfileViewModel.Instance.StoreImageBase64Str))
                    {
                        MyProfileViewModel.Instance.StoreImageBase64Str = await MvpService.GetPhoto(LoginViewModel.StoredToken);
                    }
                }
                catch (Exception ex)
                {
                    MyProfileViewModel.Instance.StoreImageBase64Str = CommonConstants.DefaultPhoto;
                    MyProfileViewModel.Instance.ErrorMessage        = ex.Message;
                }

                await Navigation.PushModalAsync(new MyProfile());
            }
            else
            {
                var tabGesture = new TapGestureRecognizer();
                tabGesture.Tapped += TabGesture_Tapped;
                //Content.FindByName<Label>("loginButton" + platformName).GestureRecognizers.Add(tabGesture);
                Content.FindByName <Label>("loginBtn").GestureRecognizers.Add(tabGesture);
            }
        }
Exemple #2
0
        private async void TabGesture_Tapped(object sender, EventArgs e)
        {
            if (LoginViewModel.Instance.IsLoggedIn)
            {
                try
                {
                    var profile = await MvpService.GetProfile(LoginViewModel.StoredToken);

                    MvpHelper.SetDataToProfileViewModel(profile);
                    if (string.IsNullOrEmpty(MyProfileViewModel.Instance.StoreImageBase64Str))
                    {
                        MyProfileViewModel.Instance.StoreImageBase64Str = await MvpService.GetPhoto(LoginViewModel.StoredToken);
                    }
                }
                catch (Exception ex)
                {
                    MyProfileViewModel.Instance.StoreImageBase64Str = CommonConstants.DefaultPhoto;
                    MyProfileViewModel.Instance.ErrorMessage        = ex.Message;
                }

                await Navigation.PushModalAsync(new MyProfile());
            }
            else
            {
                await Navigation.PushModalAsync(new LiveIdLogin());
            }
        }
Exemple #3
0
        protected async override void OnAppearing()
        {
            listView.SelectedItem = null;

            MyProfileViewModel.Instance.ErrorMessage = "";
            stkOveryLay.IsVisible = true;

            base.OnAppearing();
            GetPhoto();
            GetProfile();
            if (MyProfileViewModel.Instance.List == null || MyProfileViewModel.Instance.List.Count == 0)
            {
                var contributions = await MvpService.GetContributions(-5, 10, LogOnViewModel.StoredToken);

                MvpHelper.SetContributionInfoToProfileViewModel(contributions);
                listView.HeightRequest = MyProfileViewModel.Instance.List.Count * 50;
            }

            if (string.Compare(CommonConstants.DefaultNetworkErrorString, MyProfileViewModel.Instance.ErrorMessage, StringComparison.OrdinalIgnoreCase) == 0)
            {
                MyProfileViewModel.Instance.StoreImageBase64Str = CommonConstants.DefaultPhoto;
                MyProfileViewModel.Instance.ErrorMessage        = CommonConstants.DefaultNetworkErrorString;
            }

            stkOveryLay.IsVisible = false;
        }
Exemple #4
0
        public IActionResult Index(string id, int page = 1)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Index", "Home"));
            }

            return(View(MvpService.GetModel(_searchService, _documentDB, id, page)));
        }
Exemple #5
0
        private async void GetProfile()
        {
            if (string.IsNullOrEmpty(MyProfileViewModel.Instance.FirstAwardValue))
            {
                try
                {
                    ProfileModel profile = null;

                    CheckCache();

                    CheckCacheItem();

                    if (cacheItem.ContainsKey(CommonConstants.ProfileCacheKey))
                    {
                        DateTime cachedDate  = DateTime.Parse(cacheItem[CommonConstants.ProfileCacheDateKey].ToString());
                        DateTime ExpiredDate = cachedDate.AddHours(24);
                        if (DateTime.Compare(ExpiredDate, DateTime.Now) > 0) //Valid data.
                        {
                            string profileString = cacheItem[CommonConstants.ProfileCacheKey].ToString();
                            profile = Newtonsoft.Json.JsonConvert.DeserializeObject <ProfileModel>(profileString);
                        }
                        else
                        {
                            profile = await MvpService.GetProfile(LogOnViewModel.StoredToken);

                            cacheItem[CommonConstants.ProfileCacheKey]     = Newtonsoft.Json.JsonConvert.SerializeObject(profile);
                            cacheItem[CommonConstants.ProfileCacheDateKey] = DateTime.Now;

                            cache[currentUserIdKey] = cacheItem;
                        }
                    }
                    else
                    {
                        profile = await MvpService.GetProfile(LogOnViewModel.StoredToken);

                        cacheItem.Add(CommonConstants.ProfileCacheKey, Newtonsoft.Json.JsonConvert.SerializeObject(profile));
                        cacheItem.Add(CommonConstants.ProfileCacheDateKey, DateTime.Now);

                        cache[currentUserIdKey] = cacheItem;
                    }

                    Application.Current.Properties[CommonConstants.ProfileCacheListKey] = cache;

                    if (profile != null)
                    {
                        MyProfileViewModel.Instance.FirstAwardValue      = profile.FirstAwardYear.ToString(System.Globalization.CultureInfo.CurrentCulture);
                        MyProfileViewModel.Instance.PersonName           = profile.DisplayName;
                        MyProfileViewModel.Instance.AwardCategoriesValue = profile.AwardCategoryDisplay;
                        MyProfileViewModel.Instance.Description          = profile.Biography;
                        MyProfileViewModel.Instance.AwardsCountValue     = profile.YearsAsMVP.ToString(System.Globalization.CultureInfo.CurrentCulture);
                    }
                }
                finally
                {
                }
            }
        }
        public async void OnDelete(object sender, EventArgs eventArgs)
        {
            var mi = ((MenuItem)sender);
            ContributionModel contribution = mi.CommandParameter as ContributionModel;

            string result = await MvpService.DeleteContributionModel(Convert.ToInt32(contribution.ContributionId, System.Globalization.CultureInfo.InvariantCulture), LogOnViewModel.StoredToken);

            if (result == CommonConstants.OkResult)
            {
                var modelToDelete = MyProfileViewModel.Instance.BindingContextList.Where(item => (item is ContributionModel) && (item as ContributionModel).ContributionId == contribution.ContributionId).FirstOrDefault();
                MyProfileViewModel.Instance.BindingContextList.Remove(modelToDelete);
            }
        }
        public async Task <bool> BindingContributionType()
        {
            try
            {
                ContributionTypeDetail contributionTypeDetail = await MvpService.GetContributionTypes(LogOnViewModel.StoredToken);

                ContributionViewModel.Instance.ContributionTypeNames = new ObservableCollection <ContributionTypeModel>(contributionTypeDetail.ContributionTypes);
            }
            catch (TaskCanceledException tce) {
                ContributionViewModel.Instance.ErrorMessage = tce.Message;
            }
            return(true);
        }
Exemple #8
0
        private async void GetPhoto()
        {
            if (string.IsNullOrEmpty(MyProfileViewModel.Instance.StoreImageBase64Str))
            {
                try
                {
                    CheckCache();

                    CheckCacheItem();

                    if (cacheItem.ContainsKey(CommonConstants.ProfilePhotoCacheKey))
                    {
                        DateTime cachedDate  = DateTime.Parse(cacheItem[CommonConstants.ProfilePhotoCacheDateKey].ToString());
                        DateTime ExpiredDate = cachedDate.AddHours(24);
                        if (DateTime.Compare(ExpiredDate, DateTime.Now) > 0) //Valid data.
                        {
                            MyProfileViewModel.Instance.StoreImageBase64Str = cacheItem[CommonConstants.ProfilePhotoCacheKey].ToString();
                        }
                        else
                        {
                            MyProfileViewModel.Instance.StoreImageBase64Str = await MvpService.GetPhoto(LogOnViewModel.StoredToken);

                            cacheItem[CommonConstants.ProfilePhotoCacheKey]     = MyProfileViewModel.Instance.StoreImageBase64Str;
                            cacheItem[CommonConstants.ProfilePhotoCacheDateKey] = DateTime.Now;
                            cache[currentUserIdKey] = cacheItem;
                        }
                    }
                    else
                    {
                        MyProfileViewModel.Instance.StoreImageBase64Str = await MvpService.GetPhoto(LogOnViewModel.StoredToken);

                        cacheItem.Add(CommonConstants.ProfilePhotoCacheKey, MyProfileViewModel.Instance.StoreImageBase64Str);
                        cacheItem.Add(CommonConstants.ProfilePhotoCacheDateKey, DateTime.Now);
                        cache[currentUserIdKey] = cacheItem;
                    }

                    Application.Current.Properties[CommonConstants.ProfileCacheListKey] = cache;
                }
                finally
                {
                }
            }
        }
Exemple #9
0
        public async Task <ActionResult <DsResponse> > GetMvp(DsRequest request)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            DsResponse response;

            if (request.Filter == null || request.Filter.isDefault)
            {
                response = await MvpService.GetMvpFromTimeResults(context, request);
            }
            else
            {
                response = await MvpService.GetMvp(context, request);
            }
            sw.Stop();
            logger.LogInformation($"Get Mvp in {sw.ElapsedMilliseconds} ms");
            return(response);
        }
Exemple #10
0
        private async void makeAccessTokenRequest(string requestUrl)
        {
            HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;

            string responseTxt = String.Empty;

            using (HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse)
            {
                var reader = new StreamReader(response.GetResponseStream());
                responseTxt = reader.ReadToEnd();

                var tokenData = JsonConvert.DeserializeObject <Dictionary <string, string> >(responseTxt);
                if (tokenData.ContainsKey("access_token"))
                {
                    App.Current.Properties.Add("access_token", tokenData["access_token"]);
                    LoginViewModel.StoredToken = tokenData["access_token"];

                    // refresh token
                    App.Current.Properties.Add("refresh_token", tokenData["refresh_token"]);

                    // testing refresh token
                    // var ret = await GetNewAccessToken();

                    var profile = await MvpService.GetProfile(LoginViewModel.StoredToken);

                    MvpHelper.SetDataToProfileViewModel(profile);
                    var photobase64Str = await MvpService.GetPhoto(LoginViewModel.StoredToken);

                    LoginViewModel.StoreImageBase64Str = photobase64Str;
                    var myprofileView = new MyProfile();
                    myprofileView.SetPhoto(photobase64Str);
                    await Navigation.PushModalAsync(myprofileView);

                    Application.Current.Properties[CommonConstants.TokenKey] = string.Format("{0},{1}", LoginViewModel.StoredToken, DateTime.Now);
                }
            }
        }
Exemple #11
0
        public async void OnSaveClicked(object sender, EventArgs e)
        {
            try
            {
                bool isValid = CheckData();
                if (!isValid)
                {
                    return;
                }

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

                    if (result != null && result.ContributionId != "0")
                    {
                        Helpers.MvpHelper.SetIconAndLabelTextOfContribution(result);
                        MyProfileViewModel.Instance.List.Insert(0, result);
                        MyProfileViewModel.Instance.TotalOfData += 1;
                    }
                }
                else
                {
                    ContributionViewModel.Instance.MyContribution.ContributionType       = ContributionViewModel.Instance.ContributionTypeNames[contributionTypeSelector.SelectedIndex];
                    ContributionViewModel.Instance.MyContribution.ContributionTechnology = ContributionViewModel.Instance.ContributionAreas[ContributionAreaSelector.SelectedIndex];
                    ContributionViewModel.Instance.MyContribution.Visibility             = ContributionViewModel.Instance.PersonGroups[PersonGroupSelector.SelectedIndex];
                    ContributionViewModel.Instance.MyContribution.StartDate            = ContributionDateSelector.Date.ToUniversalTime();
                    ContributionViewModel.Instance.MyContribution.AnnualQuantity       = Convert.ToInt32(entryAnnualQuantity.Text);
                    ContributionViewModel.Instance.MyContribution.AnnualReach          = Convert.ToInt32(entryAnnualReach.Text);
                    ContributionViewModel.Instance.MyContribution.SecondAnnualQuantity = Convert.ToInt32(entrySecondAnnualQuantity.Text);
                    string result = await MvpService.EditContributionModel(ContributionViewModel.Instance.MyContribution, LoginViewModel.StoredToken);

                    if (result == CommonConstants.OKResult)
                    {
                        MyProfileViewModel.Instance.List = new ObservableCollection <ContributionModel>(MyProfileViewModel.Instance.List);
                    }
                    else
                    {
                        var m     = MyProfileViewModel.Instance.List.Where(item => item.ContributionId == ContributionViewModel.Instance.MyContribution.ContributionId).FirstOrDefault();
                        int index = MyProfileViewModel.Instance.List.IndexOf(m);
                        MyProfileViewModel.Instance.List.Remove(m);
                        MyProfileViewModel.Instance.List.Insert(index, ContributionViewModel.Instance.MyContributionBackup);
                    }
                }

                ContributionViewModel.Instance.MyContribution = null;
                await Navigation.PushModalAsync(new MyProfile());
            }
            catch (Exception ex)
            {
                ContributionViewModel.Instance.ErrorMessage = ex.Message;
            }
        }
Exemple #12
0
        public async void OnSaveClicked(object sender, EventArgs e)
        {
            if (_isTapped == true)
            {
                return;
            }
            var imageButton = sender as Image;

            try
            {
                _isTapped = true;

                if (imageButton != null)
                {
                    imageButton.Opacity = 0.5;
                    await imageButton.FadeTo(1);
                }

                bool isValid = CheckData();
                if (!isValid)
                {
                    return;
                }
                stkOveryLay.IsVisible = true;
                progressText.Text     = "Saving ...";
                if (ContributionViewModel.Instance.MyContribution == null)
                {
                    var model = new ContributionModel()
                    {
                        ContributionId         = "0",
                        ContributionType       = ContributionViewModel.Instance.ContributionTypeNames[contributionTypeSelector.SelectedIndex],
                        ContributionTechnology = ContributionViewModel.Instance.ContributionAreas[ContributionAreaSelector.SelectedIndex],
                        Visibility             = ContributionViewModel.Instance.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 MvpService.AddContributionModel(model, LogOnViewModel.StoredToken);

                    if (result != null && result.ContributionId != "0")
                    {
                        Helpers.MvpHelper.SetIconAndLabelTextOfContribution(result);
                        MyProfileViewModel.Instance.List.Insert(0, result);
                        MyProfileViewModel.Instance.TotalOfData += 1;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    ContributionViewModel.Instance.MyContribution.ContributionType       = ContributionViewModel.Instance.ContributionTypeNames[contributionTypeSelector.SelectedIndex];
                    ContributionViewModel.Instance.MyContribution.ContributionTechnology = ContributionViewModel.Instance.ContributionAreas[ContributionAreaSelector.SelectedIndex];
                    ContributionViewModel.Instance.MyContribution.Visibility             = ContributionViewModel.Instance.PersonGroups[PersonGroupSelector.SelectedIndex];
                    ContributionViewModel.Instance.MyContribution.StartDate            = ContributionDateSelector.Date.ToUniversalTime();
                    ContributionViewModel.Instance.MyContribution.AnnualQuantity       = Convert.ToInt32(entryAnnualQuantity.Text, System.Globalization.CultureInfo.InvariantCulture);
                    ContributionViewModel.Instance.MyContribution.AnnualReach          = Convert.ToInt32(entryAnnualReach.Text, System.Globalization.CultureInfo.InvariantCulture);
                    ContributionViewModel.Instance.MyContribution.SecondAnnualQuantity = Convert.ToInt32(entrySecondAnnualQuantity.Text, System.Globalization.CultureInfo.InvariantCulture);
                    string result = await MvpService.EditContributionModel(ContributionViewModel.Instance.MyContribution, LogOnViewModel.StoredToken);

                    if (result == CommonConstants.OkResult)
                    {
                        MyProfileViewModel.Instance.List = new ObservableCollection <ContributionModel>(MyProfileViewModel.Instance.List);
                    }
                    else
                    {
                        var currentContribution = MyProfileViewModel.Instance.List.Where(item => item.ContributionId == ContributionViewModel.Instance.MyContribution.ContributionId).FirstOrDefault();
                        int index = MyProfileViewModel.Instance.List.IndexOf(currentContribution);
                        MyProfileViewModel.Instance.List.Remove(currentContribution);
                        MyProfileViewModel.Instance.List.Insert(index, ContributionViewModel.Instance.MyContributionBackup);
                        return;
                    }
                }

                ContributionViewModel.Instance.MyContribution = null;

                await Navigation.PopModalAsync();
            }
            catch (WebException ex)
            {
                ContributionViewModel.Instance.ErrorMessage = ex.Message;
            }
            catch (HttpRequestException ex)
            {
                ContributionViewModel.Instance.ErrorMessage = ex.Message;
            }
            finally
            {
                if (imageButton != null)
                {
                    _isTapped = false;
                }
                stkOveryLay.IsVisible = false;
                progressText.Text     = "Loading ...";
            }
        }