里 。
处理多级分类如果文章的分类不是一级分类 , 那么把它上面的所有分类找出来,一个个排好队,方便后面处理 。
// 处理多级分类var category = await _categoryRepo.Where(a => a.Id == dto.CategoryId).FirstAsync();if (category == null) {post.Categories = "0";}else {var categories = new List<Category> {category};var parent = category.Parent;while (parent != null) {categories.Add(parent);parent = parent.Parent;}categories.Reverse();post.Categories = string.Join(",", categories.Select(a => a.Id));}
最后保存搞定~
// 存入数据库post = await _postRepo.InsertAsync(post);
系列文章
- 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客?
- 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目
- 基于.NetCore开发博客项目 StarBlog - (3) 模型设计
- 基于.NetCore开发博客项目 StarBlog - (4) markdown博客批量导入
- 基于.NetCore开发博客项目 StarBlog - (5) 开始搭建Web项目
- 基于.NetCore开发博客项目 StarBlog - (6) 页面开发之博客文章列表
- 基于.NetCore开发博客项目 StarBlog - (7) 页面开发之文章详情页面
- 基于.NetCore开发博客项目 StarBlog - (8) 分类层级结构展示
- 基于.NetCore开发博客项目 StarBlog - (9) 图片批量导入
- 基于.NetCore开发博客项目 StarBlog - (10) 图片瀑布流
- 基于.NetCore开发博客项目 StarBlog - (11) 实现访问统计
- 基于.NetCore开发博客项目 StarBlog - (12) Razor页面动态编译
- 基于.NetCore开发博客项目 StarBlog - (13) 加入友情链接功能
- 基于.NetCore开发博客项目 StarBlog - (14) 实现主题切换功能
- 基于.NetCore开发博客项目 StarBlog - (15) 生成随机尺寸图片
- 基于.NetCore开发博客项目 StarBlog - (16) 一些新功能 (监控/统计/配置/初始化)
- 基于.NetCore开发博客项目 StarBlog - (17) 自动下载文章里的外部图片
- 基于.NetCore开发博客项目 StarBlog - (18) 实现本地Typora文章打包上传
- https://www.cnblogs.com/liguix/p/11883248.html
推荐阅读
- 一 CPS攻击案例——基于脉冲宽度调制PWM的无人机攻击
- Vue3 Vite3 多环境配置 - 基于 vite 创建 vue3 全家桶项目(续篇)
- 2 Libgdx游戏开发——接水滴游戏实现
- 五 Qt+ECharts开发笔记:ECharts的动态排序柱状图介绍、基础使用和Qt封装Demo
- 18-基于CentOS7搭建RabbitMQ3.10.7集群镜像队列+HaProxy+Keepalived高可用架构
- Asp-Net-Core开发笔记:集成Hangfire实现异步任务队列和定时任务
- 【疫情动态条形图】用Python开发全球疫情排名动态条形图bar_chart_race
- 驱动开发:通过Async反向与内核通信
- 云原生下基于K8S声明式GitOps持续部署工具ArgoCD实战-上
- gRPC+Protocol Buffer Go微服务实战 - 用户服务开发