ASP.NET MVC5 網站開發實踐(二) Member區域 - 文章管理架構


上次把member的用戶部分完成,現在開始做文章管理部分。文章部分根據涉及顯示現實文章列表,發布文章,修改文章,刪除文章等功能。最終的實現目標是使用權限來控制用戶是否能進行相應操作,管理員權限的會顯示全部文章列表和我的文章列表,普通用戶只顯示我的文章列表。由於還沒做權限這塊所以沒法判斷,暫時登錄后所有都可以操作。

目錄

ASP.NET MVC5 網站開發實踐 - 概述

ASP.NET MVC5 網站開發實踐(一) - 項目框架

ASP.NET MVC5 網站開發實踐(一) - 框架(續) 模型、數據存儲、業務邏輯

ASP.NET MVC5 網站開發實踐(二) - 用戶部分(1)用戶注冊

ASP.NET MVC5 網站開發實踐(二) - 用戶部分(2)用戶登錄、注銷

ASP.NET MVC5 網站開發實踐(二) - 用戶部分(3)修改資料、修改密碼

一、總體說明

先看一下文章管理設想要實現的功能:

image

再看一下類圖

image

這里Category是欄目;CommonModel是公共模型;Article是文章;Attachment是附件;

CommonModel是內容管理這塊抽取出來的公共部分,像文章,咨詢甚至產品都有一些共同的內容這里把它單獨提取出來作為一個類。CommonModel可能包含一片文章,包含一組附件,包含一系列評論,他們之間的關系類圖中已經表示出來。

 

二、搭建架構

這個順序根以前一樣

image

1、IDAL

在IDAL添加接口InterfaceCommonModelRepository,其實只是繼承自InterfaceBaseRepository,沒有添加任何其他內容。

namespace Ninesky.IDAL
{
    /// <summary>
    /// 公共模型接口
    /// <remarks>
    /// 創建:2014.02.23
    /// 修改:2014.02.28
    /// </remarks>
    /// </summary>
    public interface InterfaceCommonModelRepository:InterfaceBaseRepository<Models.CommonModel> {

    }
}

再依次添加InterfaceCategory,InterfaceArticle,InterfaceAttachment,方式和公共模型接口相同。

2、DAL

DAL中是對IDAL接口的實現,還是從CommonModel開始,先添加CommonModelRepository,也是跟原來一樣直接繼承沒有什么代碼。

namespace Ninesky.DAL
{
    /// <summary>
    /// 公共模型倉儲
    /// <remarks>
    /// 創建:2014.02.23
    /// </remarks>
    /// </summary>
    public class CommonModelRepository:BaseRepository<Models.CommonModel>, IDAL.InterfaceCommonModel
    {
    }
}

然后依次添加CategoryRepository,ArticleRepository,AttachmentRepository。

3.IBLL

這次先從InterfaceCategoryService開始,InterfaceArticleService,InterfaceCommentService,InterfaceAttachmentService。InterfaceCommonModelService內容較多放在最后。

InterfaceCategoryService

具體功能會在做欄目的時候再寫,這里暫時空着。

namespace Ninesky.IBLL
{
    /// <summary>
    /// 欄目服務接口
    /// <remarks>
    /// 創建: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>
    /// 創建:2014.02.27
    /// </remarks>
    /// </summary>
    public class CategoryService:BaseService<Category>,InterfaceCategoryService
    {
        public CategoryService() : base(RepositoryFactory.CategoryRepository) { }
    }
}

5、Web

在web項目的Member區域下添加三個空控制器。

欄目控制器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>
    /// 創建:2014.03.05
    /// </remarks>
    /// </summary>
    [Authorize]
    public class AttachmentController : Controller
    {
 }
}

架構結束,明天開始實現文章相關功能!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM