Example #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())));
            }
        }
Example #2
0
        public ActionResult NewsReadList(NewsSearchFilter searchFilter)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Get NewsReadList").Add("UserId", this.UserInfo.UserId)
                        .ToInputLogString());

            try
            {
                _newsFacade   = new NewsFacade();
                _commonFacade = new CommonFacade();
                HomeViewModel homeVM = new HomeViewModel();
                homeVM.NewsReadSearchFilter        = searchFilter;
                homeVM.NewsReadSearchFilter.UserId = this.UserInfo.UserId;

                homeVM.NewsReadList          = _newsFacade.GetNewsReadList(homeVM.NewsReadSearchFilter);
                ViewBag.NewsReadPageSize     = homeVM.NewsReadSearchFilter.PageSize;
                ViewBag.NewsReadPageSizeList = _commonFacade.GetPageSizeList();

                Logger.Info(_logMsg.Clear().SetPrefixMsg("Get NewsReadList").ToSuccessLogString());
                return(PartialView("~/Views/Home/_NewsReadList.cshtml", homeVM));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Get NewsReadList").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Example #3
0
        public ActionResult NewsList(NewsSearchFilter searchFilter)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Search News").Add("Topic", searchFilter.Topic).ToInputLogString());

            try
            {
                #region "Validation"

                bool isValid = TryUpdateModel(searchFilter);
                if (!string.IsNullOrEmpty(searchFilter.DateFrom) && !searchFilter.AnnounceDate.HasValue)
                {
                    isValid = false;
                    ModelState.AddModelError("txtFromDate", Resource.ValErr_InvalidDate);
                }
                if (!string.IsNullOrEmpty(searchFilter.DateTo) && !searchFilter.ExpiryDate.HasValue)
                {
                    isValid = false;
                    ModelState.AddModelError("txtToDate", Resource.ValErr_InvalidDate);
                }
                if (searchFilter.AnnounceDate.HasValue && searchFilter.ExpiryDate.HasValue &&
                    searchFilter.AnnounceDate.Value > searchFilter.ExpiryDate.Value)
                {
                    isValid = false;
                    ModelState.AddModelError("dvDateRange", Resource.ValErr_InvalidDateRange);
                }

                #endregion

                if (isValid)
                {
                    _newsFacade   = new NewsFacade();
                    _commonFacade = new CommonFacade();
                    NewsViewModel newsVM = new NewsViewModel();
                    newsVM.SearchFilter = searchFilter;

                    newsVM.NewsList      = _newsFacade.GetNewsList(newsVM.SearchFilter);
                    ViewBag.PageSize     = newsVM.SearchFilter.PageSize;
                    ViewBag.PageSizeList = _commonFacade.GetPageSizeList();

                    Logger.Info(_logMsg.Clear().SetPrefixMsg("Search News").ToSuccessLogString());
                    return(PartialView("~/Views/News/_NewsList.cshtml", newsVM));
                }

                return(Json(new
                {
                    Valid = false,
                    Error = string.Empty,
                    Errors = GetModelValidationErrors()
                }));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Search News").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Example #4
0
        public GeneralController(IAboutFacade aboutFacade, INewsFacade newsFacade, IHotelFacade hotelFacade,
                                 IContactFacade contactFacade, IOwnerFacade ownerFacade, ICountryFacade countryFacade, IBackageFacade backageFacade)

        {
            _aboutFacade   = aboutFacade;
            _newsFacade    = newsFacade;
            _hotelFacade   = hotelFacade;
            _contactFacade = contactFacade;
            _ownerFacade   = ownerFacade;
            _countryFacade = countryFacade;
            _backageFacade = backageFacade;
        }
Example #5
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
                }));
            }
        }
