/// <summary> /// 设置指定用户角色 /// </summary> /// <param name="req">条件</param> /// <param name="oper">操作者信息</param> /// <returns></returns> public BaseItemRes <bool> SetUserRole(SetUserRoleReq req, OperatorInfo oper) { //验证登录名是否存在 var userDAL = this.GetUserDAL(); if (userDAL.ExistUser(req.LoginName) == false) { return(AccHelper.FailItemRes(AccConfig.Msg.UserNotExist, false)); } //用户角色实体 var lstUserRole = new List <UserRole>(); if (req.LstRoleCode != null && req.LstRoleCode.Count > 0) { var now = DateTime.Now; //当前时间 //角色 var roleDAL = this.GetRoleDAL(); //生成实体 foreach (var roleCode in req.LstRoleCode) { //验证角色是否存在 if (roleDAL.ExistRole(roleCode) == false) { return(AccHelper.FailItemRes(AccConfig.Msg.RoleNotExist, false)); } var userRole = new UserRole(); userRole.LoginName = req.LoginName; userRole.RoleCode = roleCode; userRole.Creater = oper.LoginName; userRole.CreateTime = now; lstUserRole.Add(userRole); } } //保存到数据库 this.userRoleDAL.SetUserRole(req.LoginName, lstUserRole); return(AccHelper.OkItemRes(true)); }
public BaseItemRes <bool> SetUserRole([FromBody] SetUserRoleReq req) { return(this.userRoleBLL.SetUserRole(req, this.CurUser)); }