Exemple #1
0
        public static DataTable GetSurveyResult(int SurveyQuestionID)
        {
            SurveyChoice objSurvey = new SurveyChoice();

            objSurvey.SurveyQuestionID = SurveyQuestionID;
            return(objSurvey.LoadByParams().Tables[0]);
        }
Exemple #2
0
        public void Save(int SurveyID, bool isActive, bool isMain, string SurveyQuestion, DataTable dtSurveyChoices)
        {
            int IdentityQuestion = 0;

            BINROTA.DAL.SurveyQuestion objSurveyQuestion;
            BINROTA.DAL.SurveyChoice   objSurveyChoice;

            // Soruyu Kaydet
            objSurveyQuestion = new SurveyQuestion();
            if (SurveyID == 0)
            {
                DeleteSurveyChoices(SurveyID);
                objSurveyQuestion.Load(SurveyID);
            }
            objSurveyQuestion.isActive       = isActive;
            objSurveyQuestion.isMain         = isMain;
            objSurveyQuestion.SurveyQuestion = SurveyQuestion;
            IdentityQuestion = objSurveyQuestion.Save();

            //Seçenekleri Kaydet
            foreach (DataRow dr in dtSurveyChoices.Rows)
            {
                objSurveyChoice = new SurveyChoice();
                objSurveyChoice.SurveyChoice     = dr["SurveyChoice"].ToString();
                objSurveyChoice.SurveyVoteNumber = Convert.ToInt32(dr["SurveyVoteNumber"]);
                objSurveyChoice.SurveyQuestionID = IdentityQuestion;
                objSurveyChoice.Save();
            }
        }
        public async Task <IActionResult> Edit(SurveyQuestion question)
        {
            if (!ModelState.IsValid)
            {
                return(View(question));
            }

            var existingQuestion = await _dbContext.SurveyQuestions.FirstOrDefaultAsync(q => q.Id == question.Id);

            if (existingQuestion.TypeId == QuestionType.Radio || existingQuestion.TypeId == QuestionType.Checkbox)
            {
                var existingChoices = await _dbContext.SurveyChoices.Where(c => c.QuestionId == existingQuestion.Id).ToListAsync();

                _dbContext.SurveyChoices.RemoveRange(existingChoices);
                await _dbContext.SaveChangesAsync();
            }

            existingQuestion.Text              = question.Text;
            existingQuestion.QuestionNumber    = question.QuestionNumber;
            existingQuestion.TypeId            = question.TypeId;
            existingQuestion.LastModifiedAtUtc = DateTime.UtcNow;
            existingQuestion.Category          = question.Category;
            existingQuestion.Weight            = question.Weight;
            existingQuestion.ActiveStatus      = QuestionActiveStatus.Active;

            _dbContext.SurveyQuestions.Update(existingQuestion);
            await _dbContext.SaveChangesAsync();


            // Makes sure we don't experience an error message when checking if there are any choices.
            if (question.RadioOptions != null && question.TypeId != QuestionType.Text)
            {
                var newChoices = new List <SurveyChoice>();

                for (var i = 0; i < question.RadioOptions.Count; i++)
                {
                    // Since the choice(s) aren't valid without the text field and would cause an error we need to check
                    if (question.RadioOptions[i] != null)
                    {
                        var choice = new SurveyChoice
                        {
                            Id              = Guid.NewGuid(),
                            QuestionId      = question.Id,
                            Text            = question.RadioOptions[i],
                            OrderInQuestion = i
                        };

                        newChoices.Add(choice);
                    }
                }

                await _dbContext.SurveyChoices.AddRangeAsync(newChoices);

                await _dbContext.SaveChangesAsync();
            }

            return(RedirectToAction("Index"));
        }
Exemple #4
0
        public static void AnswerInsert(int MemberID, int SurveyQuestionID, int SurveyChoiceID)
        {
            //TODO: Transection yapacaksýn haberin ola
            SurveyAnswer objSurvey = new SurveyAnswer();

            objSurvey.MemberID         = MemberID;
            objSurvey.SurveyQuestionID = SurveyQuestionID;
            objSurvey.SurveyChoiceID   = SurveyChoiceID;
            objSurvey.Save();

            SurveyChoice obj = new SurveyChoice();

            obj.Load(SurveyChoiceID);
            obj.SurveyVoteNumber++;
            obj.Save();
        }
Exemple #5
0
        /// <summary>
        /// Creates SurveyChoice for records In the prefilled DataReader, And puts them into a HashTable
        /// </summary>
        /// <param name="dr">The DataReader prefilled With the SurveyChoice records</param>
        /// <returns>The Hashtable containing SurveyChoice objects And their ID As key.</returns>
        protected static Hashtable ConvertReaderToHashTable(SqlDataReader dr)
        {
            Hashtable result = new Hashtable();

            while (dr.Read())
            {
                SurveyChoice mySurveyChoice = new SurveyChoice();

                mySurveyChoice.m_intSurveyChoiceID   = dr.GetSqlInt32(0);
                mySurveyChoice.m_intSurveyQuestionID = dr.GetSqlInt32(1);
                mySurveyChoice.m_strSurveyChoice     = dr.GetSqlString(2);
                mySurveyChoice.m_intSurveyVoteNumber = dr.GetSqlInt32(3);

                result.Add(mySurveyChoice.SurveyChoiceID, mySurveyChoice);
            }

            return(result);
        }
        public async Task <IActionResult> Create(SurveyQuestion question)
        {
            if (!ModelState.IsValid)
            {
                return(View(question));
            }

            // Create any new questions as active since there is no input on the form to do so.
            question.ActiveStatus = QuestionActiveStatus.Active;

            await _dbContext.SurveyQuestions.AddAsync(question);

            await _dbContext.SaveChangesAsync();


            // Makes sure we don't experience an error message when checking if there are any choices.
            if (question.RadioOptions != null && question.TypeId != QuestionType.Text)
            {
                var choices = new List <SurveyChoice>();

                for (var i = 0; i < question.RadioOptions.Count; i++)
                {
                    // Since the choice(s) aren't valid without the text field and would cause an error we need to check
                    if (question.RadioOptions[i] != null)
                    {
                        var choice = new SurveyChoice
                        {
                            Id              = Guid.NewGuid(),
                            QuestionId      = question.Id,
                            Text            = question.RadioOptions[i],
                            OrderInQuestion = i
                        };

                        choices.Add(choice);
                    }
                }

                await _dbContext.SurveyChoices.AddRangeAsync(choices);

                await _dbContext.SaveChangesAsync();
            }

            return(RedirectToAction("Index"));
        }