public ActionResult <Exercise> AddExerciseToTraining(int trainingId, int exerciseId) { var training = _trainingen.GetbyId(trainingId); var exercise = _exercises.GetbyId(exerciseId); if (training == null) { return(NotFound()); } if (exercise == null) { return(NotFound()); } try { training.AddExerciseToTraining(exercise); _trainingen.SaveChanges(); return(Ok(exercise)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public ActionResult <ExerciseEvaluation> CreateEvaluation([FromBody] EvaluationDTO model, int trainingId, int exerciseId) { var training = _trainings.GetbyId(trainingId); var exercise = _exercises.GetbyId(exerciseId); if (training == null) { return(NotFound("Geen training met dit Id gevonden")); } if (exercise == null) { return(NotFound("Geen oefening met dit Id gevonden")); } try { ExerciseEvaluation ee = new ExerciseEvaluation(model.Note, model.FeelingOfExercise, model.Weight, model.Repetitions, model.Sets, exercise); training.AddExerciseEvaluationToTraining(ee); _evaluations.SaveChanges(); _trainings.SaveChanges(); return(Ok(ee)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public ActionResult <Training> RemoveTraining(int id) { Training trainingToDelete = _trainings.GetbyId(id); if (trainingToDelete == null) { return(NotFound()); } try { _trainings.Remove(trainingToDelete); _trainings.SaveChanges(); return(Ok(trainingToDelete)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }