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(); /// /// 获取用户数据 /// /// public List GetUsers() { //List users = DBFactory.Instance.Queryable().ToList(); var users = systemDal.QueryUserData(); return users; } public List GetRoles() { List roles = DBFactory.Instance.Queryable() .ToList(); return roles; } public int SaveUserData(config_user configUser, List roles) { //throw new NotImplementedException(); var _db = DBFactory.Instance; try { _db.BeginTran(); var val = _db.Insertable(configUser).ExecuteCommand(); var val2 = _db.Insertable(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 roles) { var _db = DBFactory.Instance; try { _db.BeginTran(); var val = _db.Updateable() .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().Where(p => p.user_id == configUser.id).ExecuteCommand(); var val2 = _db.Insertable(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(user) .Where(p => p.id == user.id) .ExecuteCommand(); //// //先删除用户角色 _db.Deleteable().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 GetUserRoles(string userId) { var result = DBFactory.Instance.Queryable() .Where(a=> a.user_id == userId) .ToList(); return result; } public bool CheckUser(string userName, string pwd) { var users = DBFactory.Instance.Queryable().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() .RightJoin((a, b) => a.role_id == b.role_id) .LeftJoin((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; } } }