예제 #1
0
        public ActionResult InitNewsPreview(NewsViewModel newsVM)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("InitNewsPreview").ToInputLogString());

            try
            {
                AcceptNewsViewModel acceptNewsVM = new AcceptNewsViewModel();
                acceptNewsVM.Topic        = newsVM.Topic;
                acceptNewsVM.AnnounceDate = newsVM.AnnounceDate;
                acceptNewsVM.ExpiryDate   = newsVM.ExpiryDate;
                acceptNewsVM.Content      = newsVM.Content;
                acceptNewsVM.FullName     = newsVM.FullName;

                acceptNewsVM.AttachmentList = newsVM.AttachmentList.Where(x => x.IsDelete == false).ToList();

                return(PartialView("~/Views/News/_NewsPreview.cshtml", acceptNewsVM));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("InitNewsPreview").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
예제 #2
0
        public ActionResult InitAcceptNews(int?newsId, string isShowAcceptNews)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Init AcceptNews").ToInputLogString());

            try
            {
                _newsFacade = new NewsFacade();
                AcceptNewsViewModel acceptNewsVM = new AcceptNewsViewModel();

                if (newsId.HasValue)
                {
                    NewsEntity newsEntity = _newsFacade.GetNewsByID(newsId.Value);
                    acceptNewsVM.Topic        = newsEntity.Topic;
                    acceptNewsVM.AnnounceDate = newsEntity.AnnounceDateDisplay;
                    acceptNewsVM.ExpiryDate   = newsEntity.ExpiryDateDisplay;
                    acceptNewsVM.Content      = newsEntity.Content;
                    acceptNewsVM.FullName     = newsEntity.CreateUser.FullName;

                    acceptNewsVM.AttachmentList    = _newsFacade.GetNewsAttachmentList(newsId.Value);
                    TempData["NewsAttachmentList"] = acceptNewsVM.AttachmentList; // keep for download

                    // สำหรับ show/hide CheckBox
                    acceptNewsVM.IsShowAcceptNews = (isShowAcceptNews == "1") ? true : false;
                }

                return(PartialView("~/Views/Home/_AcceptNews.cshtml", acceptNewsVM));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Init AcceptNews").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
예제 #3
0
        public JsonResult SaveAcceptNews(AcceptNewsViewModel acceptNewsVM)
        {
            try
            {
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Save AcceptNews").ToInputLogString());

                if (ModelState.IsValid)
                {
                    // Save
                    ReadNewsEntity readNewsEntity = new ReadNewsEntity
                    {
                        NewsId       = acceptNewsVM.NewsId,
                        CreateUserId = this.UserInfo.UserId,
                    };

                    _newsFacade = new NewsFacade();
                    _newsFacade.SaveReadNews(readNewsEntity);

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

                return(Json(new
                {
                    Valid = false,
                    Error = string.Empty,
                    Errors = GetModelValidationErrors()
                }));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Save AcceptNews").Add("Error Message", ex.Message).ToFailLogString());
                return(Json(new
                {
                    Valid = false,
                    Error = Resource.Error_System,
                    Errors = string.Empty
                }));
            }
        }