public async Task <IActionResult> Edit(int formId, FormQuestionViewModel viewModel) { if (formId != viewModel.Form.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var form = new Form { Id = formId, Title = viewModel.Form.Title, Description = viewModel.Form.Description.ToStringOrEmpty() }; _repository.Update(form); await _repository.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!await FormExistsAsync(formId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Edit", "Questions", new { formId })); } return(View()); }
public IActionResult GetAllStatementForms(int id, [FromServices] IIoTManager ioTManager) { List <Form> forms = _formManager.GetAllStatementForms(id).ToList(); List <FormViewModel> formViewModels = new List <FormViewModel>(); foreach (Form form in forms) { IotLink iotLink = ioTManager.GetIoTLinkByForm(form); FormViewModel formViewModel = new FormViewModel() { Title = form.Title, FormId = form.FormId, Questions = new List <FormQuestionViewModel>(), IotLink = iotLink }; FormQuestionViewModel question = new FormQuestionViewModel() { Question = form.Questions[0].QuestionString }; formViewModel.Questions.Add(question); formViewModels.Add(formViewModel); } return(Ok(formViewModels)); }
public async Task <IActionResult> Edit(int?formId) { if (formId == null) { return(NotFound()); } var form = await _repository.FindAsync(formId.Value); if (form == null) { return(NotFound()); } var viewModel = new FormQuestionViewModel { Form = new FormViewModel { Id = form.Id, Title = form.Title, Description = form.Description } }; return(View(viewModel)); }
private void DeleteQuestion(object sender, FormQuestionViewModel formQuestionVM) { if (formQuestionVM.Id != 0) { inspectionFormViewModel.RemovedQuestions.Add(formQuestionVM.Id); } inspectionFormViewModel.FormQuestions.Remove(formQuestionVM); }
private void root_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args) { var context = args.NewValue; if (context != null) { this.FormQuestionViewModel = context as FormQuestionViewModel; } }
public QuestionBuilder() { this.InitializeComponent(); MultpleChoices = new List <string>(); FormQuestionViewModel = new FormQuestionViewModel(); dropDownItems = new DropDownItems(); //TODO: load from database dropDownItems.AddItem("image", "Afbeelding"); dropDownItems.AddItem("multiple_choice", "Meerkeuze"); dropDownItems.AddItem("open", "Open Vraag"); }
public void EditQuestion(FormQuestionViewModel formQuestionViewModel) { this.InEditMode = true; this.editFormQuestionViewModel = formQuestionViewModel; this.Question = formQuestionViewModel.Question; FieldQuestionType.SelectedValue = this.dropDownItems.GetOption(formQuestionViewModel.QuestionType); this.QuestionType = formQuestionViewModel.QuestionType; this.MultpleChoices = formQuestionViewModel.MultpleChoices; this.Instructions = formQuestionViewModel.Instructions; FillableList.SetOptions(this.MultpleChoices); SaveBtn.Content = "Update"; Bindings.Update(); }
public async Task <IActionResult> Edit(int?formId, int?questionId, bool?newOption, FormQuestionViewModel viewModel) { if (formId == null || questionId == null) { return(NotFound()); } var form = await _formRepository.FindAsync(formId.Value); if (form == null) { return(NotFound()); } var question = form.Questions.SingleOrDefault(question => question.Id == questionId); if (question == null) { return(NotFound()); } question.Text = viewModel.Question.Text; question.Type = viewModel.Question.Type.ToQuestionType(); question.IsRequired = viewModel.Question.IsRequired; question.Options = JsonConvert.SerializeObject(viewModel.Question.SelectedOptions.Where(option => !string.IsNullOrEmpty(option)).ToList()); var model = new FormQuestionViewModel(form, question); // this logic should be moved to its own action if (newOption.HasValue) { model.Question.SelectedOptions.Add(string.Empty); } if (ModelState.IsValid) { try { _formRepository.Update(form); await _formRepository.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } } return(View(model)); }
public async Task <IActionResult> Edit(int?formId, int?questionId) { if (formId == null) { return(NotFound()); } var form = await _formRepository.FindAsync(formId.Value); if (form == null) { return(NotFound()); } Question question = null; if (questionId == null) { question = form.Questions.FirstOrDefault(); if (question == null) { question = await AddNewQuestion(form); } } else { if (questionId == 0) // this logic should be moved to another action { question = await AddNewQuestion(form); } else { question = form.Questions.SingleOrDefault(question => question.Id == questionId); if (question == null) { return(NotFound()); } } } var viewModel = new FormQuestionViewModel(form, question); return(View("Edit", viewModel)); }
public async Task <IActionResult> Index(int?formId) { if (formId == null) { return(NotFound()); } var form = await _formRepository.FindAsync(formId.Value); var viewModel = new FormQuestionViewModel { Form = form.ToViewModel() }; return(View(viewModel)); }
public IActionResult Reply(int id) { Form form = _formManager.GetForm(id); if (form == null) { return(RedirectToAction("NotFound", "Home")); } var subdomain = Util.Util.GetSubdomain(HttpContext.Request.Host.ToString()); var formSubDomain = form.Project.Platform.Tenant; if (subdomain != formSubDomain) { return(NotFound()); } ViewBag.ProjectId = form.Project.ProjectId; var formVM = new FormViewModel() { FormId = form.FormId, Title = form.Title, Questions = new List <FormQuestionViewModel>() }; foreach (Question question in form.Questions) { var questionVM = new FormQuestionViewModel() { Question = question.QuestionString, FieldType = question.FieldType, Options = question.Options, Required = question.Required, LongAnswer = question.LongAnswer }; formVM.Questions.Add(questionVM); } _unitOfWorkManager.Save(); return(View(formVM)); }
private void StackPanel_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e) { var templateId = Int32.Parse((sender as StackPanel).Tag.ToString()); var template = inspectionViewModel.Templates.Where(t => t.Id == templateId).First(); template.Questions.ForEach(questionVM => { var newModel = new FormQuestion() { Question = questionVM.GetModel().Question, Instructions = questionVM.GetModel().Instructions, Type = questionVM.GetModel().Type, Multplechoice = questionVM.GetModel().Multplechoice.Select(x => new Multplechoice() { Option = x.Option }).ToList() }; var a = new FormQuestionViewModel(newModel); inspectionViewModel.SelectedInspectionForm.FormQuestions.Add(a); }); }
private void onEditEvent(object sender, FormQuestionViewModel formQuestionViewModel) { questionBuilder.EditQuestion(formQuestionViewModel); }
private void DeleteQuestion(object sender, FormQuestionViewModel formQuestionVM) { inspectionFormViewModel.FormQuestions.Remove(formQuestionVM); }
private void ExpandGroupbox_onDeleteEvent(object sender, FormQuestionViewModel formQuestionViewModel) { inspectionViewModel.SelectedInspectionForm.FormQuestions.Remove(formQuestionViewModel); inspectionViewModel.SelectedInspectionForm.RemovedQuestions.Add(formQuestionViewModel.Id); listViewQuestions.ItemsSource = inspectionViewModel.SelectedInspectionForm.FormQuestions; }