·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(23)-权限管理系统-角色组模块

构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(23)-权限管理系统-角色组模块

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23

构建asp.net MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(23)-权限管理系统-角色组模块

系列目录

距离上次发布22讲已经有少许日子了,真是太抱歉,最近年关项目比较急,时间太紧,没有时间发布.请大家见谅

接下来我们的目标是

  1. 角色组管理
  2. 角色组权限设置
  3. 用户管理
  4. 把角色组授权给用户
  5. 给用户分配角色组

所以最少我们还要讲多5讲才能结束这个管理系统,经过之前的样例程序,我们很熟悉这个套路了,如果你很喜欢这个系列,你可以为这种重复性的动作写一个简单的代码生成器,或者一套强大的T4模版,其实这2个我都有,而且也是刚写的,以后系统完善了,给发布出来。

是不是还可以呢,哈哈,T4我也写了一套,但毕竟还是没有winfrom来得方便。

接下来我们在之前做好的模块管理,在22讲中,添加角色组管理的记录和操作码,如图

目前我是需要添加这么多个操作码。回头就机械性的创建DAL层,BLL层,Model层,还有注入

using System;using System.Collections.Generic;using System.Linq;using System.Text;using App.Models;namespace App.IDAL{    public interface ISysRoleRepository    {             IQueryable<SysRole> GetList(DBContainer db);        int Create(SysRole entity);        int Delete(string id);        int Edit(SysRole entity);        SysRole GetById(string id);        bool IsExist(string id);    }}
ISysRoleRepository
using System;using System.Collections.Generic;using System.Linq;using System.Text;using App.Models;using App.IDAL;using System.Data;namespace App.DAL{    public class SysRoleRepository : IDisposable,ISysRoleRepository    {        public IQueryable<SysRole> GetList(DBContainer db)        {            IQueryable<SysRole> list = db.SysRole.AsQueryable();            return list;        }        public int Create(SysRole entity)        {            using (DBContainer db = new DBContainer())            {                db.SysRole.AddObject(entity);                return db.SaveChanges();            }        }        public int Delete(string id)        {            using (DBContainer db = new DBContainer())            {                SysRole entity = db.SysRole.SingleOrDefault(a => a.Id == id);                if (entity != null)                {                    db.SysRole.DeleteObject(entity);                }                return db.SaveChanges();            }        }        public int Edit(SysRole entity)        {            using (DBContainer db = new DBContainer())            {                db.SysRole.Attach(entity);                db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);                return db.SaveChanges();            }        }        public SysRole GetById(string id)        {            using (DBContainer db = new DBContainer())            {                return db.SysRole.SingleOrDefault(a => a.Id == id);            }        }        public bool IsExist(string id)        {            using (DBContainer db = new DBContainer())            {                SysRole entity = GetById(id);                if (entity != null)                    return true;                return false;            }        }        public void Dispose()        {        }    }}
SysRoleRepository
using System;using System.Collections.Generic;using System.Linq;using System.Text;using App.Models;using App.Common;using App.Models.Sys;namespace App.IBLL{    public interface ISysRoleBLL    {        List<SysRoleModel> GetList(ref GridPager pager, string queryStr);        bool Create(ref ValidationErrors errors, SysRoleModel model);        bool Delete(ref ValidationErrors errors, string id);        bool Edit(ref ValidationErrors errors, SysRoleModel model);        SysRoleModel GetById(string id);        bool IsExist(string id);    }}
ISysRoleBLL
using System;using System.Collections.Generic;using System.Linq;using Microsoft.PRactices.Unity;using App.Models;using App.Common;using System.Transactions;using App.Models.Sys;using App.IBLL;using App.IDAL;using App.BLL.Core;namespace App.BLL{    public class SysRoleBLL : BaseBLL, ISysRoleBLL    {        [Dependency]        public ISysRoleRepository m_Rep { get; set; }        public List<SysRoleModel> GetList(ref GridPager pager, string queryStr)        {            IQueryable<SysRole> queryData = null;            if (!string.IsNullOrWhiteSpace(queryStr))            {                queryData = m_Rep.GetList(db).Where(a => a.Name.Contains(queryStr));            }            else            {                queryData = m_Rep.GetList(db);            }            pager.totalRows = queryData.Count();            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);            return CreateModelList(ref queryData);        }        private List<SysRoleModel> CreateModelList(ref IQueryable<SysRole> queryData)        {            List<SysRoleModel> modelList = new List<SysRoleModel>();            foreach (var r in queryData)            {                modelList.Add(new SysRoleModel()                {                    Id = r.Id,                    Name = r.Name,                    Description = r.Description,                    CreateTime = r.CreateTime,                    CreatePerson = r.CreatePerson,                    UserName = ""                });            }            return modelList;        }        public bool Create(ref ValidationErrors errors, SysRoleModel model)        {            try            {                SysRole entity = m_Rep.GetById(model.Id);                if (entity != null)                {                    errors.Add(Suggestion.PrimaryRepeat);                    return false;                }                entity = new SysRole();                entity.Id = model.Id;                entity.Name = model.Name;                entity.Description = model.Description;                entity.CreateTime = model.CreateTime;                entity.CreatePerson = model.CreatePerson;                if (m_Rep.Create(entity) == 1)                {                    //分配给角色                    db.P_Sys_InsertSysRight();                    //清理无用的项                    db.P_Sys_ClearUnusedRightOperate();                    return true;                }                else                {                    errors.Add(Suggestion.InsertFail);                    return false;                }            }            catch (Exception ex)            {                errors.Add(ex.Message);                ExceptionHander.WriteException(ex);                return false;            }        }        public bool Delete(ref ValidationErrors errors, string id)        {            try            {                if (m_Rep.Delete(id) == 1)                {                    r