コード例 #1
0
ファイル: ResultRepository.cs プロジェクト: sergiygladkyy/mbo
        /// <summary>
        /// Write record to db table Result (person, test, testdate)
        /// Write records to db table ResultItems (webResults: array of questionId and answerId)
        /// </summary>
        /// <param name="personId"></param>
        /// <param name="testId"></param>
        /// <param name="webResults"></param>
        /// <returns></returns>
        public Result SaveResults(int personId, int testId, ICollection<WebConcreteQuestion> webResults)
        {
            var userRepo = new AuthorizationRepository();
            if (!userRepo.IsUserExist(personId))
            {
                throw new UserDoesNotExistException();
            }

            var testRepo = new TestRepository();
            var test = testRepo.GetTestById(testId);
            if (test == null)
            {
                throw new MethodsDoesNotExistException();
            }

            ////TODO : Temporary. Block writing results of test Kot
            //if (String.Equals(test.CodeName, Constraints.KKotCodeName))
            //{
            //    return null;
            //}

            using (var repository = new BaseRepository<Result>())
            {

                var resultItems = new List<ResultItem>();
                //TODO : Hack. If test is Kot we dont save resultItems. In future refactor ResultItems structure
                if (!String.Equals(test.CodeName, Constraints.KKotCodeName))
                {
                    foreach (var webConcreteQuestion in webResults)
                    {

                        resultItems.AddRange(
                            webConcreteQuestion.Answers.Select(
                                answerItem =>
                                new ResultItem
                                    {
                                        Id = Guid.NewGuid(),
                                        QuestionId = webConcreteQuestion.Id,
                                        AnswerId = Convert.ToInt64(answerItem.Id)
                                    }));

                    }
                }

                var resultList = new Result
                                     {
                                         Id = Guid.NewGuid(),
                                         TestId = testId,
                                         UserId = personId,
                                         TestDate = DateTime.Now,
                                         ResultItems = resultItems
                                     };
                repository.Create(resultList);
                return resultList;
            }
        }
コード例 #2
0
ファイル: ResultRepository.cs プロジェクト: sergiygladkyy/mbo
        /// <summary>
        /// Return list of tests with testdate, which person was tetsed
        /// DataBase table: Results
        /// </summary>
        /// <param name="personId"></param>
        /// <returns></returns>
        public List<Result> GetResultsByPerson(int personId)
        {
            var userRepo = new AuthorizationRepository();
            if (!userRepo.IsUserExist(personId))
            {
                throw new UserDoesNotExistException();
            }

            using (var resultRepo = new BaseRepository<Result>())
            {
                return resultRepo.GetAllItems.Where(x => x.UserId == personId).ToList();
            }
        }