Beispiel #1
0
 //[ValidateAntiForgeryToken]
 public IActionResult ExtendAjax([FromBody] AnswerGroupViewModel answerGroup)
 {
     if (ModelState.IsValid)
     {
         var toUpdate = _answerGroupService.GetById(answerGroup.Id);
         var result   = _answerGroupService.Extend(toUpdate);
         return(RedirectToAction("Index", new { id = answerGroup.SurveyId, selected = answerGroup.SectionGroupId }));
     }
     ViewData["SectionGroupId"] = new SelectList(_context.SectionGroup, "Id", "SectionGroup", answerGroup.SectionGroupId);
     ViewData["SurveyId"]       = new SelectList(_context.Survey, "Id", "Survey", answerGroup.SurveyId);
     return(RedirectToAction("Index", new { id = answerGroup.SurveyId, selected = answerGroup.SectionGroupId }));
 }
Beispiel #2
0
        public IActionResult EditAjax(int id)
        {
            var answerGroup = _answerGroupService.GetById(id);

            if (answerGroup == null)
            {
                return(HttpNotFound());
            }
            AnswerGroupViewModel editAnswerGroupViewModel = new AnswerGroupViewModel(answerGroup);

            return(PartialView(@"_EditAnswerGroup", editAnswerGroupViewModel));
        }
Beispiel #3
0
        //[ValidateAntiForgeryToken]
        public IActionResult Edit(AnswerGroupSelectViewModel selectViewModel, string command)
        {
            foreach (var answerGroup in selectViewModel.AnswerGroupsViewModel)
            {
                var existingAnswerGroup = _answerGroupService.GetById(answerGroup.Id);
                if (existingAnswerGroup != null)
                {
                    if (existingAnswerGroup.Address == null)
                    {
                        existingAnswerGroup.Address = new Address();
                    }
                    existingAnswerGroup.Address.AddressLine1 = answerGroup.AddressLine1;
                    existingAnswerGroup.Address.PostalCode   = answerGroup.PostalCode;
                    existingAnswerGroup.Address.City         = answerGroup.City;
                    existingAnswerGroup.Address.Country      = answerGroup.Country;

                    foreach (var answerSection in answerGroup.AnswerSection)
                    {
                        AnswerSection existingAnswerSection = existingAnswerGroup.AnswerSection.Where(item => item.Id == answerSection.Id).FirstOrDefault();
                        if (existingAnswerSection != null)
                        {
                            foreach (var answer in answerSection.Answer)
                            {
                                Answer existingAnswer = existingAnswerSection.Answer.Where(item => item.Id == answer.Id).FirstOrDefault();
                                existingAnswer.AnswerText      = answer.AnswerText;
                                existingAnswer.DefaultComments = answer.Comments;
                                existingAnswer.OptionId        = answer.OptionId;
                            }
                        }
                    }
                    _answerGroupService.Save(existingAnswerGroup);
                }
            }

            switch (command)
            {
            case "Save":
                break;

            case "Extend":
                AnswerGroupViewModel result = selectViewModel.AnswerGroupsViewModel.OrderBy(item => item.SortOrder).FirstOrDefault();
                var existingAnswerGroup     = _answerGroupService.GetById(result.Id);
                _answerGroupService.Extend(existingAnswerGroup);
                break;
            }

            if (ModelState.IsValid)
            {
                return(RedirectToAction("Index", new { id = selectViewModel.SurveyId, selected = selectViewModel.SectionGroupId }));
            }
            return(RedirectToAction("Index", new { id = selectViewModel.SurveyId, selected = selectViewModel.SectionGroupId }));
        }
Beispiel #4
0
        // GET: AnswerGroups/Edit/5
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            var answerGroup = _answerGroupService.GetById(id.Value);

            if (answerGroup == null)
            {
                return(HttpNotFound());
            }

            AnswerGroupViewModel editAnswerGroupViewModel = new AnswerGroupViewModel(answerGroup);

            return(View(editAnswerGroupViewModel));
        }
Beispiel #5
0
        //[ValidateAntiForgeryToken]
        public IActionResult EditAjax([FromBody] AnswerGroupViewModel answerGroup)
        {
            var toUpdate = _answerGroupService.GetById(answerGroup.Id);

            toUpdate.IsUsed = answerGroup.IsUsed;
            var result = _answerGroupService.Save(toUpdate);

            var answerGroups = _answerGroupService.GetBySurveyAndSectionGroupId(answerGroup.SurveyId, answerGroup.SectionGroupId);

            if (answerGroups == null)
            {
                return(HttpNotFound());
            }
            AnswerGroupSelectViewModel selectViewModel = new AnswerGroupSelectViewModel()
            {
                SurveyId = answerGroup.SurveyId, SectionGroupId = answerGroup.SectionGroupId
            };

            foreach (var answerGroupUpdated in answerGroups)
            {
                selectViewModel.AnswerGroupsViewModel.Add(new AnswerGroupViewModel(answerGroupUpdated));
            }
            return(PartialView(@"_EditAnswerGroups", selectViewModel));
        }