系列目錄
距離上次發(fā)布22講已經(jīng)有少許日子了,真是太抱歉,最近年關(guān)項(xiàng)目比較急,時(shí)間太緊,沒(méi)有時(shí)間發(fā)布.請(qǐng)大家見(jiàn)諒
接下來(lái)我們的目標(biāo)是
所以最少我們還要講多5講才能結(jié)束這個(gè)管理系統(tǒng),經(jīng)過(guò)之前的樣例程序,我們很熟悉這個(gè)套路了,如果你很喜歡這個(gè)系列,你可以為這種重復(fù)性的動(dòng)作寫(xiě)一個(gè)簡(jiǎn)單的代碼生成器,或者一套強(qiáng)大的T4模版,其實(shí)這2個(gè)我都有,而且也是剛寫(xiě)的,以后系統(tǒng)完善了,給發(fā)布出來(lái)。
是不是還可以呢,哈哈,T4我也寫(xiě)了一套,但畢竟還是沒(méi)有winfrom來(lái)得方便。
接下來(lái)我們?cè)谥白龊玫哪K管理,在22講中,添加角色組管理的記錄和操作碼,如圖
目前我是需要添加這么多個(gè)操作碼。回頭就機(jī)械性的創(chuàng)建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(); //清理無(wú)用的項(xiàng) 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
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注