ASP.NET MVC5網(wǎng)站開發(fā)文章管理架構(七)
一、總體說明
先看一下文章管理設想要實現(xiàn)的功能:

再看一下類圖

這里Category是欄目;CommonModel是公共模型;Article是文章;Attachment是附件;
CommonModel是內(nèi)容管理這塊抽取出來的公共部分,像文章,咨詢甚至產(chǎn)品都有一些共同的內(nèi)容這里把它單獨提取出來作為一個類。CommonModel可能包含一片文章,包含一組附件,包含一系列評論,他們之間的關系類圖中已經(jīng)表示出來。
二、搭建架構
這個順序根以前一樣

1、IDAL
在IDAL添加接口InterfaceCommonModelRepository,其實只是繼承自InterfaceBaseRepository,沒有添加任何其他內(nèi)容。
namespace Ninesky.IDAL
{
/// <summary>
/// 公共模型接口
/// <remarks>
/// 創(chuàng)建:2014.02.23
/// 修改:2014.02.28
/// </remarks>
/// </summary>
public interface InterfaceCommonModelRepository:InterfaceBaseRepository<Models.CommonModel> {
}
}再依次添加InterfaceCategory,InterfaceArticle,InterfaceAttachment,方式和公共模型接口相同。
2、DAL
DAL中是對IDAL接口的實現(xiàn),還是從CommonModel開始,先添加CommonModelRepository,也是跟原來一樣直接繼承沒有什么代碼。
namespace Ninesky.DAL
{
/// <summary>
/// 公共模型倉儲
/// <remarks>
/// 創(chuàng)建:2014.02.23
/// </remarks>
/// </summary>
public class CommonModelRepository:BaseRepository<Models.CommonModel>, IDAL.InterfaceCommonModel
{
}
}然后依次添加CategoryRepository,ArticleRepository,AttachmentRepository。
3.IBLL
這次先從InterfaceCategoryService開始,InterfaceArticleService,InterfaceCommentService,InterfaceAttachmentService。InterfaceCommonModelService內(nèi)容較多放在最后。
InterfaceCategoryService
具體功能會在做欄目的時候再寫,這里暫時空著。
namespace Ninesky.IBLL
{
/// <summary>
/// 欄目服務接口
/// <remarks>
/// 創(chuàng)建:2014.02.23
/// </remarks>
/// </summary>
public class InterfaceCategoryService:InterfaceBaseService<Models.Category>
{
}
}
4.BLL
同樣先從CategoryService開始,然后依次添加ArticleService,AttachmentService。CommonModelService。
using Ninesky.DAL;
using Ninesky.IBLL;
using Ninesky.Models;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Ninesky.BLL
{
/// <summary>
/// 欄目服務
/// <remarks>
/// 創(chuàng)建:2014.02.27
/// </remarks>
/// </summary>
public class CategoryService:BaseService<Category>,InterfaceCategoryService
{
public CategoryService() : base(RepositoryFactory.CategoryRepository) { }
}
}5、Web
在web項目的Member區(qū)域下添加三個空控制器。
欄目控制器CategoryController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ninesky.IBLL;
using Ninesky.BLL;
using Ninesky.Models;
namespace Ninesky.Web.Areas.Member.Controllers
{
[Authorize]
public class CategoryController : Controller
{
private InterfaceCategoryService categoryRepository;
public CategoryController() { categoryRepository = new CategoryService(); }
}
}
文章控制器ArticleController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ninesky.Models;
using Ninesky.IBLL;
using Ninesky.BLL;
namespace Ninesky.Web.Areas.Member.Controllers
{
public class ArticleController : Controller
{
private InterfaceArticleService articleService;
private InterfaceCommonModelService commonModelService;
public ArticleController() { articleService = new ArticleService(); commonModelService = new CommonModelService(); }
}
}附件控制器AttachmentController
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Web;
using System.Web.Mvc;
using System.IO;
using Ninesky.IBLL;
using Ninesky.BLL;
using Ninesky.Models;
namespace Ninesky.Web.Areas.Member.Controllers
{
/// <summary>
/// 附件控制器
/// <remarks>
/// 創(chuàng)建:2014.03.05
/// </remarks>
/// </summary>
[Authorize]
public class AttachmentController : Controller
{
}
}
架構結束啦,下面就開始實現(xiàn)文章相關功能!
- ASP.NET MVC5網(wǎng)站開發(fā)管理列表、回復及刪除(十三)
- ASP.NET MVC5網(wǎng)站開發(fā)我的咨詢列表及添加咨詢(十二)
- ASP.NET MVC5網(wǎng)站開發(fā)修改及刪除文章(十)
- ASP.NET MVC5網(wǎng)站開發(fā)添加文章(八)
- ASP.NET MVC5網(wǎng)站開發(fā)用戶修改資料和密碼(六)
- ASP.NET?MVC5網(wǎng)站開發(fā)用戶登錄、注銷(五)
- ASP.NET?MVC5網(wǎng)站開發(fā)用戶注冊(四)
- ASP.NET?MVC5網(wǎng)站開發(fā)項目框架(二)
- ASP.NET MVC5網(wǎng)站開發(fā)概述(一)
- MVC4制作網(wǎng)站教程第三章 刪除用戶組操作3.4
相關文章
常用的在數(shù)據(jù)庫中建立無限級樹形菜單的asp.net代碼
經(jīng)常在項目中遇到建立無限級樹形菜單展示的效果,這里簡單地做了一個,基本后臺代碼如下2008-09-09
ASP.NET Core Project.json文件(5)
這篇文章主要為大家詳細介紹了ASP.NET Core Project.json文件,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06
MVC+EasyUI+三層新聞網(wǎng)站建立 分頁查詢數(shù)據(jù)功能(七)
這篇文章主要為大家詳細介紹了MVC+EasyUI+三層新聞網(wǎng)站建立的第七篇,教大家如何分頁查詢出數(shù)據(jù),具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07
.NET單元測試使用AutoFixture按需填充的幾種方式和最佳實踐記錄
AutoFixture是一個.NET庫,旨在簡化單元測試中的數(shù)據(jù)設置過程,通過自動生成測試數(shù)據(jù),它幫助開發(fā)者減少測試代碼的編寫量,使得單元測試更加簡潔、易讀和易維護,本文介紹.NET單元測試使用AutoFixture按需填充的幾種方式和最佳實踐記錄,感興趣的朋友一起看看吧2024-07-07

