//Create a list of Bysykkel objects
        public List <Bysykkel> CreateBikesInfo(BysykkelResponse stationResponse, BysykkelResponse bikeInfoResponse)
        {
            //Extract information about Bysykkel stations and add them ass Bysykkel objects in a list.
            var listOfStations = new List <Bysykkel>();

            foreach (var station in stationResponse.Data.Stations)
            {
                listOfStations.Add(
                    new Bysykkel()
                {
                    StationId       = station.StationId,
                    StationName     = station.Name,
                    StationAddress  = station.Address,
                    Latitude        = station.Lat,
                    Longitude       = station.Lon,
                    StationCapacity = station.Capacity,
                });
            }
            //Iterate through bikeInfoResponse and match stationId's with the Id's in listOfStations.
            //Add information about available bikes and docks to existing bike objects in listOfStations
            foreach (var bike in bikeInfoResponse.Data.Stations)
            {
                var station = listOfStations.Find(x => x.StationId == bike.StationId);
                station.BikesAvailable = bike.Num_Bikes_Available;
                station.DocksAvailable = bike.Num_Docks_Available;
            }
            return(listOfStations);
        }
Esempio n. 2
0
        public List <Bysykkel> ExtractBysyklerInfoToList(BysykkelResponse rawBikeJsonData)
        {
            List <Bysykkel> allBikes = new List <Bysykkel>();

            foreach (var bike in rawBikeJsonData.Data.Stations)
            {
                allBikes.Add(new Bysykkel
                {
                    StationName     = bike.Name,
                    Latitude        = bike.Lat,
                    Longitude       = bike.Lon,
                    StationCapacity = bike.Capacity,
                    // TODO: Show bikes available?
                });
            }
            return(allBikes);
        }