public async Task <ActionResult> CommitDailyQuestion(PDQQuestionViewModel viewModel)
        {
            UserProfile profile = await HttpContext.GetUserAsync();

            ViewBag.ViewModel = viewModel;
            //if (!viewModel.AskerID.HasValue)
            //{
            //    ModelState.AddModelError("AskerID", "請選擇提問者!!");
            //    ViewBag.ModelState = ModelState;
            //    return View("EditDailyQuestion", profile);
            //}
            //if (!viewModel.BonusPoint.HasValue)
            //{
            //    ModelState.AddModelError("BonusPoint", "請輸入回饋點數!!");
            //    ViewBag.ModelState = ModelState;
            //    return View("EditDailyQuestion", profile);
            //}
            viewModel.BonusPoint = 1;

            if (viewModel.Suggestion == null || viewModel.Suggestion.Length < 1)
            {
                ModelState.AddModelError("Suggestion", "請輸入選項!!");
            }
            else
            {
                viewModel.Suggestion = viewModel.Suggestion
                                       .Select(s => s.GetEfficientString())
                                       .Where(s => s != null).ToArray();

                if (viewModel.Suggestion.Length < 4)
                {
                    ModelState.AddModelError("Suggestion", "請輸入選項!!");
                }
            }

            if (!viewModel.RightAnswerIndex.HasValue)
            {
                ModelState.AddModelError("RightAnswerIndex", "請正確設定答案!!");
            }

            if (!ModelState.IsValid)
            {
                ViewBag.ModelState = this.ModelState;
                return(View("~/Views/Shared/ReportInputError.ascx"));
            }

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

            if (item == null)
            {
                item = new PDQQuestion
                {
                    PDQQuestionExtension = new PDQQuestionExtension
                    {
                        BonusPoint   = 1,
                        CreationTime = DateTime.Now
                    },
                    GroupID      = 6,
                    QuestionType = (int)Naming.QuestionType.單選題,
                };

                models.GetTable <PDQQuestion>().InsertOnSubmit(item);

                for (int i = 0; i < viewModel.Suggestion.Length; i++)
                {
                    item.PDQSuggestion.Add(new PDQSuggestion {
                    });
                }
            }

            item.AskerID  = viewModel.AskerID ?? profile.UID;
            item.Question = viewModel.Question;
            item.PDQQuestionExtension.CreationTime = DateTime.Now;
            //item.QuestionType = viewModel.QuestionType;
            //item.GroupID = viewModel.GroupID;
            //item.AskerID = viewModel.AskerID;

            for (int i = 0; i < viewModel.Suggestion.Length; i++)
            {
                item.PDQSuggestion[i].Suggestion  = viewModel.Suggestion[i];
                item.PDQSuggestion[i].RightAnswer = i == viewModel.RightAnswerIndex;
            }

            //item.PDQQuestionExtension.BonusPoint = viewModel.BonusPoint;

            models.SubmitChanges();
            return(Content(new { result = true, item.QuestionID }.JsonStringify(), "application/json"));
        }
        public ActionResult CommitBonusPromotion(PromotionViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;

            if (!viewModel.BonusPoint.HasValue || viewModel.BonusPoint < 1)
            {
                ModelState.AddModelError("BonusPoint", "請輸入贈送點數!!");
            }

            if (!viewModel.StartDate.HasValue)
            {
                ModelState.AddModelError("StartDate", "請選擇活動起日!!");
            }

            viewModel.GroupName = viewModel.GroupName.GetEfficientString();
            if (viewModel.GroupName == null)
            {
                ModelState.AddModelError("GroupName", "請輸入活動名稱!!");
            }

            viewModel.Question = viewModel.Question.GetEfficientString();
            if (viewModel.Question == null)
            {
                ModelState.AddModelError("Question", "請輸入活動說明!!");
            }

            if (!ModelState.IsValid)
            {
                ViewBag.ModelState = this.ModelState;
                return(View("~/Views/Shared/ReportInputError.ascx"));
            }

            var                  item = loadPromotionItem(viewModel);
            PDQQuestion          pdq;
            PDQQuestionExtension pdqExt;

            if (item == null)
            {
                var table = models.GetTable <PDQGroup>();
                item = new PDQGroup
                {
                };
                item.GroupID = (table.OrderByDescending(p => p.GroupID).FirstOrDefault()?.GroupID + 1) ?? 1;

                table.InsertOnSubmit(item);

                pdq = new PDQQuestion
                {
                    PDQGroup = item
                };
                pdqExt = new PDQQuestionExtension
                {
                    PDQQuestion    = pdq,
                    CreationTime   = DateTime.Now,
                    AwardingAction = (int)Naming.BonusAwardingAction.手動,
                };
            }
            else
            {
                pdq    = item.PDQQuestion.First();
                pdqExt = pdq.PDQQuestionExtension;
            }

            item.GroupName    = viewModel.GroupName;
            item.StartDate    = viewModel.StartDate;
            item.EndDate      = viewModel.EndDate;
            pdq.Question      = viewModel.Question;
            pdqExt.BonusPoint = viewModel.BonusPoint;

            models.SubmitChanges();

            return(Json(new { result = true }));
        }