Ejemplo n.º 1
0
        public IActionResult DeleteConfirmed(int id)
        {
            AnswerSection answerSection = _context.AnswerSection.Single(m => m.Id == id);

            _context.AnswerSection.Remove(answerSection);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public bool Save(Survey element)
        {
            if (element.Id == 0)
            {
                var surveyTemplate = _surveyTemplateRepo.GetById(element.SurveyTemplateId);
                var customer       = _customerRepo.Find(element.CustomerId);
                foreach (var sectionGroup in surveyTemplate.SectionGroup)
                {
                    var address = new Address()
                    {
                        Recipient = customer.Name, AddressLine1 = customer.Address
                    };
                    var answergroup = new AnswerGroup()
                    {
                        SectionGroupId = sectionGroup.Id,
                        SurveyId       = element.Id,
                        IsUsed         = sectionGroup.IsMandatory ? true : false,
                        Address        = address,
                    };

                    if (answergroup.IsUsed)
                    {
                        foreach (var section in sectionGroup.Section.OrderBy(item => item.SortOrder))
                        {
                            var answerSection = new AnswerSection()
                            {
                                SectionId = section.Id,
                                Order     = element.AnswerGroup.Count + 1
                            };

                            foreach (var question in section.Question.OrderBy(item => item.SortOrder))
                            {
                                var answer = new Answer()
                                {
                                    OptionId      = null,
                                    InHighlighted = false,
                                    IsFinal       = false,
                                    IsValid       = false,
                                    QuestionId    = question.Id,
                                    OptionGroupId = question.OptionGroupId
                                };
                                answerSection.Answer.Add(answer);
                            }
                            answergroup.AnswerSection.Add(answerSection);
                        }
                    }
                    element.AnswerGroup.Add(answergroup);
                }

                element = _surveyRepo.Add(element);
            }
            else
            {
                element = _surveyRepo.Update(element);
            }

            return(true);
        }
Ejemplo n.º 3
0
 public IActionResult Edit(AnswerSection answerSection)
 {
     if (ModelState.IsValid)
     {
         _context.Update(answerSection);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewData["AnswerGroupId"] = new SelectList(_context.AnswerGroup, "Id", "AnswerGroup", answerSection.AnswerGroupId);
     ViewData["SectionId"]     = new SelectList(_context.Section, "Id", "Section", answerSection.SectionId);
     return(View(answerSection));
 }
Ejemplo n.º 4
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 }));
        }
Ejemplo n.º 5
0
        // GET: AnswerSections/Details/5
        public IActionResult Details(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            AnswerSection answerSection = _context.AnswerSection.Single(m => m.Id == id);

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

            return(View(answerSection));
        }
Ejemplo n.º 6
0
        // GET: AnswerSections/Edit/5
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            AnswerSection answerSection = _context.AnswerSection.Single(m => m.Id == id);

            if (answerSection == null)
            {
                return(HttpNotFound());
            }
            ViewData["AnswerGroupId"] = new SelectList(_context.AnswerGroup, "Id", "AnswerGroup", answerSection.AnswerGroupId);
            ViewData["SectionId"]     = new SelectList(_context.Section, "Id", "Section", answerSection.SectionId);
            return(View(answerSection));
        }
Ejemplo n.º 7
0
 public AnswerSection Update(AnswerSection answerSection)
 {
     using (var dbContextTransaction = _context.Database.BeginTransaction())
     {
         try
         {
             _context.AnswerSection.Update(answerSection);
             _context.SaveChanges();
             dbContextTransaction.Commit();
         }
         catch (Exception)
         {
             dbContextTransaction.Rollback();
             throw;
         }
         return(answerSection);
     }
 }
Ejemplo n.º 8
0
        public bool Save(AnswerGroup answerGroup)
        {
            if (answerGroup.Id == 0)
            {
                answerGroup = _answerGroupRepo.Add(answerGroup);
            }
            else
            {
                if (answerGroup.IsUsed)
                {
                    if (!answerGroup.AddressId.HasValue)
                    {
                        if (answerGroup.Survey != null)
                        {
                            var customer = _customerRepo.Find(answerGroup.Survey.CustomerId);
                            answerGroup.Address = new Address()
                            {
                                Recipient = customer.Name, AddressLine1 = customer.Address
                            };
                        }
                        else
                        {
                            answerGroup.Address = new Address();
                        }
                    }

                    if (answerGroup.AnswerSection.Count() == 0)
                    {
                        foreach (var section in answerGroup.SectionGroup.Section.OrderBy(item => item.SortOrder))
                        {
                            var answerSection = new AnswerSection()
                            {
                                SectionId = section.Id,
                                Order     = answerGroup.AnswerSection.Count + 1
                            };

                            foreach (var question in section.Question.OrderBy(item => item.SortOrder))
                            {
                                var answer = new Answer()
                                {
                                    OptionId      = null,
                                    InHighlighted = false,
                                    IsFinal       = false,
                                    IsValid       = false,
                                    QuestionId    = question.Id,
                                    OptionGroupId = question.OptionGroupId
                                };
                                answerSection.Answer.Add(answer);
                            }
                            answerGroup.AnswerSection.Add(answerSection);
                        }
                    }
                    answerGroup = _answerGroupRepo.Update(answerGroup);
                }
                else
                {
                    answerGroup = _answerGroupRepo.Use(answerGroup);
                }
            }
            return(true);
        }
Ejemplo n.º 9
0
        public bool Extend(AnswerGroup answerGroup)
        {
            if (answerGroup.IsUsed)
            {
                var existingAnswerGroups = _answerGroupRepo.GetBySectionGroupId(answerGroup.SectionGroupId);
                int sortOrder            = existingAnswerGroups.Max(item => item.SortOrder);

                Address address;
                if (answerGroup.Survey != null)
                {
                    var customer = _customerRepo.Find(answerGroup.Survey.CustomerId);
                    address = new Address()
                    {
                        Recipient = customer.Name, AddressLine1 = customer.Address
                    };
                }
                else
                {
                    address = new Address();
                }

                var answerGroupForExtention = new AnswerGroup()
                {
                    Id             = 0,
                    SurveyId       = answerGroup.SurveyId,
                    SectionGroupId = answerGroup.SectionGroupId,
                    IsUsed         = answerGroup.IsUsed,
                    SortOrder      = sortOrder + 1,
                    Address        = address
                };

                foreach (var section in answerGroup.SectionGroup.Section.OrderBy(item => item.SortOrder))
                {
                    if (section.IsRepeatable)
                    {
                        var answerSection = new AnswerSection()
                        {
                            SectionId = section.Id,
                            Order     = answerGroup.AnswerSection.Count + 1
                        };

                        foreach (var question in section.Question.OrderBy(item => item.SortOrder))
                        {
                            var answer = new Answer()
                            {
                                OptionId      = null,
                                InHighlighted = false,
                                IsFinal       = false,
                                IsValid       = false,
                                QuestionId    = question.Id,
                                OptionGroupId = question.OptionGroupId
                            };
                            answerSection.Answer.Add(answer);
                        }
                        answerGroupForExtention.AnswerSection.Add(answerSection);
                    }
                }
                return(this.Save(answerGroupForExtention));
            }
            return(false);
        }