/// <summary> /// /// </summary> /// <param name="userId"></param> /// <param name="trainingSession"></param> /// <returns></returns> public bool SubmitTrainingData(int userId, TrainingSession trainingSession) { if (TrainingSessionRepository == null) { TrainingSessionRepository = new SqlDataAccess.Entities.View.TrainingSessionsRepository(); } if (TrainingSessionDataRepository == null) { TrainingSessionDataRepository = new NoSqlDataAccess.Entities.View.TrainingSessionMeasurmentDataRepository(); } Guid uniqueId = Guid.NewGuid(); GenericError error; trainingSession.UserId = userId; try { trainingSession.MeasurementInfo.TrainingSessionId = uniqueId; TrainingSessionDataRepository.InsertEntity(out error, trainingSession.MeasurementInfo); } catch (Exception e) { error = new GenericError() { ErrorDesc = e.Message }; } if (error == null) { try { // SAVE TO SQL SERVER trainingSession.TrainingSessionId = uniqueId; TrainingSessionRepository.InsertEntity(out error, trainingSession); } catch (Exception e) { error = new GenericError() { ErrorDesc = e.Message }; } } return(error == null); }
/// <summary> /// /// </summary> /// <param name="sessions"></param> /// <param name="trainingSession"></param> /// <param name="splitingSeconds"></param> public void SplitSessionAtSpecificTime(List <TrainingSession> sessions, TrainingSession trainingSession, DateTime splitingDateTime) { var measurmentData = GetSessionMeasurmentInfo(trainingSession.TrainingSessionId); var data = measurmentData.FirstOrDefault(); TrainingSessionMeasurmentData session2Data = null; TrainingSessionMeasurmentData session1Data = null; if (data != null) { session1Data = CopyPartialMeasurmentsData(data, (m, t) => m.Where(x => x.Time >= splitingDateTime).ToList()); session2Data = CopyPartialMeasurmentsData(data, (m, t) => m.Where(x => x.Time <= splitingDateTime).ToList()); //session1Data = CopyPartialMeasurmentsData(data, (m, t) => m.Take(GetIndexForTime(t, splitingSeconds)).ToList()); //session2Data = CopyPartialMeasurmentsData(data, (m, t) => m.Skip(GetIndexForTime(t, splitingSeconds)).ToList()); } if (session1Data != null && session2Data != null) { session1Data.TrainingSessionId = sessions[0].TrainingSessionId; session2Data.TrainingSessionId = sessions[1].TrainingSessionId; session1Data.UserId = trainingSession.UserId; session2Data.UserId = trainingSession.UserId; GenericError error; try { TrainingSessionDataRepository.InsertEntity(out error, session1Data); TrainingSessionDataRepository.InsertEntity(out error, session2Data); } catch (Exception e) { error = new GenericError { ErrorDesc = e.Message }; } if (error == null) { TrainingSessionsRepository.InsertEntity(out error, sessions); measurmentData.ToList().ForEach(md => TrainingSessionDataRepository.Remove(m => m.TrainingSessionId == md.TrainingSessionId, out error)); TrainingSessionsRepository.Remove(s => s.TrainingSessionId == trainingSession.TrainingSessionId, out error); } } }
/// <summary> /// /// </summary> /// <param name="session1Data"></param> public void InsertMeasurmentData(TrainingSessionMeasurmentData session1Data) { GenericError error; TrainingSessionDataRepository.InsertEntity(out error, session1Data); }