Exemplo n.º 1
0
        public DataModel.Questions UpdateQuestion(DataModel.Questions obj)
        {
            tblQuizQuestion Question = context.tblQuizQuestions.Where(q => q.QuestionId == obj.QuestionId).FirstOrDefault();

            if (Question == null)
            {
                return(obj);
            }
            Question.QuestionId   = obj.QuestionId;
            Question.QuizId       = obj.QuizId;
            Question.QuestionText = obj.QuestionText;
            Question.IsActive     = obj.IsActive;
            Question.UpdatedAt    = DateTime.Now;
            Question.UpdatedBy    = obj.UpdatedBy;


            context.Entry(Question).State = EntityState.Modified;
            //context.Entry(question).CurrentValues.SetValues(Question);
            int saved = context.SaveChanges();

            if (saved > 0)
            {
                obj.UpdatedAt    = Question.UpdatedAt.Value;
                obj.CreatedAt    = Question.CreatedAt.Value;
                obj.Success      = true;
                obj.ErrorMessage = "Question updated successfully.";
            }
            else
            {
                obj.UpdatedAt    = Question.UpdatedAt.Value;
                obj.CreatedAt    = Question.CreatedAt.Value;
                obj.Success      = false;
                obj.ErrorMessage = "Error occured while updating question.";
            }

            return(obj);
        }
Exemplo n.º 2
0
        public DataModel.Questions Add(DataModel.Questions obj)
        {
            if (obj.QuestionId != 0)
            {
                return(UpdateQuestion(obj));
            }

            var             existing = context.tblQuizQuestions.Where(x => x.QuestionText == obj.QuestionText && x.QuizId == obj.QuizId).FirstOrDefault();
            tblQuizQuestion Question = new tblQuizQuestion();

            Question.QuizId       = obj.QuizId;
            Question.QuestionText = obj.QuestionText;
            Question.IsActive     = obj.IsActive;
            Question.CreatedAt    = DateTime.Now;
            Question.CreatedBy    = obj.CreatedBy;
            Question.UpdatedAt    = DateTime.Now;

            if (existing != null)
            {
                obj.ErrorMessage = "Question with same text already exists";
                obj.Success      = false;
                obj.CreatedAt    = Question.CreatedAt.Value;
                obj.UpdatedAt    = Question.UpdatedAt.Value;
                return(obj);
            }
            context.tblQuizQuestions.Add(Question);
            context.SaveChanges();

            //Assuming the database is generating your Id's for you
            obj.QuestionId   = Question.QuestionId;
            obj.CreatedAt    = Question.CreatedAt.Value;
            obj.UpdatedAt    = Question.UpdatedAt.Value;
            obj.Success      = true;
            obj.ErrorMessage = "Question saved successfully.";

            return(obj);
        }
Exemplo n.º 3
0
 public DataModel.Questions Update(DataModel.Questions obj)
 {
     return(null);
 }