public async Task <IActionResult> Edit(Guid id, ChoicesCreateEditViewModel vm) { if (id != vm.Choice.Id) { return(NotFound()); } if (ModelState.IsValid) { try { await _uow.Choices.UpdateAsync(vm.Choice); await _uow.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ChoiceExists(vm.Choice.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Details", "Questions", new { id = vm.Choice.QuestionId })); } vm.Questions = new SelectList(await _uow.Questions.GetAllAsync(), nameof(Question.Id), nameof(Question.Title)); return(View(vm)); }
public async Task <IActionResult> Create(ChoicesCreateEditViewModel vm) { if (ModelState.IsValid) { vm.Choice.Id = Guid.NewGuid(); _uow.Choices.Add(vm.Choice); await _uow.SaveChangesAsync(); return(RedirectToAction("Details", "Questions", new { id = vm.Choice.QuestionId })); } vm.Questions = new SelectList(await _uow.Questions.GetAllAsync(), nameof(Question.Id), nameof(Question.Title)); return(View(vm)); }
// GET: Choices/Create public IActionResult Create(Guid?question) { var vm = new ChoicesCreateEditViewModel() { Questions = new SelectList(_uow.Questions.GetAll(), nameof(Question.Id), nameof(Question.Title)) }; if (question.HasValue) { vm.Choice = new Choice { QuestionId = question.Value }; } return(View(vm)); }
// GET: Choices/Edit/5 public async Task <IActionResult> Edit(Guid?id) { if (id == null) { return(NotFound()); } var vm = new ChoicesCreateEditViewModel() { Choice = await _uow.Choices.FirstOrDefaultAsync(id.Value) }; if (vm.Choice == null) { return(NotFound()); } vm.Questions = new SelectList(await _uow.Questions.GetAllAsync(), nameof(Question.Id), nameof(Question.Title)); return(View(vm)); }