public SurveysShellResult CreateSurveyShellResultForTest(long surveysResultId, List<SurveysAnswerContent> surveysAnswerContents)
        {
            using (var shellResultRepository = new BaseRepository<SurveysShellResult>())
            {
                SurveysResult surveysResult =
                    shellResultRepository.Context.SurveysResults.FirstOrDefault(x => x.Id == surveysResultId);
                if (surveysResult == null)
                {
                    throw new SurveysResultDoesNotExistException();
                }

                // Surveys shell result existing
                SurveysShellResult foundedSurveyShellResult =
                    shellResultRepository.GetAllItems.FirstOrDefault(x => x.SurveyResultId == surveysResultId);

                // surveysResult.Methods_type == "Test"
                if (!String.Equals(surveysResult.MethodsType, Constraints.KMethodsTypeTest))
                {
                    return null;
                }
                Test test = shellResultRepository.Context.Tests.FirstOrDefault(x => x.Id == surveysResult.MethodsId);
                if (test == null)
                {
                    throw new TestPackageDoesNotExistException();
                }

                Person person =
                    shellResultRepository.Context.Persons.FirstOrDefault(x => x.Id == surveysResult.Person.Id);
                if (person == null)
                {
                    throw new PersonDoesNotExistException();
                }

                int shellMethodId = ResultConverter.GetConsulMethodId(test.CodeName);

                String answerStr = ResultConverter.GenerateAnswerString(test.CodeName, surveysAnswerContents, true);

                if (foundedSurveyShellResult == null)
                {
                    // Create row in surveysShellResult
                    SurveysShellResult surveysShellResult = new SurveysShellResult()
                    {
                        MethodsId = surveysResult.MethodsId,
                        MethodsType = surveysResult.MethodsType,
                        PersonId = person.Id,
                        ShellMethodId = shellMethodId,
                        TestDate = surveysResult.Date,
                        Answer = answerStr,
                        SurveyResultId = surveysResult.Id
                    };
                    if (!shellResultRepository.Create(surveysShellResult).Status)
                    {
                        throw new CreateException();
                    }
                    return surveysShellResult;
                }
                else
                {
                    foundedSurveyShellResult.MethodsId = surveysResult.MethodsId;
                    foundedSurveyShellResult.MethodsType = surveysResult.MethodsType;
                    foundedSurveyShellResult.PersonId = person.Id;
                    foundedSurveyShellResult.ShellMethodId = shellMethodId;
                    foundedSurveyShellResult.TestDate = surveysResult.Date;
                    foundedSurveyShellResult.Answer = answerStr;
                    foundedSurveyShellResult.SurveyResultId = surveysResult.Id;

                    if (!shellResultRepository.Update(foundedSurveyShellResult).Status)
                    {
                        throw new UpdateException();
                    }
                    return foundedSurveyShellResult;
                }

            }
        }
        public void AddShellResult(WebPerson person, SurveysShellResult surveysShellResult, String testCodeName, String answerStr)
        {
            //try
            //{
                _connection.Open();
                int count = -1;

                // Check OldUser exists
                String name = person.FirstName + " " + person.LastName;

                if (name.Length == 1)
                {
                    name = person.Email;
                }
                String gender = String.Empty;
                if (person.Gender)
                {
                    gender = "M";
                }
                else
                {
                    gender = "F";
                }
                String query = @"SELECT count(*) FROM [USER] where [NAME] = '" + name + "'" +
                           " AND [GENDER] = '" + gender + "' AND [DATE] = #" + person.BirthDate.ToString("yyyy-MM-dd") + "#";

                var command = new OleDbCommand(query, _connection);
                var reader = command.ExecuteReader();
                while (reader.Read())
                {
                    count = reader.GetInt32(0);
                }
                if (count <= 0)
                {
                    // Cut name to 30 symbols
                    if (name.Length >= 30)
                    {
                        name = name.Remove(29);
                    }

                    // Create OldUser
                    query = "INSERT INTO [USER] (NAME, GENDER, [DATE]) VALUES('"
                        + name + "', '" + gender + "', #" + person.BirthDate.ToString("yyyy-MM-dd") + "#)";
                    command = new OleDbCommand(query, _connection);
                    if (command.ExecuteNonQuery() <= 0)
                    {
                        throw new ConsulDBException();
                    }

                }

                // GET id of OldUser
                int userId = -1;

                query = @"SELECT ID FROM [USER] where [NAME] = '" + name + "'" +
                        " AND [GENDER] = '" + gender + "' AND [DATE] = #" + person.BirthDate.ToString("yyyy-MM-dd") + "#";

                command = new OleDbCommand(query, _connection);
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    userId = reader.GetInt32(0);
                }

                var comment = surveysShellResult.TestDate.ToString("dd.MM.yyyy_HH.mm.ss") + "_"
                                  + person.FirstName + "_"
                                  + person.LastName + "_"
                                  + person.BirthDate.ToString("dd.MM.yyyy") + "_"
                                  + testCodeName;

                // Create result
                query = "INSERT INTO [RESULT] (U_ID, M_ID, DATA, COMMENT, [DATE]) VALUES ("
                        + userId + ", " + surveysShellResult.ShellMethodId + ", '" + answerStr + "', '" + comment + "', #" + surveysShellResult.TestDate.ToString("yyyy-MM-dd HH:mm:ss") + "#)";
                command = new OleDbCommand(query, _connection);
                if (command.ExecuteNonQuery() <= 0)
                {
                    throw new ConsulDBException();
                }

                _connection.Close();
            //}
            //catch (Exception)
            //{
            //    throw new ConsulDBException();
            //}
        }