public List <GetDelaysAPI.Connection> GetConnection(string dep, string arr) { if (dep != null && arr != null) { if (dep != "" && arr != "") { DateTime now = DateTime.UtcNow; now = now.AddHours(2); IGetAll newaccessapi = SNCBAPI.GetAll.Instance(); DataApiConnection s = newaccessapi.GetConnection(dep, arr); List <GetDelaysAPI.Connection> connections = new List <GetDelaysAPI.Connection>(); foreach (SNCBAPI.Connection c in s.connection) { DateTime hourConnection = new DateTime(); hourConnection = hourConnection.AddHours(2); hourConnection = hourConnection.AddSeconds(c.departure.time); hourConnection = hourConnection.AddMinutes(c.departure.delay); if (now.TimeOfDay < hourConnection.TimeOfDay) { GetDelaysAPI.Connection co = new GetDelaysAPI.Connection(); co.arrival.delay = c.arrival.delay; co.arrival.station = c.arrival.station; co.arrival.time = c.arrival.time.ToString(); co.arrival.vehicle = c.arrival.vehicle; co.departure.delay = c.departure.delay; co.departure.station = c.departure.station; co.departure.time = c.departure.time.ToString(); co.departure.vehicle = c.departure.vehicle; co.duration = c.duration; if (c.vias != null) { foreach (SNCBAPI.ViaInfo via in c.vias.via) { GetDelaysAPI.Via v = new GetDelaysAPI.Via(); v.arrival.delay = via.arrival.delay; v.arrival.station = via.arrival.direction.name; v.arrival.time = via.arrival.time.ToString(); v.arrival.vehicle = via.arrival.vehicule; v.departure.delay = via.departure.delay; v.departure.station = via.departure.direction.name; v.departure.time = via.departure.time.ToString(); v.departure.vehicle = via.departure.vehicule; co.vias.Add(v); } } connections.Add(co); } } return(connections); } else { return(null); } } else { return(null); } }
public List <NotificationConnection> GetNotificationConnections(string userid) { IUser userDAL = new DALUser(); api.getdelays.POCO.User u = userDAL.GetUser(Convert.ToInt32(userid)); List <NotificationConnection> listS = new List <NotificationConnection>(); IGetAll newaccessapi = SNCBAPI.GetAll.Instance(); DateTime now = DateTime.UtcNow; now = now.AddHours(2); if (u != null) { foreach (api.getdelays.POCO.FollowedConnection s in u.followedConnections) { DataApiConnection stat = newaccessapi.GetConnection(s.departure, s.arrival, s.DateTime); foreach (SNCBAPI.Connection c in stat.connection) { DateTime hourTrain = new DateTime(); hourTrain = hourTrain.AddHours(2); hourTrain = hourTrain.AddSeconds(c.departure.time); int year = DateTime.Now.Year - hourTrain.Year; hourTrain = hourTrain.AddYears(year); if (s.DateTime.TimeOfDay == hourTrain.TimeOfDay) { hourTrain = hourTrain.AddMinutes(c.departure.delay); if (hourTrain.TimeOfDay > now.TimeOfDay) { hourTrain = hourTrain.AddMinutes(-c.departure.delay); if (c.departure.delay >= 15 && c.departure.delay < 30) { listS.Add(new NotificationConnection { Arrival = s.arrival, Departure = s.departure, DelaysArrival = Convert.ToInt32(c.arrival.delay), DelaysDeparture = Convert.ToInt32(c.departure.delay), Time = hourTrain, Priority = "warning" }); } else if (c.departure.delay < 15 && c.departure.delay >= 0) { listS.Add(new NotificationConnection { Arrival = s.arrival, Departure = s.departure, DelaysArrival = Convert.ToInt32(c.arrival.delay), DelaysDeparture = Convert.ToInt32(c.departure.delay), Time = hourTrain, Priority = "normal" }); } else if (c.departure.delay >= 30) { listS.Add(new NotificationConnection { Arrival = s.arrival, Departure = s.departure, DelaysArrival = Convert.ToInt32(c.arrival.delay), DelaysDeparture = Convert.ToInt32(c.departure.delay), Priority = "danger" }); } } } } } return(listS); } else { return(null); } }