Example #6
0
        public ActionResult NewsBranchList(NewsViewModel newsVM)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Get NewsBranch List").Add("JsonBranch", newsVM.JsonBranch).ToInputLogString());

            try
            {
                _newsFacade           = new NewsFacade();
                newsVM.NewsBranchList = _newsFacade.GetNewsBranchList(newsVM.SelectedBranch)
                                        .Where(x => x.IsDelete == false).ToList();

                Logger.Info(_logMsg.Clear().SetPrefixMsg("Get NewsBranch List").ToSuccessLogString());
                return(PartialView("~/Views/News/_NewsBranchList.cshtml", newsVM));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Get NewsBranch List").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Example #7
0
 public NewsController(INewsFacade NewsFacade)
 {
     _newsFacade = NewsFacade;
 }
Example #8
0
        public ActionResult Edit(NewsViewModel newsVM)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Save News").Add("NewsId", newsVM.NewsId)
                        .Add("Topic", newsVM.Topic).ToInputLogString());

            try
            {
                #region "Validation"

                bool   isValid = TryUpdateModel(newsVM);
                string content = ApplicationHelpers.StripHtmlTags(newsVM.Content);

                if (string.IsNullOrWhiteSpace(content))
                {
                    isValid = false;
                    ModelState.AddModelError("Content", string.Format(CultureInfo.InvariantCulture, Resource.ValErr_RequiredField, Resource.Lbl_Content));
                }
                if (!string.IsNullOrEmpty(newsVM.AnnounceDate) && !newsVM.AnnounceDateValue.HasValue)
                {
                    isValid = false;
                    ModelState.AddModelError("AnnounceDate", Resource.ValErr_InvalidDate);
                }
                else if (newsVM.AnnounceDateValue.HasValue)
                {
                    // เช็คห้ามเลือกวันที่ย้อนหลังเฉพาะกรณี เพิ่มข้อมูลใหม่
                    if ((newsVM.NewsId.HasValue == false || newsVM.NewsId == 0) && newsVM.AnnounceDateValue.Value < DateTime.Now.Date)
                    {
                        isValid = false;
                        ModelState.AddModelError("AnnounceDate", Resource.ValErr_InvalidDate_MustMoreThanToday);
                    }
                }

                if (!string.IsNullOrEmpty(newsVM.ExpiryDate) && !newsVM.ExpiryDateValue.HasValue)
                {
                    isValid = false;
                    ModelState.AddModelError("ExpiryDate", Resource.ValErr_InvalidDate);
                }
                else if (newsVM.ExpiryDateValue.HasValue)
                {
                    // เช็คห้ามเลือกวันที่ย้อนหลังเฉพาะกรณี เพิ่มข้อมูลใหม่
                    if ((newsVM.NewsId.HasValue == false || newsVM.NewsId == 0) && newsVM.ExpiryDateValue.Value < DateTime.Now.Date)
                    {
                        isValid = false;
                        ModelState.AddModelError("ExpiryDate", Resource.ValErr_InvalidDate_MustMoreThanToday);
                    }
                }

                if (newsVM.AnnounceDateValue.HasValue && newsVM.ExpiryDateValue.HasValue &&
                    newsVM.AnnounceDateValue.Value > newsVM.ExpiryDateValue.Value)
                {
                    isValid = false;
                    ModelState.AddModelError("AnnounceDate", Resource.ValErr_InvalidDateRange);
                    ModelState.AddModelError("ExpiryDate", "");
                }

                #endregion

                if (isValid)
                {
                    List <NewsBranchEntity> selectedBranch = newsVM.SelectedBranch;

                    // Validate select at least one branch
                    if (!newsVM.SelectedBranch.Any(x => x.IsDelete == false))
                    {
                        ViewBag.ErrorMessage = Resource.ValErr_AtLeastOneItem;
                        goto Outer;
                    }

                    // Validate MaxLength
                    if (newsVM.Content.Count() > Constants.MaxLength.NewsContent)
                    {
                        ModelState.AddModelError("Content", string.Format(CultureInfo.InvariantCulture, Resource.ValErr_StringLength, Resource.Lbl_Content, Constants.MaxLength.NewsContent));
                        goto Outer;
                    }

                    // Save News
                    NewsEntity newsEntity = new NewsEntity
                    {
                        NewsId       = newsVM.NewsId,
                        Topic        = newsVM.Topic,
                        AnnounceDate = newsVM.AnnounceDate.ParseDateTime(Constants.DateTimeFormat.DefaultShortDate),
                        ExpiryDate   = newsVM.ExpiryDate.ParseDateTime(Constants.DateTimeFormat.DefaultShortDate),
                        Content      = newsVM.Content,
                        Status       = newsVM.Status,
                        CreateUserId = this.UserInfo.UserId,
                        UpdateUserId = this.UserInfo.UserId
                    };

                    _commonFacade             = new CommonFacade();
                    newsEntity.DocumentFolder = _commonFacade.GetNewsDocumentFolder();

                    _newsFacade = new NewsFacade();
                    bool success = _newsFacade.SaveNews(newsEntity, selectedBranch, newsVM.AttachmentList);

                    if (success)
                    {
                        return(RedirectToAction("Search", "News"));
                    }

                    ViewBag.ErrorMessage = Resource.Error_SaveFailed;
                }

Outer:
                TempData["NewsVM"] = newsVM;
                return(InitEdit());
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Save News").Add("Exception occur:\n", ex).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Example #9
0
        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));
        }
