public void EditAthleteSave(EditAthleteViewModel athlete) { var UserPerTest = context.UserTestMappers.Where(u => u.TestID == athlete.TestId).Where(u => u.UserID == athlete.AthleteId).FirstOrDefault(); if (athlete.CooperDistance != 0) { UserPerTest.CooperTestDistance = athlete.CooperDistance; UserPerTest.FitnessRating = CalculateFitness(athlete.CooperDistance); } else { UserPerTest.SprintTestTime = athlete.SprintTime; } context.UserTestMappers.Update(UserPerTest); }
public async Task <IActionResult> EditAthleteAsync([FromRoute] int testId, [FromRoute] string athleteId, [FromBody] EditAthleteViewModel model) { var UserPerTest = context.UserTestMappers.Include(u => u.Users).Where(u => u.TestID == testId).Where(u => u.UserID == athleteId).FirstOrDefault(); UserPerTest.Users.UserName = model.Users.UserName; if (model.CooperTestDistance != null) { UserPerTest.CooperTestDistance = model.CooperTestDistance; UserPerTest.FitnessRating = CalculateFitness(model.CooperTestDistance); } else { UserPerTest.SprintTestTime = model.SprintTestTime; } context.UserTestMappers.Update(UserPerTest); await context.SaveChangesAsync(); return(Ok(model)); }
public IActionResult EditAthleteSave([FromForm] EditAthleteViewModel athlete) { uof.Test.EditAthleteSave(athlete); uof.Save(); return(RedirectToAction("TestDetails", new { id = testId })); }