public void UpdateQuestion(QuestionInfo q)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository<QuestionInfo>();
         rep.Update(q);
     }
 }
        public HttpResponseMessage DeleteQuestion(QuestionInfo question)
        {
            try
            {
                Requires.NotNull("question", question);
                Requires.NotNegative("question.ModuleId", question.ModuleId);
                Requires.NotNegative("question.VideoId", question.QuestionId);

                var qc = new QuestionController();
                qc.DeleteQuestion(question.QuestionId, question.ModuleId);

                return Request.CreateResponse(HttpStatusCode.OK);
            }
            catch (Exception exc)
            {
                Exceptions.LogException(exc);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc);
            }
        }
        public HttpResponseMessage AddQuestion(QuestionInfo questionDto)
        {
            try
            {
                Requires.NotNull("questionDto", questionDto);
                Requires.NotNegative("questionDto.QuestionId", questionDto.QuestionId);
                Requires.NotNegative("questionDto.VideoId", questionDto.VideoId);
                Requires.NotNull("questionDto.QuestionText", questionDto.QuestionText);
                Requires.NotNegative("questionDto.ModuleId", questionDto.ModuleId);
                Requires.NotNegative("questionDto.OrderIndex", questionDto.OrderIndex);
                Requires.NotNegative("questionDto.CreatedByUserId", questionDto.CreatedByUserId);
                Requires.NotNegative("questionDto.LastModifiedByUserId", questionDto.LastModifiedByUserId);

                var qc = new QuestionController();

                // get the question from the database to maintain data integrity
                var question = qc.GetQuestion(questionDto.QuestionId, questionDto.ModuleId);

                if (question == null)
                {
                    // this is a new question
                    // update all values
                    question = new QuestionInfo()
                    {
                        QuestionId = questionDto.QuestionId,
                        VideoId = questionDto.VideoId,
                        QuestionText = questionDto.QuestionText,
                        ModuleId = questionDto.ModuleId,
                        OrderIndex = questionDto.OrderIndex,
                        CreatedByUserId = questionDto.CreatedByUserId,
                        LastModifiedByUserId = questionDto.LastModifiedByUserId,
                        LastModifiedOnDate = DateTime.Now,
                        CreatedOnDate = DateTime.Now
                    };

                    qc.CreateQuestion(question);
                }
                else
                {
                    // this is an existing question that's getting updated
                    // we'll only update the values that are allowed to be updated
                    question.QuestionText = questionDto.QuestionText;
                    question.VideoId = questionDto.VideoId;
                    question.OrderIndex = questionDto.OrderIndex;
                    question.LastModifiedByUserId = questionDto.LastModifiedByUserId;
                    question.LastModifiedOnDate = DateTime.Now;

                    qc.UpdateQuestion(question);
                }

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