public void DeleteTrainingExercise(TrainingExerciseKey key) { var trainingExercise = GetTrainingExercise(key); if (trainingExercise != null) { _trainingExerciseModule.Delete(trainingExercise); SynchroManager.TrainingExerciseChange(DbContext, trainingExercise, true); if (trainingExercise.TrainingExerciseSets != null) { foreach (var trainingExerciseSet in trainingExercise.TrainingExerciseSets) { _trainingExerciseSetModule.Delete(trainingExerciseSet); } } } }
public TrainingExercise CreateTrainingExercise(TrainingExercise trainingExercise) { var result = _trainingExerciseModule.Create(trainingExercise); SynchroManager.TrainingExerciseChange(DbContext, result); if (result != null && trainingExercise.TrainingExerciseSets != null) { TrainingExerciseSet trainingExerciseSet; result.TrainingExerciseSets = new List <TrainingExerciseSet>(); foreach (var set in trainingExercise.TrainingExerciseSets) { trainingExerciseSet = _trainingExerciseSetModule.Create(set); result.TrainingExerciseSets.Add(trainingExerciseSet); } } return(result); }
public TrainingExercise UpdateTrainingExercise(TrainingExercise trainingExercise, bool manageDeleteLinkItem) { var result = _trainingExerciseModule.Update(trainingExercise); SynchroManager.TrainingExerciseChange(DbContext, result); if (result != null && trainingExercise.TrainingExerciseSets != null) { if (manageDeleteLinkItem) { // optimisation : massive delete _trainingExerciseSetModule.Delete(new TrainingExerciseSetKey() { UserId = trainingExercise.UserId, Year = trainingExercise.Year, WeekOfYear = trainingExercise.WeekOfYear, DayOfWeek = trainingExercise.DayOfWeek, TrainingDayId = trainingExercise.TrainingDayId, TrainingExerciseId = trainingExercise.Id }); result.TrainingExerciseSets = new List <TrainingExerciseSet>(); foreach (var set in trainingExercise.TrainingExerciseSets) { result.TrainingExerciseSets.Add(_trainingExerciseSetModule.Create(set)); } } else { result.TrainingExerciseSets = new List <TrainingExerciseSet>(); foreach (var set in trainingExercise.TrainingExerciseSets) { result.TrainingExerciseSets.Add(_trainingExerciseSetModule.Update(set)); } } } return(result); }