示例#1
0
        public IActionResult AddQuestion(string Question, int F_N, int Category)
        {
            if (Question == null)
            {
                return(RedirectToAction(nameof(NewSurvey)));
            }
            if (Category == 0)
            {
                return(RedirectToAction(nameof(NewSurvey)));
            }
            var CreateQuestion = new Question {
                GroupId = 1, CategoryId = Category, Text = Question, Type = F_N
            };

            SurveyID = getSurveyID();

            if (ModelState.IsValid)
            {
                context.Add(CreateQuestion);
                context.SaveChanges();

                QuestionID = getQuestionID();
                var CreateLink = new SurveyQuestion {
                    QuestionId = QuestionID, SurveyId = SurveyID
                };

                context.Add(CreateLink);
                context.SaveChanges();

                return(RedirectToAction(nameof(NewSurvey)));
            }
            return(View());
        }
示例#2
0
        public IActionResult Save(int[] score, string[] comment, int SurveyID, int ParticipantID)
        {
            int    scores, question, scount = 0, ccount = 0;
            var    questions = getQuestionsBySurvey(SurveyID);
            string comments;

            if (ModelState.IsValid)
            {
                for (int i = 0; i < (score.Length + comment.Length); i++)
                {
                    question = questions.ElementAt(i).QuestionId;

                    if (questions.ElementAt(i).Type.ToString().Equals("0"))
                    {
                        comments = comment[ccount];
                        scores   = -1;
                        ccount++;
                    }
                    else
                    {
                        comments = null;
                        scores   = score[scount];
                        scount++;
                    }

                    var surveyResponses = new SurveyResponse {
                        SurveyId = SurveyID, QuestionId = question, ParticipantId = ParticipantID, Score = scores, Comment = comments
                    };

                    context.Add(surveyResponses);
                    context.SaveChanges();
                }
                return(RedirectToAction(nameof(ThankYou)));
            }
            return(View());
        }