コード例 #1
0
        //[CheckReferrer]
       
        public virtual async Task<ActionResult> Create(AddArticleEvaluationBindingModel bindingModel)
        {
            if (!_referentialTeacherService.CanManageTeacher(bindingModel.TeacherId)) return HttpNotFound();

            if (!ModelState.IsValid)
            {
                this.NotyError("متأسفانه مشکلی در انجام عملیات بوجود آمده است");
                return RedirectToAction(MVC.ArticleEvaluation.Create(bindingModel.ArticleId));
            }
            await _evaluationService.Create(bindingModel);
            this.NotySuccess("علمیات با موفقیت انجام شد");
            return RedirectToAction(MVC.ArticleEvaluation.List(bindingModel.ArticleId));
        }
コード例 #2
0
        public async Task Create(AddArticleEvaluationBindingModel bindingModel)
        {
            var currentUserId = _userManager.GetCurrentUserId();

            var questionIds = new List<Guid>();
            if (bindingModel.CheckBoxListQuestions != null && bindingModel.CheckBoxListQuestions.Any())
                questionIds.AddRange(bindingModel.CheckBoxListQuestions.Select(a => a.Id));
            if (bindingModel.NumericQuestions != null && bindingModel.NumericQuestions.Any())
                questionIds.AddRange(bindingModel.NumericQuestions.Select(a => a.Id));
            if (bindingModel.StringQuestions != null && bindingModel.StringQuestions.Any())
                questionIds.AddRange(bindingModel.StringQuestions.Select(a => a.Id));
            if (bindingModel.RadioButtonListQuestions != null && bindingModel.RadioButtonListQuestions.Any())
                questionIds.AddRange(bindingModel.RadioButtonListQuestions.Select(a => a.Id));



            var answerOptionIds = new List<Guid>();

            if (bindingModel.CheckBoxListQuestions != null && bindingModel.CheckBoxListQuestions.Any())
                answerOptionIds.AddRange(bindingModel.CheckBoxListQuestions.Where(a => a.OptionIds != null && a.OptionIds.Any())
                    .SelectMany(a => a.OptionIds));

            if (bindingModel.RadioButtonListQuestions != null && bindingModel.RadioButtonListQuestions.Any())
                answerOptionIds.AddRange(bindingModel.RadioButtonListQuestions.Where(a => a.OptionId != null)
                    .Select(a => a.OptionId.Value));

            var actualQuestions = await _questionService.GetQuestionsByIdsAsync(questionIds);
            var actualAnswerOptions = await _answerOptionService.GetAnswerOptionsByIds(answerOptionIds);
            var newEvalution = new ArticleEvaluation
            {
                Brief = bindingModel.Brief.ToSafeHtml(),
                Content = bindingModel.Content.ToSafeHtml(),
                StrongPoint = bindingModel.StrongPoint.ToSafeHtml(),
                CreatorId = currentUserId,
                EvaluatorId = bindingModel.EvaluatorId,
                ArticleId = bindingModel.ArticleId,
                EvaluationDate = DateTime.Now

            };

            foreach (var item in actualQuestions)
            {
                newEvalution.Questions.Add(item);
            }


            if (bindingModel.NumericQuestions != null && bindingModel.NumericQuestions.Any())
            {
                foreach (var numericQuestion in bindingModel.NumericQuestions)
                {
                    newEvalution.ArticleEvaluationQuestions.Add(new ArticleEvaluationQuestion
                    {
                        ArticleEvaluationId = newEvalution.Id,
                        QuestionId = numericQuestion.Id,
                        CreatorId = currentUserId,
                        Value = numericQuestion.Value.ToString()
                    });
                }
            }

            if (bindingModel.StringQuestions != null && bindingModel.StringQuestions.Any())
            {
                foreach (var stringQuestion in bindingModel.StringQuestions)
                {
                    newEvalution.ArticleEvaluationQuestions.Add(new ArticleEvaluationQuestion
                    {
                        ArticleEvaluationId = newEvalution.Id,
                        QuestionId = stringQuestion.Id,
                        CreatorId = currentUserId,
                        Value = stringQuestion.Value.ToSafeHtml()
                    });
                }
            }

            var answerOptions = actualAnswerOptions as IList<AnswerOption> ?? actualAnswerOptions.ToList();
            if (actualAnswerOptions != null && answerOptions.Any())
            {
                foreach (var answerOption in answerOptions)
                {
                    newEvalution.AnswerOptions.Add(answerOption);
                }
            }
            _ArticleEvaluations.Add(newEvalution);
            await _unitOfWork.SaveAllChangesAsync();
        }