Ejemplo n.º 1
0
        public async Task <object> GetUsersWithFilter(string location, string year, string promo)
        {
            HttpClient   client     = new HttpClient();
            TrombiFilter resultlist = new TrombiFilter();

            resultlist.Results = new List <TrombiFilterItem> ();

            var result = await client.PostAsync(BaseAPI + "/user/filter/user?format=json&" + "location=" + location + "&year=" + year + "&promo=" + promo + "&offset=0", GetHeader());

            if (!result.IsSuccessStatusCode)
            {
                throw new Exception("Impossible de récuperer les profils");
            }
            try {
                TrombiFilter root = Newtonsoft.Json.JsonConvert.DeserializeObject <TrombiFilter> (await result.Content.ReadAsStringAsync());
                if (root.Results == null)
                {
                    return(null);
                }
                resultlist.Results.AddRange(root.Results);
                resultlist.Count = root.Count;
                while (root.Results != null)
                {
                    result = await client.PostAsync(BaseAPI + "/user/filter/user?format=json&" + "location=" + location + "&year=" + year + "&promo=" + promo + "&offset=" + resultlist.Results.Count, GetHeader());

                    root = Newtonsoft.Json.JsonConvert.DeserializeObject <TrombiFilter> (await result.Content.ReadAsStringAsync());
                    if (root.Results != null)
                    {
                        resultlist.Results.AddRange(root.Results);
                    }
                }
                return(resultlist);
            } catch (Exception ex) {
                throw new Exception("Impossible de récuperer les profils", ex);
            }
        }
Ejemplo n.º 2
0
        private async void DisplayContentLocal()
        {
            TrombiFilter profiles = ((TrombiFilter)await App.API.GetUsersWithFilter(((App)Application.Current).User.Location, DateTime.Now.Year.ToString(), "Tek" + ((App)Application.Current).User.Studentyear)) ?? ((TrombiFilter)await App.API.GetUsersWithFilter(((App)Application.Current).User.Location, (DateTime.Now.Year - 1).ToString(), "Tek" + ((App)Application.Current).User.Studentyear));

            int i = 0;

            foreach (TrombiFilterItem item in profiles.Results)
            {
                i++;
                ((LoadingScreen)Content).SetPercent((((double)i) / ((double)(profiles.Results.Count))));
                var tmp = await App.API.GetUserShort(item.Login) as User;

                if (tmp == null)
                {
                    continue;
                }
                Profiles.Add(tmp);
            }
            Profiles = Profiles.Where(x => !x.Close).ToList();
            Profiles.Sort((x, y) => y.Gpa [0].GPA.CompareTo(x.Gpa [0].GPA));
            InsertAverageAndMedian();

            int foo = 1;

            foreach (User item in Profiles)
            {
                item.Index = foo++;
            }

            ListView list = new ListView {
                ItemTemplate  = new DataTemplate(typeof(LeaderboardCell)),
                ItemsSource   = Profiles,
                HasUnevenRows = true
            };

            list.ItemSelected += (sender, e) => {
                if (e.SelectedItem != null)
                {
                    Navigation.PushAsync(new Profile(((User)e.SelectedItem).Login));
                    ((ListView)sender).SelectedItem = null;
                }
            };

            SearchBar search = new SearchBar {
                CancelButtonColor = IntraColor.LightBlue,
                Placeholder       = "Cherchez dans le leaderboard"
            };

            search.TextChanged += (sender, e) => {
                if (e.NewTextValue == String.Empty || e.NewTextValue == null)
                {
                    list.ItemsSource = Profiles;
                }
                else
                {
                    List <User> newlist;
                    newlist = Profiles.Where(x => x.Login.Contains(e.NewTextValue.ToLower())).ToList();
                    newlist.AddRange(Profiles.Where(x => x.Title.ToLower().Contains(e.NewTextValue.ToLower())));
                    newlist.Distinct().ToList();
                    newlist.Sort((x, y) => y.Gpa [0].GPA.CompareTo(x.Gpa [0].GPA));
                    list.ItemsSource = newlist;
                }
            };

            list.Header = new StackLayout {
                Padding  = new Thickness(0, 0, 0, 10),
                Children =
                {
                    search,
                    new PlotView {
                        Model             = GetPieGraph(),
                        HeightRequest     = 200,
                        VerticalOptions   = LayoutOptions.Fill,
                        HorizontalOptions = LayoutOptions.Fill,
                        WidthRequest      = App.ScreenWidth - 20,
                    }
                }
            };

            Content = list;
        }