Exemplo n.º 1
0
        private async Task <SQuestion> CreateQuestionAsync(Survey quiz, SQuestionViewModel model)
        {
            SQuestion question = new SQuestion();

            question.SurveyID       = quiz.ID;
            question.IsQuiz         = false;
            question.Title          = model.Title;
            question.TypeOfQuestion = Operations.GetQuestionType(model.TypeOfQuestion);

            if (model.CorrectOption != null)
            {
                question.Options = new List <Option>();
                question.Options.Add(model.CorrectOption);
                question.Options.AddRange(model.Options);
            }

            question.IsActive   = true;
            question.ModifiedOn = DateTime.Now;

            db.SQuestions.Add(question);

            await db.SaveChangesAsync();

            return(question);
        }
Exemplo n.º 2
0
        private async Task <SQuestion> DeleteQuestionAsync(Survey quiz, SQuestionViewModel model, SQuestion question)
        {
            foreach (var attemptedQuestion in db.AttemptedQuestions.Where(at => at.Question.ID == question.ID).ToList())
            {
                attemptedQuestion.IsActive   = false;
                attemptedQuestion.ModifiedOn = DateTime.Now;

                db.Entry(attemptedQuestion).State = System.Data.Entity.EntityState.Modified;
            }

            question.IsActive   = false;
            question.ModifiedOn = DateTime.Now;

            db.Entry(question).State = System.Data.Entity.EntityState.Modified;

            await db.SaveChangesAsync();

            return(question);
        }
Exemplo n.º 3
0
        private async Task <SQuestion> UpdateQuestionAsync(Survey quiz, SQuestionViewModel model, SQuestion question)
        {
            foreach (var option in question.Options.ToList())
            {
                option.IsActive   = false;
                option.ModifiedOn = DateTime.Now;

                db.Entry(question).State = System.Data.Entity.EntityState.Modified;
            }

            question.SurveyID       = quiz.ID;
            question.Title          = model.Title;
            question.TypeOfQuestion = Operations.GetQuestionType(model.TypeOfQuestion);
            if (model.CorrectOption != null)
            {
                question.Options = new List <Option>();
                question.Options.Add(model.CorrectOption);
                question.Options.AddRange(model.Options);
            }


            question.ModifiedOn = DateTime.Now;

            db.Entry(question).State = System.Data.Entity.EntityState.Modified;

            await db.SaveChangesAsync();

            return(question);
        }