public async Task <ActionResult> DeleteExerciseAsync(int id) { var exercise = await exerciseRepository.GetByIdAsync(id); if (exercise == null) { return(NotFound()); } exerciseRepository.Delete(exercise); var saveResult = await exerciseRepository.SaveAllAsync(); if (!saveResult) { return(BadRequest("Unable to delete exercise.")); } return(NoContent()); }
public async Task CanDelete() { using var context = new DataContext(ContextOptions); var user = await GetUser(context); var exerciseRepo = new ExerciseRepository(context); var exerciseName = "Exercise test CanDelete"; await AddExercise(exerciseName, exerciseRepo, context); var exercise = (await exerciseRepo.GetAllByUserId(user.Id)).FirstOrDefault(x => x.Name == exerciseName); Assert.IsNotNull(exercise); // Delete exercise exerciseRepo.Delete(exercise); await exerciseRepo.SaveAll(); // Check is deleted var exercises = await exerciseRepo.GetAllByUserId(user.Id); Assert.IsFalse(exercises.Any(x => x.Name == exerciseName)); }
public ActionResult <Exercise> DeleteExercise([FromBody] Exercise exercise) { _exerciseRepository.Delete(exercise); return(CreatedAtAction(nameof(DeleteExercise), exercise)); }