예제 #1
0
파일: AnswerDto.cs 프로젝트: HP-dufeng/WIKI
        public static AnswerDto MapToDto(this Entities.Answer entity)
        {
            var mapper = new MapperConfiguration(config =>
                                                 config.CreateMap <Entities.Answer, AnswerDto>()
                                                 .ForMember(m => m.AnswerId, opt => opt.MapFrom(s => s.Id))
                                                 .ForMember(m => m.Id, opt => opt.MapFrom(s => s.Id + "." + s.QuestionId))
                                                 .AfterMap((s, d) =>
            {
                d.join_field = new JoinField
                {
                    name   = "answer",
                    parent = s.QuestionId
                };

                d.ExpandProperty = new ExpandProperty
                {
                    CreatedBy     = s.EX_CreatedBy,
                    UpdatedBy     = s.EX_UpdatedBy,
                    CreatedByDept = s.EX_CreatedByDept,
                    UpdatedByDept = s.EX_UpdatedByDept
                };

                d.Audit = new Audit
                {
                    CreatedBy   = s.CreatedBy,
                    CreatedTime = s.CreatedTime,
                    UpdatedBy   = s.UpdatedBy,
                    UpdatedTime = s.UpdatedTime
                };
            })
                                                 ).CreateMapper();

            return(mapper.Map <AnswerDto>(entity));
        }
        protected void updateProbabilities(PossibleStatesWithPossibilities existingpossibleStatesWithPossibilities, StudentGetOneTestQueryResult.Question answeredQuestion)
        {
            List <int> realAnswersCorrect = new List <int>();

            foreach (StudentGetOneTestQueryResult.Answer a in answeredQuestion.Answers)
            {
                Entities.Answer realAnswer = _answerRepository.getAnswerById(a.AnswerId);
                if (realAnswer.Correct)
                {
                    realAnswersCorrect.Add(realAnswer.AnswerId);
                }
            }
            int flag = 0;

            foreach (StudentGetOneTestQueryResult.Answer studentsAnswer in answeredQuestion.SelectedAnswers)
            {
                if (realAnswersCorrect.Contains(studentsAnswer.AnswerId))
                {
                    flag += 1;
                }
            }
            if (realAnswersCorrect.Count() == flag)
            {
                foreach (Problem state in existingpossibleStatesWithPossibilities.states)
                {
                    List <string> splitedTitle = state.Title.Split(" ").ToList();
                    if (splitedTitle.Contains(answeredQuestion.ProblemId.ToString()))
                    {
                        state.statePosibility = (float)(state.statePosibility * 1.3);
                    }
                }
            }
            else
            {
                foreach (Problem state in existingpossibleStatesWithPossibilities.states)
                {
                    List <string> splitedTitle = state.Title.Split(" ").ToList();
                    if (splitedTitle.Contains(answeredQuestion.ProblemId.ToString()))
                    {
                        state.statePosibility = (float)(state.statePosibility * 0.6);
                    }
                }
            }
        }
예제 #3
0
        public int InsertAnswer(Entities.Answer answer)
        {
            int answerId = 0;

            _dbRead.Execute(
                "AnswerInsert",
                new[] {
                new SqlParameter("@CreatedDate", answer.CreatedDate),
                new SqlParameter("@Vote", answer.Vote),
                new SqlParameter("@Flags", answer.Flags),
                new SqlParameter("@IdUser", answer.IdUser),
                new SqlParameter("@Id_qst", answer.IdQuestion),
                new SqlParameter("@HtmlRep", answer.HTMLRep),
                new SqlParameter("@InternalRep", answer.InternalRep)
            },
                r => answerId = Read <int>(r, "Id")
                );
            return(answerId);
        }
        public ActionResult SaveAnswer(Entities.Answer obj)
        {
            using (ApplicationDbContext data = new ApplicationDbContext())
            {
                if (obj.id == 0)
                {
                    data.Answers.Add(obj);
                }
                else
                {
                    Answer answ = data.Answers.FirstOrDefault(f => f.id == obj.id);

                    answ.Name        = obj.Name;
                    answ.Correct     = obj.Correct;
                    answ.Description = obj.Description;
                }

                data.SaveChanges();
            }

            return(null);
        }
예제 #5
0
 public int Insert(Entities.Answer answer)
 {
     return(_repository.InsertAnswer(answer));
 }