// GET: Athletes/Details/5 public async Task <IActionResult> Details(int?id) { var currentUser = await GetCurrentUserAsync(); if (id == null) { return(NotFound()); } var athlete = await _context.Athletes .Include(a => a.AthleteRaces) .Include(a => a.AthleteWorkouts) .ThenInclude(aw => aw.Workout) .Where(a => a.Id == id) .FirstOrDefaultAsync(m => m.Id == id); if (athlete == null) { return(NotFound()); } AthleteDetailsViewModel model = new AthleteDetailsViewModel { Athlete = athlete, AthleteWorkouts = await _context.AthleteWorkouts.Select(a => a).Where(a => a.AthleteId == id && a.Athlete.UserId == currentUser.Id).ToListAsync(), }; return(View(model)); }
// GET: Athletes/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Athlete athlete = db.Athletes.Find(id); if (athlete == null) { return(HttpNotFound()); } AthleteDetailsViewModel viewModel = new AthleteDetailsViewModel(athlete); return(View(viewModel));//passing the viewModel here }