Exemplo n.º 1
0
        private static List <LocationResponseModel> GetStations(UserMapParams user)
        {
            UriBuilder builder = new UriBuilder("https://api.openchargemap.io/v3/poi/");

            if (user.Latitude != 0)
            {
                builder.Query = "key=347654fb-65d0-435c-9239-15523ae572d7&output=json&countrycode=IN&distanceunit=km&maxresults=" + user.MaxResult + "&distance=" + user.Distance + "&latitude=" + user.Latitude + "&longitude=" + user.longitude;
            }
            else if ((user.Latitude == 0) && (user.MaxResult != 0))
            {
                builder.Query = "key=347654fb-65d0-435c-9239-15523ae572d7&output=json&countrycode=IN&maxresults=" + user.MaxResult;
            }



            HttpClient client = new HttpClient();
            var        result = client.GetAsync(builder.Uri).Result;
            List <LocationResponseModel> response = new List <LocationResponseModel>();

            if (result.IsSuccessStatusCode)
            {
                var res = result.Content.ReadAsStringAsync().Result;
                response = Newtonsoft.Json.JsonConvert.DeserializeObject <List <LocationResponseModel> >(res);
            }
            else
            {
                response = null;
            }
            return(response);
        }
Exemplo n.º 2
0
 public ActionResult GeAllData(UserMapParams user)
 {
     try
     {
         var res = userServices.GetListUserAsync(user);
         return(Ok(res));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
Exemplo n.º 3
0
        public object GetListUserAsync(UserMapParams user)
        {
            var response = GetStations(user);

            List <LocationResponseViewModel> model = new List <LocationResponseViewModel>();

            foreach (var item in response)
            {
                LocationResponseViewModel locationResponseView = new LocationResponseViewModel();
                DataProviderViewMdel      dataProvider         = new DataProviderViewMdel();
                UsageTypeViewMdel         usageTypeView        = new UsageTypeViewMdel();
                AddressInfoMdel           AddressInfo          = new AddressInfoMdel();
                ConnectionsMdel           connections          = new ConnectionsMdel();
                LevelMdel          levelMdel      = new LevelMdel();
                CurrentType        currentType    = new CurrentType();
                List <LevelMdel>   levelMdelmodel = new List <LevelMdel>();
                List <CurrentType> currentTypes   = new List <CurrentType>();
                NumberOfPoints     numberOfPoints = new NumberOfPoints();
                dataProvider.Title = item.DataProvider.Title;
                locationResponseView.DataProvider = dataProvider;
                usageTypeView.IsPayAtLocation     = item.UsageType.IsPayAtLocation;
                usageTypeView.Title = item.UsageType.Title;
                locationResponseView.usageTypeView = usageTypeView;
                AddressInfo.Id                   = item.AddressInfo.ID;
                AddressInfo.Title                = item.AddressInfo.Title;
                AddressInfo.AddressLine1         = item.AddressInfo.AddressLine1;
                AddressInfo.Town                 = item.AddressInfo.Town;
                AddressInfo.StateOrProvince      = item.AddressInfo.StateOrProvince;
                AddressInfo.Postcode             = item.AddressInfo.Postcode;
                AddressInfo.Latitude             = item.AddressInfo.Latitude;
                AddressInfo.Longitude            = item.AddressInfo.Longitude;
                AddressInfo.ContactTelephone1    = item.AddressInfo.ContactTelephone1;
                AddressInfo.ContactEmail         = item.AddressInfo.ContactEmail;
                AddressInfo.AccessComments       = item.AddressInfo.AccessComments;
                AddressInfo.RelatedURL           = item.AddressInfo.RelatedURL;
                AddressInfo.Distance             = item.AddressInfo.Distance;
                AddressInfo.DistanceUnit         = item.AddressInfo.DistanceUnit;
                AddressInfo.CountryName          = item.AddressInfo.CountryName;
                locationResponseView.addressInfo = AddressInfo;
                foreach (var conn in item.Connections)
                {
                    levelMdel.PowerKW = conn.PowerKW;
                    if (conn.Level != null)
                    {
                        levelMdel.IsFastChargeCapable = conn.Level.IsFastChargeCapable;
                        levelMdel.Title          = conn.Level.Title;
                        connections.Connenctions = conn.Level.Title;
                        currentType.Title        = conn.Level.Title;
                    }
                }
                locationResponseView.connectionsMdel = connections;
                levelMdelmodel.Add(levelMdel);
                locationResponseView.levelMdel       = levelMdelmodel;
                locationResponseView.connectionsMdel = connections;
                currentTypes.Add(currentType);
                locationResponseView.currentType          = currentTypes;
                numberOfPoints.NumberOfPoint              = item.NumberOfPoints;
                locationResponseView.numberOfPoints       = numberOfPoints;
                locationResponseView.dateLastStatusUpdate = item.DateLastStatusUpdate;

                model.Add(locationResponseView);
            }

            return(model);
        }