// Query to get all serviceDetails public static List <ServiceTimingModel> GetServiceTiming(int serviceId, List <LocationModel> locations) { var sql = @" select Locations.Id as LocationId, TimeEvents.id as TimeEventId, Locations.LocationName as LocationName, Locations.LocationAbbreviation as LocationAbbrev, Locations.[Order] AS LocationsOrder, TimeEvents.EventType as EventType, TimeEvents.ArrivalTime as ArrivalTime, TimeEvents.WaitTime as WaitTime, '--' as TimeString from Locations, TimeEvents where TimeEvents.LocationId=Locations.Id and TimeEvents.ServiceTemplateId=( select ServiceTemplates.Id from ServiceTemplates, Services where ServiceTemplates.Id= Services.ServiceTemplateId and Services.id=@serviceId) order by Locations.[order] asc " ; var serviceTiming = SQLiteData.LoadData <ServiceTimingModel, dynamic>(sql, new { serviceId }, SQLiteData.GetConnectionString()).ToList(); // Now we need to complete the list, using return(serviceTiming); }
public static List <ExtendedServiceModel> GetExtendedServicesPerRoute(int routeId, int serviceDirectionId) { List <ServiceClassModel> serviceClasses = ServiceClassDataAccess.GetAllServiceClasses(); string sql = @"SELECT Services.Id AS Id, Services.ServiceName, Services.ServiceAbbreviation, Services.StartTime, Services.EndTime, ServiceTemplates.ServiceType, Services.ServiceTemplateId FROM Services, ServiceTemplates WHERE @RouteId=ServiceTemplates.RouteId AND Services.ServiceTemplateId== ServiceTemplates.Id AND ServiceTemplates.ServiceDirectionId=@ServiceDirectionId;"; var serviceList = SQLiteData.LoadData <ExtendedServiceModel, dynamic>(sql, new { routeId, serviceDirectionId }, SQLiteData.GetConnectionString()).ToList(); foreach (var item in serviceList) { var classVar = ServiceClassDataAccess.GetServiceClassModelFromString(item.ServiceType, serviceClasses); item.Category = classVar.Category; } return(serviceList); }
public static List <ServiceClassModel> GetAllServiceClasses() { var sql = "SELECT Id, ServiceClassname, ServiceClassDescription, Category, Color FROM \"ServiceClasses\";"; var serviceClassList = SQLiteData.LoadData <ServiceClassModel, dynamic>(sql, new { }, SQLiteData.GetConnectionString()).ToList(); return(serviceClassList); }
public static List <TimeEventTypeModel> GetAllTimeEventTypes() { var sql = "SELECT Id, EventType, EventTypeDescription FROM \"TimeEventTypes\";"; var timeEventList = SQLiteData.LoadData <TimeEventTypeModel, dynamic>(sql, new {}, SQLiteData.GetConnectionString()).ToList(); return(timeEventList); }
public static List <TimetableModel> GetAllTimetablesPerRoute(int routeId) { string sql = "SELECT * FROM Timetables WHERE RouteId=@RouteId"; var timetableList = SQLiteData.LoadData <TimetableModel, dynamic>(sql, new { routeId }, SQLiteData.GetConnectionString()).ToList(); return(timetableList); }
public static LocationModel GetLocationById(int locationId) { string sql = "SELECT * FROM Locations WHERE Id= @LocationId"; var location = SQLiteData.LoadData <LocationModel, dynamic>(sql, new { locationId }, SQLiteData.GetConnectionString()).FirstOrDefault(); return(location); }
public static List <LocationModel> GetAllLocationsPerRoute(int routeId) { string sql = "SELECT * FROM Locations WHERE RouteId=@RouteId ORDER BY Locations.[Order] ASC"; var locationList = SQLiteData.LoadData <LocationModel, dynamic>(sql, new { routeId }, SQLiteData.GetConnectionString()).ToList(); return(locationList); }
public static TimetableModel GetTimetableById(int timeTableId) { string sql = "SELECT * FROM Timetables WHERE Id= @timeTableId"; var timeTable = SQLiteData.LoadData <TimetableModel, dynamic>(sql, new { timeTableId }, SQLiteData.GetConnectionString()).FirstOrDefault(); return(timeTable); }
public static RouteModel GetRouteById(int routeId) { string sql = "SELECT * FROM Routes WHERE Id= @RouteId"; var route = SQLiteData.LoadData <RouteModel, dynamic>(sql, new { routeId }, SQLiteData.GetConnectionString()).FirstOrDefault(); return(route); }
public static List <ConnectTtSiModel> GetAllConnectTtSiPerRoute(int routeId) { string sql = "SELECT ConnectTtSi.Id, ConnectTtSi.TimetableId, ConnectTtSi.ServiceId FROM ConnectTtSi, Timetables WHERE ConnectTtSi.TimetableId= Timetables.Id AND Timetables.RouteId=@RouteId"; var connectList = SQLiteData.LoadData <ConnectTtSiModel, dynamic>(sql, new { routeId }, SQLiteData.GetConnectionString()).ToList(); return(connectList); }
public static List <RouteModel> GetAllRoutes() { string sql = "SELECT * FROM Routes"; var routesList = SQLiteData.LoadData <RouteModel, dynamic>(sql, new { }, SQLiteData.GetConnectionString()).ToList(); return(routesList); }
public static List <ServiceTemplateModel> GetServiceTemplatesPerRoute(int routeId) { string sql = "SELECT * FROM ServiceTemplates WHERE RouteId=@RouteId"; var serviceList = SQLiteData.LoadData <ServiceTemplateModel, dynamic>(sql, new { routeId }, SQLiteData.GetConnectionString()).ToList(); return(serviceList); }
public static ServiceTemplateModel GetServiceTemplateById(int serviceTemplateId) { string sql = "SELECT * FROM ServiceTemplates WHERE Id= @serviceTemplateId"; var timeTable = SQLiteData.LoadData <ServiceTemplateModel, dynamic>(sql, new { serviceTemplateId }, SQLiteData.GetConnectionString()).FirstOrDefault(); return(timeTable); }
internal static ServiceDirectionModel GetServiceDirectionByServiceTemplateId(int serviceTemplateId) { string sql = "SELECT ServiceDirections.Id, ServiceDirections.ServiceDirectionName, ServiceDirections.ServiceDirectionAbbreviation, ServiceDirections.RouteId, ServiceDirections.IsDescending " + "FROM ServiceDirections, ServiceTemplates WHERE ServiceTemplates.id=@ServiceTemplateId AND ServiceDirections.Id= ServiceTemplates.ServiceDirectionId"; var serviceDirection = SQLiteData.LoadData <ServiceDirectionModel, dynamic>(sql, new { serviceTemplateId }, SQLiteData.GetConnectionString()).FirstOrDefault(); return(serviceDirection); }
public static ServiceDirectionModel GetServiceDirectionById(int serviceDirectionId) { string sql = "SELECT * FROM ServiceDirections WHERE Id= @ServiceDirectionId"; var serviceDirection = SQLiteData.LoadData <ServiceDirectionModel, dynamic>(sql, new { serviceDirectionId }, SQLiteData.GetConnectionString()).FirstOrDefault(); return(serviceDirection); }
public static List <string> GetAllTimeEventTypeStrings() { var sql = "SELECT Id, EventType, EventTypeDescription FROM \"TimeEventTypes\";"; var timeEventList = SQLiteData.LoadData <TimeEventTypeModel, dynamic>(sql, new {}, SQLiteData.GetConnectionString()).ToList(); var output = timeEventList.Select(x => x.EventType).ToList(); return(output); }
public static List <TimeEventModel> GetAllTimeEventsPerServiceTemplate(int serviceTemplateId) { string sql = "SELECT * FROM TimeEvents " + "WHERE ServiceTemplateId=@ServiceTemplateId"; var timeEventList = SQLiteData.LoadData <TimeEventModel, dynamic>(sql, new { serviceTemplateId }, SQLiteData.GetConnectionString()).ToList(); return(timeEventList); }
public static TimeEventModel GetTimeEventById(int timeEventId) { string sql = "SELECT * FROM TimeEvents " + "WHERE Id= @TimeEventId"; var timeEvent = SQLiteData.LoadData <TimeEventModel, dynamic>(sql, new { timeEventId }, SQLiteData.GetConnectionString()).FirstOrDefault(); return(timeEvent); }
public static List <TimetableRouteModel> GetAllTimetables() { string sql = "SELECT Timetables.Id AS TimetableId, Routes.Id AS RouteId, Timetables.TimetableAbbreviation, Timetables.TimetableName, " + "Timetables.TimetableDescription, Timetables.IsMultiDirection, Timetables.ServiceDirectionId, " + "Routes.RouteName, Routes.RouteAbbreviation " + "FROM Timetables, Routes WHERE Timetables.RouteId=Routes.Id ORDER BY Routes.RouteAbbreviation"; var timetableList = SQLiteData.LoadData <TimetableRouteModel, dynamic>(sql, new {}, SQLiteData.GetConnectionString()).ToList(); return(timetableList); }
public static List <ServiceModel> GetServicesPerRoute(int routeId) { string sql = @"SELECT Services.Id AS Id, Services.ServiceName, Services.ServiceAbbreviation, Services.StartTime, Services.EndTime, Services.ServiceTemplateId FROM Services, ServiceTemplates WHERE @RouteId=ServiceTemplates.RouteId AND Services.ServiceTemplateId== ServiceTemplates.Id"; var serviceList = SQLiteData.LoadData <ServiceModel, dynamic>(sql, new { routeId }, SQLiteData.GetConnectionString()).ToList(); return(serviceList); }
public static List <ServiceModel> GetServicesPerTimetable(int timetableId) { string sql = @" SELECT Services.Id AS Id, Services.ServiceName, Services.ServiceAbbreviation, Services.StartTime, Services.EndTime, Services.ServiceTemplateId FROM Services, ConnectTtSi WHERE ConnectTtSi.TimetableId=@TimetableId AND Services.Id=ConnectTtSi.ServiceId; "; var serviceList = SQLiteData.LoadData <ServiceModel, dynamic>(sql, new { timetableId }, SQLiteData.GetConnectionString()).ToList(); return(serviceList); }
public static void ServiceTemplateMigration() { // Make sure to never do this twice! var sql = "SELECT 1 FROM sqlite_master WHERE type='table' AND name='ServiceTemplates'"; int tableExists = SQLiteData.LoadData <int, dynamic>(sql, new { }, SQLiteData.GetConnectionString()).FirstOrDefault(); if (tableExists == 0) { sql = File.ReadAllText("SQL\\ServiceTemplatesChange.sql"); SQLiteData.SaveData <dynamic>(sql, new { }, SQLiteData.GetConnectionString()); if (Settings.DatabaseVersion == 2) { VersionDataAccess.UpdateDatabaseVersion(3); } } }
public static int GetCurrentDatabaseVersion() { string sql1 = "SELECT 1 FROM sqlite_master WHERE type='table' AND name='Version'"; string sql2 = "SELECT VersionNr FROM Version"; try { int tableExists = SQLiteData.LoadData <int, dynamic>(sql1, new {}, SQLiteData.GetConnectionString()).FirstOrDefault(); if (tableExists == 1) { return(SQLiteData.LoadData <int, dynamic>(sql2, new { }, SQLiteData.GetConnectionString()) .FirstOrDefault()); } return(0); } catch (SQLiteException e) { return(0); } }