Пример #1
0
        public ActionResult addPageQuestion(string callback, int pageID, int faqID, string question, string answer)
        {
            ajaxReturnData data = new ajaxReturnData();

            try
            {
                using (ApplicationDbContext DB = new ApplicationDbContext())
                {
                    Page page = DB.Pages.Include("faqs.questions").Where(p => p.pageID == pageID).FirstOrDefault();
                    Faq faq = page.faqs.Where(f => f.id == faqID).FirstOrDefault();
                    FaqQuestion fq = new FaqQuestion();
                    fq.udate(DB, question, answer);
                    faq.questions.Add(fq);
                    DB.SaveChanges();

                }


                if (string.IsNullOrEmpty(callback))
                {
                    data.statusCode = (int)statusCodes.success;
                }
                else
                {
                    data.statusCode = (int)statusCodes.successRun;
                    data.callback = callback;
                }

                //data.message = "question added";
                return Json(data);
            }
            catch (Exception ex)
            {
                data.statusCode = (int)statusCodes.fail;
                data.message = "Failed to add question; " + ex.Message;
                return Json(data);
            }
        }
        public ActionResult addShortCourseQuestion(string callback, int courseID, string question, string answer)
        {
            ajaxReturnData data = new ajaxReturnData();

            try
            {
                using (ApplicationDbContext DB = new ApplicationDbContext())
                {
                    ShortCourse sc = DB.shortCourses.Include("faq.questions").Where(s => s.id == courseID).FirstOrDefault();
                    FaqQuestion fq = new FaqQuestion();
                    fq.udate(DB, question, answer);
                    sc.faq.questions.Add(fq);
                    DB.SaveChanges();

                }


                if (string.IsNullOrEmpty(callback))
                {
                    data.statusCode = (int)statusCodes.success;
                }
                else
                {
                    data.statusCode = (int)statusCodes.successRun;
                    data.callback = callback;
                }

                data.message = "question added";
                return Json(data);
            }
            catch (Exception ex)
            {
                data.statusCode = (int)statusCodes.fail;
                data.message = "Failed to add question; " + ex.Message;
                return Json(data);
            }
        }