public async Task <ResultDto <ArticleDto> > GetPageDataAsync(ArticleQueryModel qModel) { var res = new ResultDto <ArticleDto>(); var query = _testDB.Article.AsNoTracking().Where(x => x.IsDeleted == false); query = qModel.Status.HasValue ? query.Where(x => x.Status == qModel.Status) : query; query = qModel.UserId.HasValue ? query.Where(x => x.UserId == qModel.UserId) : query; query = !string.IsNullOrEmpty(qModel.TypeName) ? query.Where(x => x.ArticleType.Name.Contains(qModel.TypeName)) : query; var queryData = query.Select(x => new ArticleDto() { Id = x.Id, Title = x.Title, Content = x.Content, TypeId = x.TypeId, CreateTime = x.CreateTime }); queryData = queryData.OrderBy(o => o.CreateTime); queryData = queryData.Skip((qModel.PageIndex - 1) * qModel.PageSize).Take(qModel.PageSize); res.ActionResult = true; res.Message = "Success"; res.List = await queryData.ToListAsync(); return(res); }
public PagingResultModel <ArticleResultModel> GetArticles(ArticleQueryModel query) { Expression <Func <Article, bool> > where = ExpressionExtension.TrueExpression <Article>() .AndIfHaveValue(query.Title, a => a.Title.Contains(query.Title)) .AndIfHaveValue(query.Tag, u => u.Tags.Contains(query.Tag)) .AndIfHaveValue(query.ColumnId?.ToString(), u => u.ColumnId == query.ColumnId); var articleQuery = from article in _articleRepository.Get().Where(@where) join column in _columnRepository.Get() on article.ColumnId equals column.Id into columnInfo from c in columnInfo.DefaultIfEmpty() orderby article.CreateTime descending select new ArticleResultModel { Id = article.Id, Title = article.Title, SubTitle = article.SubTitle, ColumnId = article.ColumnId, ColumnName = c.Name, Source = article.Source, Sort = article.Sort, Tags = article.Tags, Content = article.Content, CreateTime = article.CreateTime }; var skip = query.Size * (query.Page - 1); return(new PagingResultModel <ArticleResultModel> { Data = articleQuery.Skip(skip).Take(query.Size).ToList(), Count = articleQuery.Count() }); }
public ActionResult Index(ArticleQueryModel model, string Message = null) { ///操作判断开始 if (!string.IsNullOrEmpty(model.Method)) { if (model.Method.Equals("Trash")) { return(TrashList(model.ArticleIds)); } else if (model.Method.Equals("Edit")) { //return Edit(model.ArticleIds); } else if (model.Method.Equals("UnTrash")) { return(UnTrashList(model.ArticleIds)); } else if (model.Method.Equals("Delete")) { return(DeleteList(model.ArticleIds)); } } ViewBag.Message = Message; ///取得每页显示数 int pageSize = int.Parse(_settiongService.GetSetting("AdminArticlePageSize")); model.Page = model.Page <= 0 ? 1 : model.Page; model.PageSize = model.PageSize <= 0 ? pageSize : model.PageSize; ///更新数据库 if (model.PageSize != pageSize) { _settiongService.SetSetting("AdminArticlePageSize", model.PageSize.ToString()); } //构造查询条件 model.PageInfo = _articleService.FindArticlesByQuery(query => BulidQuery(query, model), model.Page, model.PageSize); model.Page = model.PageInfo.PageIndex; ///取得博客数目 model.AllCount = (int)_articleService.GetArticleSingle(qyery => qyery.Where(a => a.Type == ArticleType.Blog).Count()); model.OpenCount = (int)_articleService.GetArticleSingle(qyery => qyery.Where(a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Open).Count()); model.DeleteCount = (int)_articleService.GetArticleSingle(qyery => qyery.Where(a => a.Type == ArticleType.Blog && a.Status == ArticleStatus.Delete).Count()); ///取得审核评论数目 IDictionary <int, int> VerifyComment = new Dictionary <int, int>(); foreach (Article articel in model.PageInfo) { VerifyComment[articel.ArticleId] = (int)_commentService.GetCommentSingle(query => query.Where(c => c.Article.Type == ArticleType.Blog && c.Article.ArticleId == articel.ArticleId && c.Status == CommentStatus.Verify).Count()); } model.VerifyComment = VerifyComment; ///取得分类与分档 model.MonthCategorys = _categoryService.GetMonthCategory(); model.Categorys = _categoryService.GetAllCategory(); return(View("Index", model)); }
public async Task <IResultModel> Query(ArticleQueryModel model) { var result = new QueryResultModel <ArticleEntity> { Rows = await _repository.Query(model), Total = model.TotalCount }; return(ResultModel.Success(result)); }
public async Task <IList <ArticleEntity> > Query(ArticleQueryModel model) { var paging = model.Paging(); var query = Db.Find(); if (!paging.OrderBy.Any()) { query.OrderByDescending(m => m.Id); } var result = await query.LeftJoin <AccountEntity>((x, y) => x.CreatedBy == y.Id) .Select((x, y) => new { x, Creator = y.Name }) .PaginationAsync(paging); model.TotalCount = paging.TotalCount; return(result); }
public async Task <JsonResult> GetPageAsync(ArticleQueryModel qModel) { var res = await _articleSvc.GetPageDataAsync(qModel); return(Json(res)); }
public IActionResult Get([FromQuery] ArticleQueryModel articleQuery) { return(Ok(_articleService.GetArticles(articleQuery))); }
public void OnGet(string id) { Article = _articleQuery.GetArticleDetails(id); }
public void OnGet(string id) { Article = _articleQuery.GetArticleDetails(id); LatestArticles = _articleQuery.LatestArticles(); ArticleCategories = _articleCategoryQuery.GetArticleCategories(); }
/// <summary> /// 创建查询表达式 /// </summary> /// <param name="query"></param> /// <param name="model"></param> /// <returns></returns> public IQueryable <Article> BulidQuery(IQueryable <Article> query, ArticleQueryModel model) { ///状态限制 if (model.Status != null) { query = query.Where(a => a.Status == model.Status); } else { query = query.Where(a => a.Status != ArticleStatus.Delete); } ///标题查询 if (!string.IsNullOrEmpty(model.Title)) { query = query.Where(a => a.Title.Contains(model.Title)); } ///分类查询 if (model.Category != null && model.Category > 0) { query = query.Where(a => a.Categorys.Where(c => c.CategoryId == model.Category).Count() > 0); } ///标签查询 if (!string.IsNullOrEmpty(model.Tag)) { query = query.Where(a => a.Categorys.Where(c => c.Name == model.Tag && c.Type == CategoryType.Tag).Count() > 0); } ///分档查询 if (!string.IsNullOrEmpty(model.MonthCategory)) { try { int year = int.Parse(model.MonthCategory.Substring(0, 4)); int month = int.Parse(model.MonthCategory.Substring(4, 2)); query = query.Where(a => a.CreateDate.Year == year && a.CreateDate.Month == month); } catch (Exception) { View("Error"); } } ///开始排序 if (model.OrderBy == ArticleOrder.Title) { if (model.OrderType == OrderType.Asc) { return(query.OrderBy(a => a.Title)); } else { return(query.OrderByDescending(a => a.Title)); } } else if (model.OrderBy == ArticleOrder.CommentCount) { if (model.OrderType == OrderType.Asc) { return(query.OrderBy(a => a.CommentCount)); } else { return(query.OrderByDescending(a => a.CommentCount)); } } else if (model.OrderBy == ArticleOrder.CreateDate) { if (model.OrderType == OrderType.Asc) { return(query.OrderBy(a => a.CreateDate)); } else { return(query.OrderByDescending(a => a.CreateDate)); } } else { return(query.OrderByDescending(a => a.CreateDate)); } }
public IActionResult GetArticleList(ArticleQueryModel qModel) { return(null); }
public Task <IResultModel> Query([FromQuery] ArticleQueryModel model) { return(_service.Query(model)); }