public void UpdateAnswer(AnswerInfo a)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository<AnswerInfo>();
         rep.Update(a);
     }
 }
        public HttpResponseMessage AddAnswer(AnswerInfo answerDto)
        {
            try
            {
                Requires.NotNull("answerDto.AnswerId", answerDto.AnswerId);
                Requires.NotNegative("answerDto.QuestionId", answerDto.QuestionId);
                Requires.NotNull("answerDto.AnswerText", answerDto.AnswerText);
                Requires.NotNegative("answerDto.ModuleId", answerDto.ModuleId);
                Requires.NotNegative("answerDto.OrderIndex", answerDto.OrderIndex);
                Requires.NotNegative("answerDto.CreatedByUserId", answerDto.CreatedByUserId);
                Requires.NotNegative("answerDto.LastModifiedByUserId", answerDto.LastModifiedByUserId);

                var ac = new AnswerController();

                // get the answer from the database to maintain data integrity
                var answer = ac.GetAnswer(answerDto.AnswerId, answerDto.ModuleId);

                if (answer == null)
                {
                    UserInfo _currentUser = UserController.Instance.GetCurrentUserInfo();
                    int UserID = _currentUser.UserID;
                    // this is a new question
                    // update all values
                    answer = new AnswerInfo()
                    {
                        QuestionId				= answerDto.QuestionId,
                        AnswerId				= answerDto.AnswerId,
                        AnswerText				= answerDto.AnswerText,
                        ModuleId				= answerDto.ModuleId,
                        OrderIndex				= answerDto.OrderIndex,
                        AssignedUserId          = UserID,
                        CreatedByUserId			= answerDto.CreatedByUserId,
                        LastModifiedByUserId	= answerDto.LastModifiedByUserId,
                        LastModifiedOnDate		= DateTime.Now,
                        CreatedOnDate			= DateTime.Now
                    };

                    ac.CreateAnswer(answer);
                }
                else
                {
                    // this is an existing question that's getting updated
                    // we'll only update the values that are allowed to be updated
                    answer.AnswerText				= answerDto.AnswerText;
                    answer.QuestionId				= answerDto.QuestionId;
                    answer.AnswerId					= answerDto.AnswerId;
                    answer.OrderIndex				= answerDto.OrderIndex;
                    answer.LastModifiedByUserId		= answerDto.LastModifiedByUserId;
                    answer.LastModifiedOnDate		= DateTime.Now;
                    answer.CreatedOnDate			= DateTime.Now;

                    ac.UpdateAnswer(answer);
                }

                return Request.CreateResponse(HttpStatusCode.OK);
            }
            catch (Exception exc)
            {
                Exceptions.LogException(exc);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc);
            }
        }