コード例 #1
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())));
            }
        }
コード例 #2
0
ファイル: NewsController.cs プロジェクト: KKPBank/CSM
        public ActionResult InitEdit(int?newsId = null)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Edit News").Add("NewsId", newsId).ToInputLogString());

            NewsViewModel newsVM = null;

            if (TempData["NewsVM"] != null)
            {
                newsVM = (NewsViewModel)TempData["NewsVM"];
            }
            else
            {
                newsVM = new NewsViewModel {
                    NewsId = newsId
                };
            }

            _newsFacade   = new NewsFacade();
            _commonFacade = new CommonFacade();

            var statusList = _commonFacade.GetStatusSelectList();

            newsVM.StatusList = new SelectList((IEnumerable)statusList, "Key", "Value", string.Empty);

            if (TempData["NewsVM"] == null && newsVM.NewsId != null)
            {
                NewsEntity newsEntity = _newsFacade.GetNewsByID(newsVM.NewsId.Value);
                newsVM.Topic        = newsEntity.Topic;
                newsVM.AnnounceDate = newsEntity.AnnounceDateDisplay;
                newsVM.ExpiryDate   = newsEntity.ExpiryDateDisplay;
                newsVM.Content      = newsEntity.Content;
                newsVM.FullName     = newsEntity.CreateUser.FullName;
                newsVM.Status       = newsEntity.Status;

                // User
                newsVM.CreateUser  = newsEntity.CreateUser != null ? newsEntity.CreateUser.FullName : "";
                newsVM.CreatedDate = newsEntity.CreatedDate.FormatDateTime(Constants.DateTimeFormat.DefaultFullDateTime);
                newsVM.UpdateDate  = newsEntity.UpdateDate.FormatDateTime(Constants.DateTimeFormat.DefaultFullDateTime);
                newsVM.UpdateUser  = newsEntity.UpdateUser != null ? newsEntity.UpdateUser.FullName : "";

                var newsBranches = _newsFacade.GetNewsBranchList(newsVM.NewsId.Value);
                newsVM.NewsBranchList = newsBranches;
                newsVM.JsonBranch     = JsonConvert.SerializeObject(newsBranches);

                var newsAttachments = _newsFacade.GetNewsAttachmentList(newsVM.NewsId.Value);
                newsVM.AttachmentList = newsAttachments;
                newsVM.JsonAttach     = JsonConvert.SerializeObject(newsAttachments);
            }
            else if (TempData["NewsVM"] == null)
            {
                // Default UserLogin
                if (this.UserInfo != null)
                {
                    newsVM.FullName = this.UserInfo.FullName; // ผู้ประกาศ

                    var today = DateTime.Now;
                    newsVM.CreateUser  = this.UserInfo.FullName;
                    newsVM.CreatedDate = today.FormatDateTime(Constants.DateTimeFormat.DefaultFullDateTime);
                    newsVM.UpdateDate  = today.FormatDateTime(Constants.DateTimeFormat.DefaultFullDateTime);
                    newsVM.UpdateUser  = this.UserInfo.FullName;
                }

                newsVM.NewsBranchList = _newsFacade.GetNewsBranchList(newsVM.SelectedBranch)
                                        .Where(x => x.IsDelete == false).ToList();
            }
            else
            {
                newsVM.NewsBranchList = _newsFacade.GetNewsBranchList(newsVM.SelectedBranch)
                                        .Where(x => x.IsDelete == false).ToList();
            }

            return(View("~/Views/News/Edit.cshtml", newsVM));
        }