private async Task CreateForms(ExerciseBody exerciseBody, Exercise newExercise) { // delete old await exerciseRepository.DeleteFormsAsync(newExercise.Id); // create new newExercise.ExerciseForms = new List <ExerciseForm>(); List <MovementForm> exerciseForms = new List <MovementForm>(); foreach (MovementForm form in exerciseBody.Forms) { // if movement form was already added if (exerciseForms.Contains(form)) { continue; } ExerciseForm newForm = new ExerciseForm { Exercise = newExercise, MovementForm = form }; newExercise.ExerciseForms.Add(newForm); exerciseForms.Add(newForm.MovementForm); } }
public async Task <Exercise> CreateExercise(ExerciseBody exerciseBody) { // create exercise Exercise newExercise = new Exercise { Name = exerciseBody.Name, Media = exerciseBody.Media, ExerciseSteps = new List <ExerciseStep>(), ExerciseRequirements = new List <ExerciseRequirement>(), ExerciseForms = new List <ExerciseForm>() }; // create exercise steps await CreateSteps(exerciseBody, newExercise); // create exercise requirements await CreateRequirements(exerciseBody, newExercise); // create exercise forms await CreateForms(exerciseBody, newExercise); // save exercise to database newExercise = await exerciseRepository.CreateAsync(newExercise); return(newExercise); }
private async Task CreateRequirements(ExerciseBody exerciseBody, Exercise newExercise) { // delete old await exerciseRepository.DeleteRequirementsAsync(newExercise.Id); // create new newExercise.ExerciseRequirements = new List <ExerciseRequirement>(); foreach (string requirement in exerciseBody.Requirements) { ExerciseRequirement newRequirement = new ExerciseRequirement { Exercise = newExercise, Requirement = requirement }; newExercise.ExerciseRequirements.Add(newRequirement); } }
private async Task CreateSteps(ExerciseBody exerciseBody, Exercise newExercise) { // delete old await exerciseRepository.DeleteStepsAsync(newExercise.Id); // create new newExercise.ExerciseSteps = new List <ExerciseStep>(); int stepCount = 1; foreach (string step in exerciseBody.Steps) { ExerciseStep newStep = new ExerciseStep { Exercise = newExercise, StepNumber = stepCount, StepDescription = step }; newExercise.ExerciseSteps.Add(newStep); stepCount++; } }
public async Task <Exercise> UpdateExercise(int exerciseId, ExerciseBody exerciseBody) { // update exercise Exercise updatedExercise = new Exercise() { Id = exerciseId, Name = exerciseBody.Name, Media = exerciseBody.Media, ExerciseSteps = null, ExerciseRequirements = null, ExerciseForms = null }; // create exercise requirements if (exerciseBody.Requirements != null) { await CreateRequirements(exerciseBody, updatedExercise); } // create exercise steps if (exerciseBody.Steps != null) { await CreateSteps(exerciseBody, updatedExercise); } // create exercise forms if (exerciseBody.Forms != null) { await CreateForms(exerciseBody, updatedExercise); } // save exercise to database Exercise exercise = await exerciseRepository.UpdateAsync(updatedExercise); return(exercise); }