public async Task <IActionResult> EditExercise(int id) { var exercise = await _exerciseService.TakeExerciseById(id); var exerciseViewModel = new EditExerciseViewModel() { Name = exercise.Name }; return(View(exerciseViewModel)); }
public IActionResult EditExercise(EditExerciseViewModel viewModel) { var result = this.exercisesService.EditExercise(viewModel); if (result.Result > 0) { return(this.Redirect("/Exercises/AllExercises")); } return(this.View(viewModel)); }
public async Task <int> EditExercise(EditExerciseViewModel viewModel) { var exercise = this.exercisesRepository.All() .Where(x => x.Id == viewModel.Id) .FirstOrDefault(); exercise.Name = viewModel.Name; exercise.Description = viewModel.Description; this.db.Exercises.Update(exercise); return(await this.db.SaveChangesAsync()); }
public async Task <IActionResult> EditExercise(EditExerciseViewModel model) { var exercise = new Exercise() { Id = model.Id }; exercise.Name = model.Name; await _exerciseService.EditExercise(exercise); return(RedirectToAction("ShowAllExercises", "Administration")); }
public ActionResult EditExercise(int id, EditExerciseViewModel model) { try { if (ModelState.IsValid) { var result = adminServices.EditCurrentExercise(id, model, User.Identity.GetUserId()); return(PartialView("_EditExerciseResult", result)); } throw new Exception(); } catch { return(View(model)); } }
public EditExerciseViewModel GetExerciseDataCreated(int exerciseId) { var exerciseCreated = context.Exercises.FirstOrDefault(e => e.ExerciseId == exerciseId); var model = new EditExerciseViewModel(); var exercise = new ExerciseDTO(); var topic = new TopicDTO(); exercise.Problem = exerciseCreated.Problem; exercise.Development = exerciseCreated.Development; exercise.Solution = exerciseCreated.Solution; exercise.Description = exerciseCreated.Description; topic.TopicId = exerciseCreated.Topic.TopicId; model.Exercise = exercise; model.Topic = topic; model.ComboTopics = this.GetAllTopics(); return(model); }
public async Task <IActionResult> Edit(string exerciseId) { var exercise = await this.exercisesService.GetExercisesByIdAsync(exerciseId); if (exercise.Content == null) { exercise.Content = NullContent; } var viewModel = new EditExerciseViewModel { Title = exercise.Title, Content = exercise.Content, Gender = exercise.TypeOfGender.ToString(), Video = exercise.Video, }; viewModel.ExerciseId = exerciseId; return(this.View(viewModel)); }
public Boolean?EditCurrentExercise(int id, EditExerciseViewModel model, string userId) { try { Exercise exerciseToEdit = context.Exercises.FirstOrDefault(e => e.ExerciseId == id); exerciseToEdit.Problem = model.Exercise.Problem; exerciseToEdit.Development = model.Exercise.Development; exerciseToEdit.Solution = model.Exercise.Solution; exerciseToEdit.Description = model.Exercise.Description; exerciseToEdit.Topic = context.Topics.FirstOrDefault(t => t.TopicId == model.Topic.TopicId); exerciseToEdit.User = context.Users.FirstOrDefault(u => u.Id == userId); context.SaveChanges(); return(true); } catch { return(false); } }
public IActionResult EditExercise(int id) { var exercise = this.exercisesService.GetExerciseById(id); if (exercise == null) { return(this.RedirectToAction("Error")); } var toolsModel = this.exercisesService.GetAllToolsForExercise <ToolsListViewModel>(id); var viewModel = new EditExerciseViewModel { Id = exercise.Id, Name = exercise.Name, Description = exercise.Description, Tools = toolsModel.ToList(), }; return(this.View(viewModel)); }