Пример #1
0
        public string deleteOldLeftOverAnswers(Entities.QuizQuestion _updatedQuestion)
        {
            string _deletionResult = "Answers Deleted Successfully";

            try
            {
                List <FarmworkersWebAPI.Entities.QuizAnswer> _oldAnswers =
                    _context.QuizAnswers.
                    Where(q => q.QuizID.Equals(_updatedQuestion.QuizID) &&
                          q.QuizVersion.Equals(_updatedQuestion.QuizVersion) &&
                          q.QuestionID.Equals(_updatedQuestion.QuestionID) &&
                          q.IsActive.Equals("1")).ToList();

                if (_oldAnswers.Count > _updatedQuestion.QuizAnswers.Count && _updatedQuestion.QuizAnswers.Count != 0)
                {
                    for (int i = _updatedQuestion.QuizAnswers.Count + 1; i <= _oldAnswers.Count; i++)
                    {
                        Entities.QuizAnswer _answerToDelete = new Entities.QuizAnswer();

                        FarmworkersWebAPI.Entities.QuizAnswer original = _context.QuizAnswers.
                                                                         Where(q => q.QuizID.Equals(_updatedQuestion.QuizID) &&
                                                                               q.QuizVersion.Equals(_updatedQuestion.QuizVersion) &&
                                                                               q.QuestionID.Equals(_updatedQuestion.QuestionID) &&
                                                                               q.AnswerID.Equals(i)).FirstOrDefault();

                        _answerToDelete.QuizID       = _updatedQuestion.QuizID;
                        _answerToDelete.QuizVersion  = _updatedQuestion.QuizVersion;
                        _answerToDelete.QuestionID   = _updatedQuestion.QuestionID;
                        _answerToDelete.AnswerID     = i;
                        _answerToDelete.Answer       = original.Answer;
                        _answerToDelete.IsCorrect    = original.IsCorrect;
                        _answerToDelete.IsActive     = "0";
                        _answerToDelete.DateModified = original.DateModified;

                        _context.Entry(original).CurrentValues.SetValues(_answerToDelete);

                        _context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex).ToString());
            }

            return(_deletionResult);
        }
Пример #2
0
        public string EFdeleteQuizAnswer(FarmworkersWebAPI.Entities.QuizAnswer _deletedQuizAnswer)
        {
            _context.Configuration.ProxyCreationEnabled = false;

            try
            {
                _context.QuizAnswers.Attach(_deletedQuizAnswer);
                _context.QuizAnswers.Remove(_deletedQuizAnswer);
                _context.SaveChanges();

                return("Answer Deleted Successfully");
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex).ToString());
            }
        }
Пример #3
0
        public string EFinsertQuizAnswer(FarmworkersWebAPI.Entities.QuizAnswer _newQuizAnswer)
        {
            _context.Configuration.ProxyCreationEnabled = false;

            FarmworkersWebAPI.Entities.QuizAnswer _quizAnswerContentData = new FarmworkersWebAPI.Entities.QuizAnswer();

            try
            {
                _quizAnswerContentData = _context.QuizAnswers.Add(_newQuizAnswer);
                _context.SaveChanges();

                return("Answer Inserted Successfully");
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex).ToString());
            }
        }
Пример #4
0
        public string EFupdateQuizAnswer(FarmworkersWebAPI.Entities.QuizAnswer _updatedQuizAnswer)
        {
            if (_updatedQuizAnswer.AnswerID < 0)
            {
                return("Quiz Answer ID can not be negative");
            }

            if (_updatedQuizAnswer.AnswerID == 0)
            {
                return("Quiz Answer ID Not Specified");
            }

            _context.Configuration.ProxyCreationEnabled = false;

            try
            {
                FarmworkersWebAPI.Entities.QuizAnswer original = _context.QuizAnswers.
                                                                 Where(q => q.QuizID.Equals(_updatedQuizAnswer.QuizID) && q.QuizVersion.Equals(_updatedQuizAnswer.QuizVersion) && q.QuestionID.Equals(_updatedQuizAnswer.QuestionID) && q.AnswerID.Equals(_updatedQuizAnswer.AnswerID)).FirstOrDefault();

                if (original != null)
                {
                    _context.Entry(original).CurrentValues.SetValues(_updatedQuizAnswer);
                    _context.SaveChanges();


                    return("Answer Updated Successfully");
                }
                else      //If during the update process, there is a new answer that wasn't there before.
                {
                    string _insertAnswerResult = EFinsertQuizAnswer(_updatedQuizAnswer);

                    if (_insertAnswerResult != "Answer Inserted Successfully")
                    {
                        return(_insertAnswerResult);
                    }

                    return("Answer Updated Successfully");
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex).ToString());
            }
        }