Example #1
0
        public async Task<tbSurveyQuestion> CreateNewQuestion(dtoSurveyQuestion question)
        {
            tbSurveyQuestion newQuestion = new tbSurveyQuestion();

            try
            {
                var questionCount = _db.tbSurveyQuestions.Where(x => x.SurveyId == question.SurveyId
                    && (x.IsActive ?? true) && !(x.IsDeleted ?? false)).Count();
                newQuestion.SurveyId = question.SurveyId;
                newQuestion.Question = question.Question;
                newQuestion.QuestionType = question.QuestionType;
                newQuestion.QuestionOrder = questionCount + 1;
                newQuestion.CreatedDate = DateTime.UtcNow;
                newQuestion.UpdatedDate = DateTime.UtcNow;
                newQuestion.IsActive = true;
                newQuestion.IsDeleted = false;

                _db.tbSurveyQuestions.Add(newQuestion);

                if (question.dtoItems != null)
                {
                    if (question.dtoItems.Count() > 0)
                    {
                        foreach (dtoSurveyQuestionItem item in question.dtoItems)
                        {
                            item.QuestionId = newQuestion.QuestionId;
                            await CreateNewItem(item);
                        }
                    }
                }

                await _db.SaveChangesAsync();
            }
            catch (DataException dex)
            {
                throw new ApplicationException("Data error!", dex);
            }

            return newQuestion;
        }
Example #2
0
        public async Task<tbSurveyQuestion> GetSurveyQuestionByQuestionId(int questionId)
        {
            tbSurveyQuestion question = new tbSurveyQuestion();

            try
            {
                question = await _db.tbSurveyQuestions.FirstOrDefaultAsync(x => x.QuestionId == questionId
                    && (x.IsActive ?? true) && !(x.IsDeleted ?? false));
            }
            catch (DataException dex)
            {
                throw new ApplicationException("Data error!", dex);
            }

            return question;
        }