public MobileSrc.Commuter.Shared.CommuteHistory GetCommuteHistory(Guid deviceId, Guid commuteId) { LogRequest(deviceId, "GetCommuteHistory"); MobileSrc.Commuter.Shared.CommuteHistory history = new MobileSrc.Commuter.Shared.CommuteHistory(); try { using (SqlConnection connection = new SqlConnection(@"Data Source=wpcommuter.db.3448251.hostedresource.com; Initial Catalog=wpcommuter; User ID=wpcommuter; Password='******';")) { connection.Open(); SqlCommand command = new SqlCommand("GetCommuteHistory", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("idCommute", commuteId); using (SqlDataReader reader = command.ExecuteReader()) { Dictionary <Guid, MobileSrc.Commuter.Shared.RouteHistory> routes = new Dictionary <Guid, MobileSrc.Commuter.Shared.RouteHistory>(); while (reader.Read()) { Guid idRoute = (Guid)reader["idRoute"]; if (!routes.ContainsKey(idRoute)) { MobileSrc.Commuter.Shared.RouteHistory routeHistory = new MobileSrc.Commuter.Shared.RouteHistory(); routeHistory.RouteId = idRoute; history.Routes.Add(routeHistory); routes.Add(idRoute, routeHistory); } MobileSrc.Commuter.Shared.RouteHistory.RouteHistoryDay day = new MobileSrc.Commuter.Shared.RouteHistory.RouteHistoryDay(); day.Day = (DayOfWeek)Convert.ToInt32(reader["Day"]); day.Minutes = Convert.ToDouble(reader["Duration"]); bool isDeparture = Convert.ToBoolean(reader["IsDeparture"]); if (isDeparture) { routes[idRoute].DepartureAverages.Add(day); } else { routes[idRoute].ReturnAverages.Add(day); } } } } } catch { } return(history); }
public MobileSrc.Commuter.Shared.CommuteHistory GetCommuteHistory(Guid deviceId, Guid commuteId) { LogRequest(deviceId, "GetCommuteHistory"); MobileSrc.Commuter.Shared.CommuteHistory history = new MobileSrc.Commuter.Shared.CommuteHistory(); try { using (SqlConnection connection = new SqlConnection(@"Data Source=wpcommuter.db.3448251.hostedresource.com; Initial Catalog=wpcommuter; User ID=wpcommuter; Password='******';")) { connection.Open(); SqlCommand command = new SqlCommand("GetCommuteHistory", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("idCommute", commuteId); using (SqlDataReader reader = command.ExecuteReader()) { Dictionary<Guid, MobileSrc.Commuter.Shared.RouteHistory> routes = new Dictionary<Guid, MobileSrc.Commuter.Shared.RouteHistory>(); while (reader.Read()) { Guid idRoute = (Guid)reader["idRoute"]; if (!routes.ContainsKey(idRoute)) { MobileSrc.Commuter.Shared.RouteHistory routeHistory = new MobileSrc.Commuter.Shared.RouteHistory(); routeHistory.RouteId = idRoute; history.Routes.Add(routeHistory); routes.Add(idRoute, routeHistory); } MobileSrc.Commuter.Shared.RouteHistory.RouteHistoryDay day = new MobileSrc.Commuter.Shared.RouteHistory.RouteHistoryDay(); day.Day = (DayOfWeek)Convert.ToInt32(reader["Day"]); day.Minutes = Convert.ToDouble(reader["Duration"]); bool isDeparture = Convert.ToBoolean(reader["IsDeparture"]); if (isDeparture) { routes[idRoute].DepartureAverages.Add(day); } else { routes[idRoute].ReturnAverages.Add(day); } } } } } catch { } return history; }