public ActionResult CommitMotivationalWords(MotivationalWordsViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;

            var profile = HttpContext.GetUser();

            if (String.IsNullOrEmpty(viewModel.Title))
            {
                ModelState.AddModelError("Title", "請輸入激勵小語!!");
            }

            if (!viewModel.StartDate.HasValue)
            {
                ModelState.AddModelError("StartDate", "請選擇開始時間!!");
            }

            if (!ModelState.IsValid)
            {
                ViewBag.ModelState = this.ModelState;
                return(View("EditMotivationalWords", viewModel));
            }

            var item = models.GetTable <Article>().Where(a => a.DocID == viewModel.DocID && a.Document.DocType == (int)Naming.DocumentTypeDefinition.Inspirational).FirstOrDefault();

            if (item == null)
            {
                item = new Article
                {
                    Document = new Document
                    {
                        DocDate = DateTime.Now,
                        DocType = (int)Naming.DocumentTypeDefinition.Inspirational
                    },
                    Publication = new Publication {
                    }
                };
                models.GetTable <Article>().InsertOnSubmit(item);
            }

            item.AuthorID = profile.UID;
            item.Title    = viewModel.Title;
            item.Publication.StartDate = viewModel.StartDate;
            item.Publication.EndDate   = viewModel.EndDate;

            models.SubmitChanges();

            ViewBag.Message = "資料已儲存!!";
            ViewResult result = (ViewResult)MotivationalWords();

            result.ViewName = "MotivationalWords";
            return(result);
        }
        public ActionResult EditMotivationalWords(int?id)
        {
            var item = models.GetTable <Article>().Where(a => a.DocID == id && a.Document.DocType == (int)Naming.DocumentTypeDefinition.Inspirational).FirstOrDefault();

            MotivationalWordsViewModel viewModel = new MotivationalWordsViewModel
            {
                StartDate = DateTime.Today
            };

            ViewBag.ViewModel = viewModel;

            if (item != null)
            {
                viewModel.DocID     = item.DocID;
                viewModel.Title     = item.Title;
                viewModel.StartDate = item.Publication.StartDate;
                viewModel.EndDate   = item.Publication.EndDate;
            }

            return(View(item));
        }