public async Task UpdateExercise(int exerciseId, MakeOrUpdateExerciseVM makeOrUpdateExerciseVM) { var exercise = await GetExerciseById(exerciseId); exercise.Title = makeOrUpdateExerciseVM.Title; exercise.Description = makeOrUpdateExerciseVM.Description; exercise.MaxPoints = makeOrUpdateExerciseVM.MaxPoints; await context.SaveChangesAsync(); }
public async Task <IActionResult> UpdateExercise(int ExerciseId) { MakeOrUpdateExerciseVM makeOrUpdateExerciseVM = new MakeOrUpdateExerciseVM(); var exercise = await exerciseRepository.GetExerciseById(ExerciseId); makeOrUpdateExerciseVM.Description = exercise.Description; makeOrUpdateExerciseVM.Title = exercise.Title; makeOrUpdateExerciseVM.MaxPoints = exercise.MaxPoints; return(View(makeOrUpdateExerciseVM)); }
public async Task <int> AddExercise(MakeOrUpdateExerciseVM makeExerciseVM) { var userId = userService.GetUserId(); var User = context.Users.FirstOrDefault(x => x.Id == userId); var newExercise = new Exercise { Title = makeExerciseVM.Title, Description = makeExerciseVM.Description, CreatedAt = DateTime.Now, MaxPoints = makeExerciseVM.MaxPoints, Creator = User, CreatorId = userId, }; await context.Exercises.AddAsync(newExercise); await context.SaveChangesAsync(); return(newExercise.ExerciseId); }
public async Task <IActionResult> UpdateExercise(int ExerciseId, MakeOrUpdateExerciseVM makeOrUpdateExerciseVM) { await exerciseRepository.UpdateExercise(ExerciseId, makeOrUpdateExerciseVM); return(RedirectToAction("Index")); }
public async Task <IActionResult> AddExercise(MakeOrUpdateExerciseVM makeExerciseVM) { int id = await exerciseRepository.AddExercise(makeExerciseVM); return(RedirectToAction("Index")); }