private List<AvailableDriverList> lookupCurrespondingUserTripInDB(List<LOCATION> locations) { List<AvailableDriverList> listDriverTripInfo = new List<AvailableDriverList>(); using (Hyk_Database_ModelContainer context = new Hyk_Database_ModelContainer()) { context.Configuration.ProxyCreationEnabled = false; context.Configuration.LazyLoadingEnabled = false; foreach (LOCATION location in locations) { List<AvailableDriverList> results = (from trips in context.TRIPs where trips.ID_ == location.TRIPID_ where trips.DRIVER_ID_ != null join driver in context.DRIVERs on trips.DRIVER_ID_ equals driver.ID_ select new AvailableDriverList() { userProfilePicture = driver.USER.PICTURE_, userFirstName = driver.USER.FIRSTNAME_, userPreference = driver.USER.PREFERENCE, dateScheduled = trips.DATE_SCHEDULED_, availableSeats = trips.SEATS_, // need to figure out a way to calculate seats tripId = trips.ID_, }).ToList(); listDriverTripInfo.AddRange(results); } } return listDriverTripInfo; }
private List<LOCATION> lookupMatchingLocationsInDB(List<LOCATION> listOfRequestLocations) { List<LOCATION> tempMatch = new List<LOCATION>(); using (Hyk_Database_ModelContainer context = new Hyk_Database_ModelContainer()) { context.Configuration.ProxyCreationEnabled = false; context.Configuration.LazyLoadingEnabled = false; foreach (LOCATION requestedlocation in listOfRequestLocations) { List<LOCATION> locationsFromDB = (from dbLocations in context.LOCATIONs where dbLocations.CITY_ == requestedlocation.CITY_ where dbLocations.PROVINCE_ == requestedlocation.PROVINCE_ select dbLocations).ToList(); if (locationsFromDB.Any()) { resultOfLocationsFromDB.Add(locationsFromDB); } } if (resultOfLocationsFromDB.Count > 1) { LOCATION[][] arraysLocation = resultOfLocationsFromDB.Select(a => a.ToArray()).ToArray(); for (int a = 0; a < arraysLocation.Length - 1; a++) { for (int b = a + 1; b < arraysLocation.Length; b++) { List<LOCATION> resultMatch = (from startLocations in arraysLocation[a] from endLocations in arraysLocation[b] where startLocations.TRIPID_ == endLocations.TRIPID_ where startLocations.SEQUENCE_ <= endLocations.SEQUENCE_ select startLocations).ToList(); if (resultMatch.Any()) { tempMatch.AddRange(resultMatch); } } } if(tempMatch.Any())return tempMatch; } } return null; }
private List<LOCATION> lookupMatchingLocationsInDB(string startCity, string startProvince, string endCity, string endProvince) { using (Hyk_Database_ModelContainer context = new Hyk_Database_ModelContainer()) { context.Configuration.ProxyCreationEnabled = false; context.Configuration.LazyLoadingEnabled = false; List<LOCATION> resultStartLocations = (from locations in context.LOCATIONs where locations.CITY_ == startCity where locations.PROVINCE_ == startProvince select locations).ToList(); if (resultStartLocations.Any()) { List<LOCATION> resultEndStopLocations = (from locations in context.LOCATIONs where locations.CITY_ == endCity where locations.PROVINCE_ == endProvince select locations).ToList(); if (resultEndStopLocations.Any()) { List<LOCATION> resultMatch = (from startLocations in resultStartLocations from endLocations in resultEndStopLocations where startLocations.TRIPID_ == endLocations.TRIPID_ where startLocations.SEQUENCE_ <= endLocations.SEQUENCE_ select startLocations).ToList(); if (resultMatch.Any()) { return resultMatch; } } } return null; } }