Exemple #1
0
        public Question PostQuestionFromDraft(QuestionCreateFromDraftRequestDTO q, int accountId)
        {
            DraftQuestion question = _questionServices.GetDraftQuestion(q.QuestionDraftId);

            //Validations
            if (accountId != question.AccountId)
            {
                throw new InvalidAccountException("User cannot edit another user's question");
            }
            if (q.Text == null || q.Text.Length < _questionCharMin || q.Text.Length > _questionCharMax)
            {
                throw new InvalidQuestionLengthException("Question must be between " + _questionCharMin + " and " + _questionCharMax + " characters.");
            }

            //Create question after validations based on type
            //Then post question and return posted question
            Question questionToPost = question;

            switch (q.QuestionType)
            {
            case _schoolQuestion:
                //Validate Ids?
                questionToPost = new SchoolQuestion()
                {
                    AccountId         = accountId,
                    SchoolId          = q.SchoolId,
                    Text              = q.Text,
                    ExpNeededToAnswer = q.ExpNeededToAnswer
                };
                _questionServices.DeleteQuestion(q.QuestionDraftId);
                return(_questionServices.UpdateQuestion(questionToPost));

            case _departmentQuestion:
                //Validate Ids?
                questionToPost = new DepartmentQuestion()
                {
                    AccountId          = accountId,
                    SchoolDepartmentId = q.DepartmentId,
                    Text = q.Text,
                    ExpNeededToAnswer = q.ExpNeededToAnswer
                };
                // Delete question then return posted question
                _questionServices.DeleteQuestion(q.QuestionDraftId);
                return(_questionServices.PostQuestion(questionToPost));

            case _courseQuestion:
                questionToPost = new CourseQuestion()
                {
                    AccountId         = accountId,
                    CourseId          = q.CourseId,
                    Text              = q.Text,
                    ExpNeededToAnswer = q.ExpNeededToAnswer
                };
                _questionServices.DeleteQuestion(q.QuestionDraftId);
                return(_questionServices.PostQuestion(questionToPost));

            default:
                throw new ArgumentException("Invalid Question type");
            }
        }
Exemple #2
0
        //private string _schoolQuestionTypeName = typeof(SchoolQuestion).Name;
        //private string _departmentQuestionTypeName = typeof(DepartmentQuestion).Name;
        //private string _courseQuestionTypeName = typeof(CourseQuestion).Name;
        //private string _draftQuestionTypeName = typeof(CourseQuestion).Name;

        public Question PostQuestion(QuestionCreateRequestDTO q, int accountId)
        {
            //Validations
            if (q.Text == null || q.Text.Length < _questionCharMin || q.Text.Length > _questionCharMax)
            {
                throw new InvalidQuestionLengthException("Question must be between " + _questionCharMin + " and " + _questionCharMax + " characters.");
            }

            //Create question after validations based on type
            //Then post question and return posted question
            Question question;

            switch (q.QuestionType)
            {
            case _schoolQuestion:
                //Validate Ids?
                question = new SchoolQuestion()
                {
                    AccountId         = accountId,
                    SchoolId          = q.SchoolId,
                    Text              = q.Text,
                    ExpNeededToAnswer = q.ExpNeededToAnswer
                };
                return(_questionServices.PostQuestion(question));

            case _departmentQuestion:
                //Validate Ids?
                question = new DepartmentQuestion()
                {
                    AccountId          = accountId,
                    SchoolDepartmentId = q.DepartmentId,
                    Text = q.Text,
                    ExpNeededToAnswer = q.ExpNeededToAnswer
                };
                return(_questionServices.PostQuestion(question));

            case _courseQuestion:
                question = new CourseQuestion()
                {
                    AccountId         = accountId,
                    CourseId          = q.CourseId,
                    Text              = q.Text,
                    ExpNeededToAnswer = q.ExpNeededToAnswer
                };
                return(_questionServices.PostQuestion(question));

            case _draftQuestion:
                question = new DraftQuestion()
                {
                    AccountId         = accountId,
                    Text              = q.Text,
                    ExpNeededToAnswer = q.ExpNeededToAnswer
                };
                return(_questionServices.PostQuestion(question));

            default:
                throw new ArgumentException("Invalid Question type");
            }
        }
 public vCourseQuestion(CourseQuestion model)
 {
     this.ID = model.ID;
     this.Content = model.Content;
     this.RightAnswer = model.RightAnswer;
     this.Remark = model.Remark;
     this.Time = model.Time;
     this.CourseID = model.CourseID;
     this.Course = model.Course;
     this.Answers= model.Answers.Split('|').ToList();
 }
        public ActionResult AddCourseQuestion(CourseQuestion model)
        {
            var options = Request.Params.GetValues("option");
            string Answers = "";
            for (int i = 0; i < options.Count(); i++)
            {
                if (i == options.Count() - 1)
                {
                    Answers += options[i];
                }
                else
                {
                    Answers += options[i] + "|";
                }
            }

            model.Answers = Answers;
            model.Time = DateTime.Now;
            db.CourseQuestions.Add(model);
            db.SaveChanges();
            return Redirect("/Admin/CourseShow/" + model.CourseID);
        }
 public ActionResult CourseShow(int id)
 {
     CourseQuestion coursequestion = new CourseQuestion();
     List<CourseQuestion> coursequestions = db.CourseQuestions.Where(cq => cq.CourseID == id).ToList();
     List<vCourseQuestion> coursequestionlist = new List<vCourseQuestion>();
     foreach (var item in coursequestions)
     {
         coursequestionlist.Add(new vCourseQuestion(item));
     }
     ViewBag.CourseQuestions = coursequestionlist;
     Course course = new Course();
     course = db.Courses.Find(id);
     ViewBag.Course = course;
     return View();
 }
 public ActionResult CourseQuestionDelete(int id)
 {
     CourseQuestion coursequestion = new CourseQuestion();
     coursequestion = db.CourseQuestions.Find(id);
     db.CourseQuestions.Remove(coursequestion);
     db.SaveChanges();
     return Content("ok");
 }