public async Task <IActionResult> Create(AthleteWorkoutCreateViewModel viewModel, [FromRoute] int id) { if (ModelState.IsValid) { //athleteWorkout.WorkoutId = id; // aw.WorkoutId = id; //viewModel.AthleteWorkouts.WorkoutId = id; //viewModel.AthleteWorkouts.WorkoutId = id; List <int> AthleteIdsToPost = viewModel.SelectedAthletes; foreach (int i in AthleteIdsToPost) { AthleteWorkout aw = new AthleteWorkout { AthleteId = i, WorkoutId = id, Pace = viewModel.AthleteWorkouts.Pace, Distance = viewModel.AthleteWorkouts.Distance, Repetition = viewModel.AthleteWorkouts.Repetition, WorkoutDate = viewModel.AthleteWorkouts.WorkoutDate }; _context.Add(aw); } await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Workouts")); } return(View(viewModel)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,AthleteId,WorkoutId,Distance,Pace,Repetition,WorkoutDate")] AthleteWorkout athleteWorkout) { if (id != athleteWorkout.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(athleteWorkout); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AthleteWorkoutExists(athleteWorkout.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AthleteId"] = new SelectList(_context.Athletes, "Id", "FirstName", athleteWorkout.AthleteId); ViewData["WorkoutId"] = new SelectList(_context.Workouts, "Id", "Description", athleteWorkout.WorkoutId); return(View(athleteWorkout)); }