public string addTrip(string userID, string tripDate, string startTime,string data) { List<tripData> li = new List<tripData>(); dbManager db = new dbManager(); trip t = new trip(); t.userID = Convert.ToInt32(userID); t.tripDate = tripDate; t.startTime = startTime; //get an id to link the data to the trip int tripID = db.addUserTrip(t); //saves to database //process data string StringReader reader = new StringReader(data); string line; var context = new drivestatsEntities(); using (var transactionScope = new TransactionScope()) { context.Configuration.AutoDetectChangesEnabled = false; context.Configuration.ValidateOnSaveEnabled = false; int count = 0; while (reader.Peek() > -1) { count++; tripData d = new tripData(); d.tripID = tripID; line = reader.ReadLine(); string lat = line.Substring(1, line.IndexOf(',')-1); line = line.Remove(0, lat.Length + 3); string lon = line.Substring(0, line.IndexOf(']')); line = line.Remove(0, lon.Length + 2); string speed = line.Substring(0, line.IndexOf(';')); line = line.Remove(0, speed.Length + 1); string x = line.Substring(0, line.IndexOf(';')); line = line.Remove(0, x.Length + 1); string y = line.Substring(0, line.IndexOf(';')); line = line.Remove(0, y.Length + 1); string z = line.Substring(0, line.IndexOf(';')); d.latitude = lat; d.longitude = lon; d.speed = speed; d.maxXAcelerometer = x; d.maxYAcelerometer = y; d.maxZAcelerometer = z; li.Add(d); } context.BulkInsert(li); context.SaveChanges(); transactionScope.Complete(); if (userID == "1")//test client { return "5.3"; } } ScoreCalculator score = new ScoreCalculator(li,3); return score.getscore().ToString(); }
public void inserTripData(tripData td) { using (var context = new drivestatsEntities()) { context.tripDatas.Add(td); context.SaveChanges(); } }