public static bool AddPullData(XContainer xc, List<Station> stationList) { try { string LastUpdate = xc.Element("stations").Attribute("lastUpdate").Value; CaBiDataContext dc = new CaBiDataContext(); if ((from p in dc.Pulls where p.DateSignature == LastUpdate select p).Count<Pull>() == 0) { Pull p = new Pull(); p.DateSignature = LastUpdate; p.PullDate = DateTime.Now; dc.Pulls.InsertOnSubmit(p); dc.SubmitChanges(); int pullID = (from pid in dc.Pulls where pid.DateSignature == LastUpdate select pid.PullID).First<int>(); foreach (Station s in stationList) { if ((from ps in dc.PulledStations where ps.StationID == s.id select ps).Count<PulledStation>() == 0) { CaBiDataContext dcsub = new CaBiDataContext(); PulledStation ps = new PulledStation(); ps.StationID = s.id; ps.StationName = s.name; ps.Latitude = s.lat; ps.Longitude = s.lng; ps.Installed = s.installed; ps.Locked = s.locked; ps.Temporary = s.temporary; dcsub.PulledStations.InsertOnSubmit(ps); dcsub.SubmitChanges(); } PullResult pr = new PullResult(); pr.PullID = pullID; pr.StationID = s.id; pr.Docked = s.bikeCount; pr.Empty = s.dockCount; pr.Installed = s.installed; pr.Locked = s.locked; pr.Temporary = s.temporary; dc.PullResults.InsertOnSubmit(pr); } dc.SubmitChanges(); } return true; } catch { return false; } }
public static bool AddPullData(XContainer xc, List <Station> stationList) { try { string LastUpdate = xc.Element("stations").Attribute("lastUpdate").Value; CaBiDataContext dc = new CaBiDataContext(); if ((from p in dc.Pulls where p.DateSignature == LastUpdate select p).Count <Pull>() == 0) { Pull p = new Pull(); p.DateSignature = LastUpdate; p.PullDate = DateTime.Now; dc.Pulls.InsertOnSubmit(p); dc.SubmitChanges(); int pullID = (from pid in dc.Pulls where pid.DateSignature == LastUpdate select pid.PullID).First <int>(); foreach (Station s in stationList) { if ((from ps in dc.PulledStations where ps.StationID == s.id select ps).Count <PulledStation>() == 0) { CaBiDataContext dcsub = new CaBiDataContext(); PulledStation ps = new PulledStation(); ps.StationID = s.id; ps.StationName = s.name; ps.Latitude = s.lat; ps.Longitude = s.lng; ps.Installed = s.installed; ps.Locked = s.locked; ps.Temporary = s.temporary; dcsub.PulledStations.InsertOnSubmit(ps); dcsub.SubmitChanges(); } PullResult pr = new PullResult(); pr.PullID = pullID; pr.StationID = s.id; pr.Docked = s.bikeCount; pr.Empty = s.dockCount; pr.Installed = s.installed; pr.Locked = s.locked; pr.Temporary = s.temporary; dc.PullResults.InsertOnSubmit(pr); } dc.SubmitChanges(); } return(true); } catch { return(false); } }
partial void DeletePulledStation(PulledStation instance);
partial void UpdatePulledStation(PulledStation instance);
partial void InsertPulledStation(PulledStation instance);