添加项目文件。
This commit is contained in:
159
SamplePre.ProcessBll/ConfigManagerBLL/RolesBll.cs
Normal file
159
SamplePre.ProcessBll/ConfigManagerBLL/RolesBll.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using DataDAL;
|
||||
using Models.Const;
|
||||
using Models.Ext;
|
||||
using Models.Models;
|
||||
using SamplePre.Common;
|
||||
using SamplePre.Common.Helper;
|
||||
using SamplePre.DAL;
|
||||
using SamplePre.DAL.DBContext;
|
||||
using SamplePre.Models;
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.Models.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Collections.Specialized.BitVector32;
|
||||
|
||||
namespace SamplePre.ProcessBll.BLL
|
||||
{
|
||||
public class RolesBll
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除角色
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public int DeleteRole(config_role role)
|
||||
{
|
||||
|
||||
var _db = DBFactory.Instance;
|
||||
|
||||
try
|
||||
{
|
||||
_db.BeginTran();
|
||||
var val = _db.Deleteable<config_role>(role)
|
||||
.Where(p => p.id == role.id)
|
||||
.ExecuteCommand();
|
||||
|
||||
|
||||
////
|
||||
//删除角色权限
|
||||
_db.Deleteable<config_role_permisson>().Where(p => p.role_id == role.id).ExecuteCommand();
|
||||
|
||||
|
||||
_db.CommitTran();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_db.RollbackTran();
|
||||
LoggerHelper.Logger.Error(ex.Message);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取功能树
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public List<config_function_ext> GetFuncDataTree()
|
||||
{
|
||||
List<config_function> funcList = DBFactory.Instance.Queryable<config_function>().ToList();
|
||||
List<config_function_ext> funcList2 = new List<config_function_ext>();
|
||||
|
||||
foreach(var item in funcList)
|
||||
{
|
||||
config_function_ext ext = new config_function_ext();
|
||||
ext.code = item.code;
|
||||
ext.id = item.id;
|
||||
ext.name = item.name;
|
||||
ext.description = item.description;
|
||||
ext.IsChecked = false;
|
||||
ext.parent_id = item.parent_id;
|
||||
|
||||
funcList2.Add(ext);
|
||||
}
|
||||
|
||||
return funcList2;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取角色的权限id集合
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public List<int> GetPermission(string id)
|
||||
{
|
||||
var list = DBFactory.Instance.Queryable<config_role_permisson>()
|
||||
.Where(p => p.role_id == id)
|
||||
.Select(p => p.function_id)
|
||||
.ToList();
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<config_role> GetRoles()
|
||||
{
|
||||
List<config_role> roles = DBFactory.Instance.Queryable<config_role>().ToList();
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
public int SavePermission(List<config_role_permisson> rolePermissonList)
|
||||
{
|
||||
var _db = DBFactory.Instance;
|
||||
|
||||
try
|
||||
{
|
||||
_db.BeginTran();
|
||||
|
||||
//先删除
|
||||
var val = _db.Deleteable<config_role_permisson>()
|
||||
.Where(p => p.role_id == rolePermissonList[0].role_id)
|
||||
.ExecuteCommand();
|
||||
|
||||
|
||||
///保存权限
|
||||
DBFactory.Instance.Insertable<config_role_permisson>(rolePermissonList).ExecuteCommand();
|
||||
|
||||
_db.CommitTran();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_db.RollbackTran();
|
||||
LoggerHelper.Logger.Error(ex.Message);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int SaveRoleData(config_role configRole)
|
||||
{
|
||||
var val = DBFactory.Instance.Insertable<config_role>(configRole).ExecuteCommand();
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
public int UpdateRoleData(config_role configRole)
|
||||
{
|
||||
var val = DBFactory.Instance.Updateable<config_role>(configRole).ExecuteCommand();
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
176
SamplePre.ProcessBll/ConfigManagerBLL/UsersBll.cs
Normal file
176
SamplePre.ProcessBll/ConfigManagerBLL/UsersBll.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
using DataDAL;
|
||||
using Models.Const;
|
||||
using Models.Ext;
|
||||
using Models.Models;
|
||||
using SamplePre.Common;
|
||||
using SamplePre.DAL;
|
||||
using SamplePre.DAL.DBContext;
|
||||
using SamplePre.Models.Ext;
|
||||
using SamplePre.Models.Tables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Collections.Specialized.BitVector32;
|
||||
|
||||
namespace SamplePre.ProcessBll.BLL
|
||||
{
|
||||
public class UsersBll
|
||||
{
|
||||
|
||||
SystemDal systemDal = new SystemDal();
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<config_user_ext> GetUsers()
|
||||
{
|
||||
//List<config_user> users = DBFactory.Instance.Queryable<config_user>().ToList();
|
||||
|
||||
var users = systemDal.QueryUserData();
|
||||
return users;
|
||||
}
|
||||
|
||||
|
||||
public List<config_role> GetRoles()
|
||||
{
|
||||
List<config_role> roles = DBFactory.Instance.Queryable<config_role>()
|
||||
.ToList();
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
public int SaveUserData(config_user configUser, List<config_user_role> roles)
|
||||
{
|
||||
//throw new NotImplementedException();
|
||||
|
||||
var _db = DBFactory.Instance;
|
||||
|
||||
try
|
||||
{
|
||||
_db.BeginTran();
|
||||
var val = _db.Insertable<config_user>(configUser).ExecuteCommand();
|
||||
|
||||
var val2 = _db.Insertable<config_user_role>(roles).ExecuteCommand();
|
||||
|
||||
_db.CommitTran();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_db.RollbackTran();
|
||||
LoggerHelper.Logger.Error(ex.Message);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int UpdateUserData(config_user configUser, List<config_user_role> roles)
|
||||
{
|
||||
var _db = DBFactory.Instance;
|
||||
|
||||
try
|
||||
{
|
||||
_db.BeginTran();
|
||||
var val = _db.Updateable<config_user>()
|
||||
.SetColumns(it => new config_user() { username = configUser.username
|
||||
,password = configUser.password
|
||||
,is_enabled = configUser.is_enabled })
|
||||
.Where(p => p.id == configUser.id)
|
||||
.ExecuteCommand();
|
||||
|
||||
|
||||
////用户角色
|
||||
//先删除,后插入
|
||||
_db.Deleteable<config_user_role>().Where(p => p.user_id == configUser.id).ExecuteCommand();
|
||||
var val2 = _db.Insertable<config_user_role>(roles).ExecuteCommand();
|
||||
|
||||
_db.CommitTran();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_db.RollbackTran();
|
||||
LoggerHelper.Logger.Error(ex.Message);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int DeleteUser(config_user user)
|
||||
{
|
||||
var _db = DBFactory.Instance;
|
||||
|
||||
try
|
||||
{
|
||||
_db.BeginTran();
|
||||
var val = _db.Deleteable<config_user>(user)
|
||||
.Where(p => p.id == user.id)
|
||||
.ExecuteCommand();
|
||||
|
||||
|
||||
////
|
||||
//先删除用户角色
|
||||
_db.Deleteable<config_user_role>().Where(p => p.user_id == user.id).ExecuteCommand();
|
||||
|
||||
|
||||
_db.CommitTran();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_db.RollbackTran();
|
||||
LoggerHelper.Logger.Error(ex.Message);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public List<config_user_role> GetUserRoles(string userId)
|
||||
{
|
||||
|
||||
var result = DBFactory.Instance.Queryable<config_user_role>()
|
||||
.Where(a=> a.user_id == userId)
|
||||
.ToList();
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public bool CheckUser(string userName, string pwd)
|
||||
{
|
||||
var users = DBFactory.Instance.Queryable<config_user>().Where(p => p.username == userName && p.password == pwd).Single();
|
||||
if(users == null || string.IsNullOrEmpty(users.username)) return false;
|
||||
|
||||
SystemConst.loginUserInfo.user = users;
|
||||
|
||||
//查询用户权限
|
||||
var result = DBFactory.Instance.Queryable<config_user_role>()
|
||||
.RightJoin<config_role_permisson>((a, b) => a.role_id == b.role_id)
|
||||
.LeftJoin<config_function>((a, b, c) => b.function_id == c.id)
|
||||
.Where((a, b, c) => a.user_id == users.id)
|
||||
.Select((a, b, c) => new config_function
|
||||
{
|
||||
id = c.id,
|
||||
name = c.name,
|
||||
code = c.code,
|
||||
parent_id = c.parent_id,
|
||||
description = c.description
|
||||
})
|
||||
.ToList();
|
||||
|
||||
SystemConst.loginUserInfo.functions = result;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user