public GetDelaysAPI.Station GetStationsByName(string station) { if (station != null) { DateTime now = DateTime.UtcNow; now = now.AddHours(2); IGetAPIGoogle googleApi = new SearchPlaceAPI(); IGetAll newaccessapi = SNCBAPI.GetAll.Instance(); DataApiPerStations s = newaccessapi.GetDelaysForStation(station); DetailsPlace n = googleApi.GetInfo(string.Concat(s.stationinfo.locationY + "," + s.stationinfo.locationX)); GetDelaysAPI.Station stat = new GetDelaysAPI.Station(); stat.stationinfo.id = s.stationinfo.id; stat.stationinfo.locationX = s.stationinfo.locationX; stat.stationinfo.locationY = s.stationinfo.locationY; stat.stationinfo.name = s.stationinfo.name; if (n.result.opening_hours != null) { stat.stationinfo.opening_hours = n.result.opening_hours.weekday_text; } stat.stationinfo.rating = n.result.rating; foreach (GoogleAPI.Review r in n.result.reviews) { stat.stationinfo.reviews.Add(new GetDelaysAPI.Review { author_name = r.author_name, rating = r.rating, text = r.text }); } foreach (SNCBAPI.ArrDep arrdep in s.arrivals.arrival) { DateTime hourTrain = new DateTime(); hourTrain = hourTrain.AddHours(2); hourTrain = hourTrain.AddSeconds(arrdep.time); hourTrain = hourTrain.AddMinutes(arrdep.delay); if (now.TimeOfDay < hourTrain.TimeOfDay) { stat.arrivals.Add(new ArrivalDeparture { delay = arrdep.delay, id = arrdep.id, station = arrdep.station, time = arrdep.time.ToString(), vehicle = arrdep.vehicle }); } } foreach (SNCBAPI.ArrDep arrdep in s.departures.departure) { DateTime hourTrain = new DateTime(); hourTrain = hourTrain.AddHours(2); hourTrain = hourTrain.AddSeconds(arrdep.time); hourTrain = hourTrain.AddMinutes(arrdep.delay); if (now.TimeOfDay < hourTrain.TimeOfDay) { stat.departures.Add(new ArrivalDeparture { delay = arrdep.delay, id = arrdep.id, station = arrdep.station, time = arrdep.time.ToString(), vehicle = arrdep.vehicle }); } } return(stat); } else { return(null); } }
public List <NotificationStation> GetNotificationStations(string userid) { IUser userDAL = new DALUser(); api.getdelays.POCO.User u = userDAL.GetUser(Convert.ToInt32(userid)); List <NotificationStation> listS = new List <NotificationStation>(); IGetAll newaccessapi = SNCBAPI.GetAll.Instance(); DateTime now = DateTime.UtcNow; now = now.AddHours(2); if (u != null) { foreach (api.getdelays.POCO.FollowedStation s in u.followedStations) { int delays = 0; DataApiPerStations stat = newaccessapi.GetDelaysForStation(s.stationName); foreach (SNCBAPI.ArrDep arrdep in stat.arrivals.arrival) { DateTime hourTrain = new DateTime(); hourTrain = hourTrain.AddHours(2); hourTrain = hourTrain.AddSeconds(arrdep.time); hourTrain = hourTrain.AddMinutes(arrdep.delay); if (now.TimeOfDay < hourTrain.TimeOfDay) { delays += arrdep.delay; } } foreach (SNCBAPI.ArrDep arrdep in stat.departures.departure) { DateTime hourTrain = new DateTime(); hourTrain = hourTrain.AddHours(2); hourTrain = hourTrain.AddSeconds(arrdep.time); hourTrain = hourTrain.AddMinutes(arrdep.delay); if (now.TimeOfDay < hourTrain.TimeOfDay) { delays += arrdep.delay; } } if (delays >= 15 && delays < 30) { listS.Add(new NotificationStation { StationName = s.stationName, Delays = delays, Priority = "warning" }); } else if (delays < 15 && delays > 0) { listS.Add(new NotificationStation { StationName = s.stationName, Delays = delays, Priority = "normal" }); } else if (delays >= 30) { listS.Add(new NotificationStation { StationName = s.stationName, Delays = delays, Priority = "danger" }); } } return(listS); } else { return(listS); } }