Пример #1
0
        private List <KeyValuePair <RessourceVM, string> > ListToDictionary(List <List <Object> > list)
        {
            KeyValuePair <RessourceVM, string> dictionary = new KeyValuePair <RessourceVM, string>();

            List <KeyValuePair <RessourceVM, string> > listFinal = new List <KeyValuePair <RessourceVM, string> >();

            foreach (var x in list)
            {
                RessourceVM r = ObjectExtensions.ToObject <RessourceVM>((IDictionary <string, object>)x.ElementAt <Object>(0));
                listFinal.Add(new KeyValuePair <RessourceVM, string>(r, Convert.ToString(x.ElementAt <Object>(1))));
            }

            return(listFinal);
        }
Пример #2
0
        // GET: A
        public async System.Threading.Tasks.Task <ActionResult> Index()
        {
            ITestService      ts = new TestService();
            IRessourceService rs = new RessourceService();
            //ts.getProf();
            var x = ts.nbByCountry();
            //ViewBag.count = 20;
            double b;

            List <KeyValuePair <RessourceVM, double> > flist = new List <KeyValuePair <RessourceVM, double> >();


            foreach (ressource r in rs.getRessources())
            {
                listWS = new List <KeyValuePair <RessourceVM, string> >();
                RessourceVM rVM = new RessourceVM {
                    id = r.id, Name = r.user.name, LastName = r.user.lastname
                };


                HttpClient Client = new HttpClient();
                Client.BaseAddress = new Uri("http://localhost:18080/l4c_map-v2-web/");
                Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = await Client.GetAsync("rest/efficiencies?id=" + r.id);

                string data = await response.Content.ReadAsStringAsync();

                JavaScriptSerializer JSserializer = new JavaScriptSerializer();
                listWS = ListToDictionary(JSserializer.Deserialize <List <List <Object> > >(data));
                string actStr = listWS[0].Value;
                if (actStr.Contains("%"))
                {
                    actStr = actStr.Remove(actStr.IndexOf("%"), 1);

                    System.Diagnostics.Debug.WriteLine(actStr);
                    b = double.Parse(actStr, System.Globalization.CultureInfo.InvariantCulture);
                }
                else
                {
                    b = 0;
                }
                ract = new KeyValuePair <RessourceVM, double>(rVM, b);
                flist.Add(ract);
            }
            ViewBag.listOfPair = flist;

            return(View());
        }