public ActionResult DeleteQuestion(DailyQuestionViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;
            if (viewModel.KeyID != null)
            {
                viewModel.QuestionID = viewModel.DecryptKeyValue();
            }

            var item = models.GetTable <PDQQuestion>().Where(q => q.QuestionID == viewModel.QuestionID && q.GroupID == 6).FirstOrDefault();

            if (item != null)
            {
                if (models.GetTable <PDQTask>().Any(t => t.QuestionID == item.QuestionID))
                {
                    viewModel.Status = (int)Naming.GeneralStatus.Failed;
                    return(CommitQuestionStatus(viewModel));
                }
                else
                {
                    models.ExecuteCommand("delete PDQQuestion where QuestionID={0}", item.QuestionID);
                    return(Json(new { result = true }));
                }
            }

            return(View("~/Views/Shared/JsAlert.cshtml", model: "問與答資料錯誤!!"));
        }
        public async Task <ActionResult> AnswerDailyQuestion(DailyQuestionViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;
            var profile = await HttpContext.GetUserAsync();

            var item = models.GetTable <PDQQuestion>().Where(q => q.QuestionID == viewModel.QuestionID).FirstOrDefault();

            if (item == null)
            {
                return(Json(new { result = false, message = "回答題目錯誤!!" }));
            }

            if (models.GetTable <PDQTask>().Any(t => t.UID == profile.UID &&
                                                t.TaskDate >= DateTime.Today && t.TaskDate < DateTime.Today.AddDays(1) &&
                                                t.PDQQuestion.GroupID == 6))
            {
                return(Json(new { result = false, message = "很抱歉,您今日已答過題嘍!!" }));
            }

            if (String.IsNullOrEmpty(viewModel.Question) || !item.Question.StartsWith(viewModel.Question))
            {
                return(View("~/Views/Html/Module/LearnerDailyQuestion.ascx", item));
            }

            var taskItem = new PDQTask
            {
                QuestionID   = item.QuestionID,
                SuggestionID = viewModel.SuggestionID,
                UID          = profile.UID,
                TaskDate     = DateTime.Now
            };

            models.GetTable <PDQTask>().InsertOnSubmit(taskItem);
            models.SubmitChanges();

            if (item.PDQSuggestion.Any(s => s.SuggestionID == viewModel.SuggestionID && s.RightAnswer == true))
            {
                if (item.PDQQuestionExtension != null)
                {
                    taskItem.PDQTaskBonus = new PDQTaskBonus {
                    };
                    models.SubmitChanges();

                    return(Json(new { result = true, message = item.PDQQuestionExtension.BonusPoint.ToString() }));
                }
            }

            return(Json(new { result = false }));
        }
        public ActionResult LoadDailyQuestion(DailyQuestionViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;
            if (viewModel.KeyID != null)
            {
                viewModel.QuestionID = viewModel.DecryptKeyValue();
            }
            var item = models.GetTable <PDQQuestion>().Where(q => q.QuestionID == viewModel.QuestionID && q.GroupID == 6).FirstOrDefault();

            if (item != null)
            {
                return(View("~/Views/Activity/Module/DailyQuestionDataItem.ascx", item));
            }

            return(View("~/Views/Shared/JsAlert.cshtml", model: "問與答資料錯誤!!"));
        }
        public ActionResult CommitQuestionStatus(DailyQuestionViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;
            if (viewModel.KeyID != null)
            {
                viewModel.QuestionID = viewModel.DecryptKeyValue();
            }

            //models.ExecuteCommand("update PDQQuestionExtension set Status={0} where QuestionID={1}", status, questionID);
            var item = models.GetTable <PDQQuestionExtension>().Where(t => t.QuestionID == viewModel.QuestionID).FirstOrDefault();

            if (item != null)
            {
                item.Status = viewModel.Status;
                models.SubmitChanges();
                return(Content(new { result = true, item.QuestionID }.JsonStringify(), "application/json"));
            }

            return(View("~/Views/Shared/JsAlert.cshtml", model: "問與答資料錯誤!!"));
        }