public async Task <IActionResult> Edit(int id, [Bind("Id,Type,Date")] Test test) { if (id != test.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(test); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TestExists(test.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(test)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Distance,Time,FitnessRating,TId,UId")] UserTestMapping userTestMapping) { if (id != userTestMapping.Id) { return(NotFound()); } if (userTestMapping.Distance <= 1000) { userTestMapping.FitnessRating = "Below Average"; } else if (userTestMapping.Distance > 1000 && userTestMapping.Distance <= 2000) { userTestMapping.FitnessRating = "Average"; } else if (userTestMapping.Distance > 2000 && userTestMapping.Distance <= 3500) { userTestMapping.FitnessRating = "Good"; } else if (userTestMapping.Distance > 3500) { userTestMapping.FitnessRating = "Very good"; } if (ModelState.IsValid) { try { _context.Update(userTestMapping); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserTestMappingExists(userTestMapping.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Details", "Tests", new { Id = userTestMapping.TId })); } ViewData["TId"] = new SelectList(_context.Test, "Id", "Id", userTestMapping.TId); ViewData["UId"] = new SelectList(_context.User.Where(k => k.Type != "Coach"), "Id", "Name", userTestMapping.UId); return(View(userTestMapping)); }