/// <summary> /// 发布帖子 /// </summary> /// <returns></returns> public IActionResult Add() { Common.PostsChannel postsProperty = new Common.PostsChannel(); var model = postsProperty.GetListByCache(); return(View(model)); }
public ViewModels.PostsViewModel LoadMainData(int id) { ViewModels.PostsViewModel model = new ViewModels.PostsViewModel(); //查询帖子数据 int pageIndex = Framework.Core.Transform.GetInt(Request.Query["p"], 1); int pageSize = 10; PostsRepository repository = new PostsRepository(); var query = repository.GetPostsPageList(); model.ListData = query.Where(m => (id > 0 ? m.ChannelId == id : m.ChannelId > 0) && m.IsShow == true).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList(); model.TotalCount = query.Where(m => (id > 0 ? m.ChannelId == id : m.ChannelId > 0) && m.IsShow == true).Count(); //加载帖子频道 Common.PostsChannel postsProperty = new Common.PostsChannel(); model.PostsChannelData = postsProperty.GetListByCache(); //加载热门帖子 model.HotListData = query.OrderByDescending(m => m.ReadCount).Where(m => m.PostDate >= DateTime.Now.AddDays(-7)).Skip(0).Take(10).ToList(); return(model); }
/// <summary> /// 帖子内容阅读 /// </summary> /// <param name="id"></param> /// <returns></returns> public IActionResult Read(string id) { int postsId = Framework.Core.Transform.GetInt(id, 0); ViewModels.PostsReadViewModel model = new ViewModels.PostsReadViewModel(); if (postsId != 0) { PostsRepository repository = new PostsRepository(); model.PostsData = repository.GetPosts(postsId)[0]; int pageSize = 10; int pageIndex = Framework.Core.Transform.GetInt(Request.Query["p"], 1); var query = repository.GetAnswerPageList(); model.AnswerListData = query.Where(m => m.PostsId == postsId).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList(); model.TotalCount = query.Where(m => m.PostsId == postsId).Count(); //加载帖子频道 Common.PostsChannel postsProperty = new Common.PostsChannel(); model.PostsChannelData = postsProperty.GetListByCache(); //加载热门帖子 model.HotListData = repository.GetPostsListByHot().OrderByDescending(m => m.PlusCount).Where(m => m.PostDate >= DateTime.Now.AddDays(-7)).Skip(0).Take(10).ToList(); } return(View(model)); }
public IActionResult Edit(int id) { ViewModels.PostsEditViewModel model = new ViewModels.PostsEditViewModel(); int postsId = id; int userId = Framework.Core.Transform.GetInt(HttpContext.Session.GetString("UserId"), 0); //加载帖子数据 PostsRepository repository = new PostsRepository(); model.PostsData = repository.GetPostsByEdit(postsId, userId); if (model.PostsData != null) { //加载帖子频道数据 Common.PostsChannel postsProperty = new Common.PostsChannel(); model.PostsChannels = postsProperty.GetListByCache(); return(View(model)); } return(new ContentResult() { Content = "您的请求未得到授权!", StatusCode = 401 }); }
/// <summary> /// 加载属性列表 /// </summary> /// <returns></returns> public string LoadProperty() { //加载属性数据 Common.PostsChannel common = new Common.PostsChannel(); return(Newtonsoft.Json.JsonConvert.SerializeObject(common.GetListByCache())); }