Example #10
0
        public ActionResult Index()
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Index").Add("CallId", this.CallId)
                        .Add("UserId", this.UserInfo.UserId).ToInputLogString());

            try
            {
                _newsFacade     = new NewsFacade();
                _userFacade     = new UserFacade();
                _commonFacade   = new CommonFacade();
                _customerFacade = new CustomerFacade();

                HomeViewModel homeVM = new HomeViewModel();
                homeVM.NewsUnreadSearchFilter = new NewsSearchFilter
                {
                    Topic     = string.Empty,
                    Status    = Constants.ApplicationStatus.Active.ToString(CultureInfo.InvariantCulture),
                    PageNo    = 1,
                    PageSize  = _commonFacade.GetPageSizeStart(),
                    SortField = "NewsId",
                    SortOrder = "DESC"
                };

                homeVM.NewsReadSearchFilter = new NewsSearchFilter
                {
                    Topic     = string.Empty,
                    Status    = Constants.ApplicationStatus.Active.ToString(CultureInfo.InvariantCulture),
                    PageNo    = 1,
                    PageSize  = _commonFacade.GetPageSizeStart(),
                    SortField = "NewsId",
                    SortOrder = "DESC"
                };

                homeVM.GroupSrSearchFilter = new SrSearchFilter
                {
                    PageNo    = 1,
                    PageSize  = _commonFacade.GetPageSizeStart(),
                    SortField = "CreateDate",
                    SortOrder = "ASC"
                };

                homeVM.IndividualSrSearchFilter = new SrSearchFilter
                {
                    FilterType = null,
                    PageNo     = 1,
                    PageSize   = _commonFacade.GetPageSizeStart(),
                    SortField  = "CreateDate",
                    SortOrder  = "ASC"
                };

                #region "News Unread"

                //homeVM.NewsUnreadSearchFilter.UserId = this.UserInfo.UserId;
                //homeVM.NewsUnreadList = _newsFacade.GetNewsUnreadList(homeVM.NewsUnreadSearchFilter);

                #endregion

                #region "News Read"

                //homeVM.NewsReadSearchFilter.UserId = this.UserInfo.UserId;
                //homeVM.NewsReadList = _newsFacade.GetNewsReadList(homeVM.NewsReadSearchFilter);

                #endregion

                #region "Group ServiceRequest"

                //var lstDummyUser = _userFacade.GetDummyUsers(this.UserInfo);
                //homeVM.GroupSrSearchFilter.OwnerList = lstDummyUser;
                //homeVM.GroupServiceRequestList = _customerFacade.GetSrList(homeVM.GroupSrSearchFilter);

                #endregion

                #region "Individual ServiceRequest"

                //var lstEmployeeUser = new List<UserEntity>();
                //lstEmployeeUser = _userFacade.GetEmployees(this.UserInfo);
                //lstEmployeeUser.Add(this.UserInfo); // Add current user
                //homeVM.IndividualSrSearchFilter.OwnerList = lstEmployeeUser;
                //homeVM.IndividualServiceRequestList = _customerFacade.GetSrList(homeVM.IndividualSrSearchFilter);

                #endregion

                ViewBag.NewsUnreadPageSize = homeVM.NewsUnreadSearchFilter.PageSize;
                ViewBag.NewsReadPageSize   = homeVM.NewsReadSearchFilter.PageSize;
                ViewBag.GroupPageSize      = homeVM.GroupSrSearchFilter.PageSize;
                ViewBag.IndyPageSize       = homeVM.IndividualSrSearchFilter.PageSize;

                var pageSizeList = _commonFacade.GetPageSizeList();
                ViewBag.NewsUnreadPageSizeList = pageSizeList;
                ViewBag.NewsReadPageSizeList   = pageSizeList;
                ViewBag.GroupPageSizeList      = pageSizeList;
                ViewBag.IndyPageSizeList       = pageSizeList;

                ViewBag.Message = string.Empty;

                return(View(homeVM));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Index").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }