public ActionResult Add(News news) { string result = "发布失败"; if (Session["UserId"] == null) { return Content("长时间未操作,请重新登录。"); } if (news == null) { result = "参数为空"; } else { if (!string.IsNullOrEmpty(news.Title) && !string.IsNullOrEmpty(news.CategoryId) && !string.IsNullOrEmpty(news.ContentStyle)) { news.ContentText = news.ContentStyle; news.InsertTime = DateTime.Now; news.UpdateTime = news.InsertTime; news.ViewCount = 0; news.IsActive = true; NewsService newsService = new NewsService(); result = newsService.AddNews(news); } else { result = "必填项 [标题、分类、内容] 不能为空"; } } return Content(result); }
/// <summary> /// 新闻首页 /// </summary> public ActionResult Index(string category, string page) { this.Internationalization(); NewsModel model = new NewsModel(); if (string.IsNullOrEmpty(page)) { page = "1"; } NewsService newsService = new NewsService(); model.Page = Int32.Parse(page); model.PageSize = 10;//每页显示10张 model.PageIndex = Int32.Parse(page); int count = 0; //新闻列表 if (string.Equals(category, "news", StringComparison.CurrentCultureIgnoreCase)) { category = null; } model.NewsList = newsService.GetNewsList(category, null, model.PageSize, model.PageIndex, out count); //分页 if (model.NewsList != null && model.NewsList.Count > 0) { model.PageStep = 10; //页码10个 model.AllCount = count; if (model.AllCount % model.PageSize == 0) { model.PageCount = model.AllCount / model.PageSize; } else { model.PageCount = model.AllCount / model.PageSize + 1; } } if (category == null || string.Equals(category, "news", StringComparison.CurrentCultureIgnoreCase)) { CategoryService categoryService = new CategoryService(); model.Category = categoryService.GetCategoryById(category ?? "news"); } else { WitBird.Sex.Model.NewsCategory newsCategory = newsService.GetNewsCategoryById(category); model.Category = new Model.Category(); model.Category.Id = newsCategory.Id; model.Category.Name = newsCategory.Name; model.Category.Description = newsCategory.Description; model.Category.Keywords = newsCategory.Keywords; } //VideoService videoService = new VideoService(); //猜你喜欢 //model.Like = videoService.GetLike(16); return View(model); }
public PartialViewResult NewsRight() { NewsRightModel model = new NewsRightModel(); NewsService newsService = new NewsService(); model.RecommendNews = newsService.GetRecommendNews(); model.TopNews = newsService.GetHotNews(); return PartialView(model); }
public ActionResult Add() { if (Session["UserId"] == null) { return Redirect("/admin/login"); } NewsModel model = new NewsModel(); NewsService newsService = new NewsService(); model.NewsCategories = newsService.GetNewsCategories(); return View(model); }
/// <summary> /// 新闻首页 /// </summary> public ActionResult Index(string page) { this.Internationalization(); NewsModel model = new NewsModel(); if (string.IsNullOrEmpty(page)) { page = "1"; } NewsService newsService = new NewsService(); model.Page = Int32.Parse(page); model.PageSize = 10;//每页显示10张 model.PageIndex = Int32.Parse(page); int count = 0; //视频列表 model.NewsList = newsService.GetNewsList(null, null, model.PageSize, model.PageIndex, out count); //分页 if (model.NewsList != null && model.NewsList.Count > 0) { model.PageStep = 10; //页码10个 model.AllCount = count; if (model.AllCount % model.PageSize == 0) { model.PageCount = model.AllCount / model.PageSize; } else { model.PageCount = model.AllCount / model.PageSize + 1; } } CategoryService categoryService = new CategoryService(); model.Category = categoryService.GetCategoryById("news"); VideoService videoService = new VideoService(); //猜你喜欢 //model.Like = videoService.GetLike(16); return View(model); }
public ActionResult Show(string id) { this.Internationalization(); NewsModel model = new NewsModel(); if (string.IsNullOrEmpty(id)) { id = "1"; } NewsService newsService = new NewsService(); model.News = newsService.GetNewsById(Int32.Parse(id)); //随机推荐 //model.RecommendRandoms = newsService.GetRecommendRandom(6); //猜你喜欢 //VideoService videoService = new VideoService(); //model.Like = videoService.GetLike(16); //推荐新闻 //model.RecommendNews = NewsService.GetRecommendRandom(10); //推荐小说 //model.RecommendNovels = NovelService.GetRecommendRandom(10); if (model.News == null) { model.News = new Model.News(); model.News.Title = "该新闻不存在或已被删除"; } else { AlbumService albumService = new AlbumService(); int outCount = 0; model.RelatedAlbum = albumService.GetAlbumList(string.Empty, model.News.Keywords, 8, 1, out outCount); model.RelatedNews = newsService.GetRelatedNews(model.News.Id); } return View(model); }
public ActionResult AddCategory(NewsCategory category) { if (Session["UserId"] == null) { return Redirect("/admin/login"); } if (category != null) { if (!string.IsNullOrEmpty(category.Id) && !string.IsNullOrEmpty(category.Name) && category.Sort > 0) { category.IsActive = true; NewsService newsService = new NewsService(); newsService.AddNewsCategory(category); Cache.UpdateNewsCategories();//更新缓存 } } return Redirect(Request.UrlReferrer.AbsoluteUri); }
public ActionResult Show(string id) { this.Internationalization(); NewsModel model = new NewsModel(); if (string.IsNullOrEmpty(id)) { id = "1"; } NewsService newsService = new NewsService(); model.News = newsService.GetNewsById(Int32.Parse(id)); if (model.News == null) { model.News = new Model.News(); model.News.Title = "该新闻不存在或已被删除"; } else { AlbumService albumService = new AlbumService(); int outCount = 0; model.RelatedAlbum = albumService.GetAlbumList(string.Empty, model.News.Keywords, 5, 1, out outCount); model.RelatedNews = newsService.GetRelatedNews(model.News.Id); model.LastNews = newsService.GetPrvNewsById(model.News.Id); model.NextNews = newsService.GetNextNewsById(model.News.Id); } return View(model); }
public static void UpdateNewsCategories() { NewsService newsService = new NewsService(); newsCategories = newsService.GetNewsCategories(); }
// // GET: /Search/ public ActionResult Index(string keywords, string page) { this.Internationalization(); SearchModel model = new SearchModel(); AlbumService albumService = new AlbumService(); NewsService newsService = new NewsService(); int tempPage = 1; if (!string.IsNullOrEmpty(page)) { Int32.TryParse(page, out tempPage); } //专辑列表 int tempCount = 0; int tempCount1 = 0; int pageSize = 20; model.NewsResult = newsService.GetNewsList(string.Empty, keywords, 6, tempPage, out tempCount); if (tempCount > 0 && model.NewsResult != null && model.NewsResult.Count > 6) { pageSize = 8; } model.AlbumResult = albumService.GetAlbumList(null, keywords, pageSize, tempPage, out tempCount1); model.TotalResultsCount = tempCount + tempCount1; model.TotalNewsCount = tempCount; model.TotalAlbumCount = tempCount1; if (tempCount1 == 0 && tempCount < 10) { model.RecommendAlbum = albumService.GetRecommendRandom(20); } tempCount = tempCount1 > tempCount ? tempCount1 : tempCount; //分页 if ((model.AlbumResult != null && model.AlbumResult.Count > 0) || (model.NewsResult != null && model.NewsResult.Count > 0)) { model.PageIndex = tempPage; model.PageSize = pageSize; model.PageStep = 10; model.AllCount = tempCount; if (model.AllCount % model.PageSize == 0) { model.PageCount = model.AllCount / model.PageSize; } else { model.PageCount = model.AllCount / model.PageSize + 1; } } //关键字 model.Keywords = keywords; if (model.AlbumResult == null) { model.AlbumResult = new List<Album>(); } return View(model); }
public ActionResult Index(string categoryId, string keywords, string page) { if (Session["UserId"] == null) { return Redirect("/admin/login"); } NewsService newsService = new NewsService(); int tempPage = 1; if (!string.IsNullOrEmpty(page)) { Int32.TryParse(page, out tempPage); } NewsModel model = new NewsModel(); //新闻类别列表 model.NewsCategories = newsService.GetNewsCategories(); //当前选中新闻类别 model.NewsCategory = new NewsCategory(); if (!string.IsNullOrEmpty(categoryId)) { if (model.NewsCategories != null && model.NewsCategories.Count > 0) { foreach (var item in model.NewsCategories) { if (item.Id == categoryId) { model.NewsCategory = item; break; } } } } //新闻列表 int tempCount = 0; model.NewsList = newsService.GetNewsList(categoryId, keywords, 15, tempPage, out tempCount); //分页 if (model.NewsList != null && model.NewsList.Count > 0) { model.PageIndex = tempPage; model.PageSize = 15; model.PageStep = 10; model.AllCount = tempCount; if (model.AllCount % model.PageSize == 0) { model.PageCount = model.AllCount / model.PageSize; } else { model.PageCount = model.AllCount / model.PageSize + 1; } } //关键字 model.Keywords = keywords; return View(model); }
public ActionResult Edit(News news) { string result = "更新失败"; if (Session["UserId"] == null) { return Content("长时间未操作,请重新登录。"); } if (news == null) { result = "参数为空"; } else { if (!string.IsNullOrEmpty(news.Title) && !string.IsNullOrEmpty(news.CategoryId) && !string.IsNullOrEmpty(news.ContentStyle)) { news.ContentText = news.ContentStyle; news.UpdateTime = DateTime.Now; news.IsActive = true; if (news.Keywords == null) { news.Keywords = string.Empty; } if (news.Description == null) { news.Description = string.Empty; } if (news.Author == null) { news.Author = string.Empty; } if (news.ComeFrom == null) { news.ComeFrom = string.Empty; } if (news.Cover == null) { news.Cover = string.Empty; } if (news.PictureGroup == null) { news.PictureGroup = string.Empty; } NewsService newsService = new NewsService(); result = newsService.EditNews(news); } else { result = "必填项 [标题、分类、内容] 不能为空"; } } return Content(result); }
public ActionResult Edit(int id) { if (Session["UserId"] == null) { return Redirect("/admin/login"); } NewsModel model = new NewsModel(); NewsService newsService = new NewsService(); model.NewsCategories = newsService.GetNewsCategories(); model.News = newsService.GetNewsById(id); if (model.News != null && !model.News.IsActive) { model.News = null; } if (model.News == null) { model.News = new News(); } return View(model); }
public ActionResult DeleteCategory(string id) { if (Session["UserId"] == null) { return Redirect("/admin/login"); } NewsService newsService = new NewsService(); newsService.RemoveNewsCategory(id); Cache.UpdateNewsCategories();//更新缓存 return Redirect(Request.UrlReferrer.AbsoluteUri); }
public ActionResult Delete(int id) { if (Session["UserId"] == null) { return Redirect("/admin/login"); } NewsService newsService = new NewsService(); newsService.RemoveNews(id); return Redirect(Request.UrlReferrer.AbsoluteUri); }