public async Task <IActionResult> PutExerciseWorkout(int id, ExerciseWorkout exerciseWorkout) { if (id != exerciseWorkout.ExerciseId) { return(BadRequest()); } _context.Entry(exerciseWorkout).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExerciseWorkoutExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult AddExercise(AddWorkoutExerciseViewModel addWorkoutExerciseViewModel) { if (ModelState.IsValid) { var exerciseID = addWorkoutExerciseViewModel.ExerciseID; var workoutID = addWorkoutExerciseViewModel.WorkoutID; IList <ExerciseWorkout> existingItems = context.ExerciseWorkouts .Where(cm => cm.ExerciseID == exerciseID) .Where(cm => cm.WorkoutID == workoutID).ToList(); if (existingItems.Count == 0) { ExerciseWorkout workoutItem = new ExerciseWorkout { Exercise = context.Exercises.Single(e => e.ExerciseID == exerciseID), Workout = context.Workouts.Single(w => w.WorkoutID == workoutID) }; context.ExerciseWorkouts.Add(workoutItem); context.SaveChanges(); } return(Redirect(string.Format("/Workout/ViewWorkout/{0}", addWorkoutExerciseViewModel.WorkoutID))); } return(View(addWorkoutExerciseViewModel)); }
public async Task <ActionResult <ExerciseWorkout> > PostExerciseWorkout(ExerciseWorkout exerciseWorkout) { _context.ExerciseWorkout.Add(exerciseWorkout); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (ExerciseWorkoutExists(exerciseWorkout.ExerciseId)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetExerciseWorkout", new { id = exerciseWorkout.ExerciseId }, exerciseWorkout)); }