添加项目文件。
This commit is contained in:
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