示例#1
0
        public void SaveAnswer(AnswerViewModel answervm)
        {
            Answer answer = null;

            if (answervm.Id > 0)
            {
                answer = u_repo.GetAnswer(a => a.Id == answervm.Id);
            }
            else if (answervm.MapComponentYearsId > 0 && answervm.QuestionId > 0)
            {
                answer = u_repo.GetAnswer(a => a.MapComponentYearsId == answervm.MapComponentYearsId &&
                                          a.QuestionId == answervm.QuestionId);
            }

            if (answer == null)
            {
                answer = answervm.ToAnswer();
            }

            try
            {
                answer.Text = answervm.Text;
                u_repo.DoSaveAnswer(answer);
            }
            catch (ArgumentNullException)
            {
                throw new PhenotypeException("Invalid answer to save");
            }
        }