Example #1
0
        public ActionResult AddNews(NewsModel model)
        {
            if (AdminNews.AdminGetNewsIdByTitle(model.Title) > 0)
                ModelState.AddModelError("Title", "标题已经存在");

            if (ModelState.IsValid)
            {
                NewsInfo newsInfo = new NewsInfo()
                {
                    NewsTypeId = model.NewsTypeId,
                    IsShow = model.IsShow,
                    IsTop = model.IsTop,
                    IsHome = model.IsHome,
                    DisplayOrder = model.DisplayOrder,
                    AddTime = DateTime.Now,
                    Title = model.Title,
                    Url = model.Url == null ? "" : model.Url,
                    Body = model.Body ?? ""
                };

                AdminNews.CreateNews(newsInfo);
                AddAdminOperateLog("添加新闻", "添加新闻,新闻为:" + model.Title);
                return PromptView("新闻添加成功");
            }

            Load();
            return View(model);
        }
Example #2
0
        public ActionResult EditNews(NewsModel model, int newsId = -1)
        {
            NewsInfo newsInfo = AdminNews.AdminGetNewsById(newsId);
            if (newsInfo == null)
                return PromptView("新闻不存在");

            int newsId2 = AdminNews.AdminGetNewsIdByTitle(model.Title);
            if (newsId2 > 0 && newsId2 != newsId)
                ModelState.AddModelError("Title", "名称已经存在");

            if (ModelState.IsValid)
            {
                newsInfo.NewsTypeId = model.NewsTypeId;
                newsInfo.IsShow = model.IsShow;
                newsInfo.IsTop = model.IsTop;
                newsInfo.IsHome = model.IsHome;
                newsInfo.DisplayOrder = model.DisplayOrder;
                newsInfo.Title = model.Title;
                newsInfo.Url = model.Url == null ? "" : model.Url;
                newsInfo.Body = model.Body ?? "";

                AdminNews.UpdateNews(newsInfo);
                AddAdminOperateLog("修改新闻", "修改新闻,新闻ID为:" + newsId);
                return PromptView("新闻修改成功");
            }

            Load();
            return View(model);
        }
Example #3
0
 public ActionResult AddNews()
 {
     NewsModel model = new NewsModel();
     Load();
     return View(model);
 }
Example #4
0
        public ActionResult EditNews(int newsId = -1)
        {
            NewsInfo newsInfo = AdminNews.AdminGetNewsById(newsId);
            if (newsInfo == null)
                return PromptView("新闻不存在");

            NewsModel model = new NewsModel();
            model.NewsTypeId = newsInfo.NewsTypeId;
            model.IsShow = newsInfo.IsShow;
            model.IsTop = newsInfo.IsTop;
            model.IsHome = newsInfo.IsHome;
            model.DisplayOrder = newsInfo.DisplayOrder;
            model.Title = newsInfo.Title;
            model.Url = newsInfo.Url;
            model.Body = newsInfo.Body;

            Load();
            return View(model);
        }