Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
 private void DeleteQuestion(object sender, FormQuestionViewModel formQuestionVM)
 {
     if (formQuestionVM.Id != 0)
     {
         inspectionFormViewModel.RemovedQuestions.Add(formQuestionVM.Id);
     }
     inspectionFormViewModel.FormQuestions.Remove(formQuestionVM);
 }
Esempio n. 5
0
        private void root_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            var context = args.NewValue;

            if (context != null)
            {
                this.FormQuestionViewModel = context as FormQuestionViewModel;
            }
        }
Esempio n. 6
0
        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");
        }
Esempio n. 7
0
 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();
 }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
        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));
        }
Esempio n. 10
0
        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));
        }
Esempio n. 11
0
        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));
        }
Esempio n. 12
0
        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);
            });
        }
Esempio n. 13
0
 private void onEditEvent(object sender, FormQuestionViewModel formQuestionViewModel)
 {
     questionBuilder.EditQuestion(formQuestionViewModel);
 }
Esempio n. 14
0
 private void DeleteQuestion(object sender, FormQuestionViewModel formQuestionVM)
 {
     inspectionFormViewModel.FormQuestions.Remove(formQuestionVM);
 }
Esempio n. 15
0
 private void ExpandGroupbox_onDeleteEvent(object sender, FormQuestionViewModel formQuestionViewModel)
 {
     inspectionViewModel.SelectedInspectionForm.FormQuestions.Remove(formQuestionViewModel);
     inspectionViewModel.SelectedInspectionForm.RemovedQuestions.Add(formQuestionViewModel.Id);
     listViewQuestions.ItemsSource = inspectionViewModel.SelectedInspectionForm.FormQuestions;
 }