Ejemplo n.º 1
0
        public OperateResult <IEnumerable <Auth_RoleUser> > BindUsers(RoleBindUsersParam param)
        {
            //校验角色
            if (!_db.Auth_Role.Any(l => l.Id == param.RoleId))
            {
                return(OperateResult <IEnumerable <Auth_RoleUser> > .Error("角色不存在"));
            }
            //删除角色用户
            var roleUsers = _db.Auth_RoleUser.Where(l => l.RoleId == param.RoleId);
            var repo      = _unitOfWork.GetRepository <Auth_RoleUser>();

            repo.Delete(roleUsers);
            //生成实体
            var list = new List <Auth_RoleUser>();

            foreach (var userId in param.UserIds)
            {
                var obj = new Auth_RoleUser()
                {
                    Id     = Guid.NewGuid(),
                    UserId = userId,
                    RoleId = param.RoleId
                };
                list.Add(obj);
                repo.Insert(obj);
            }
            _unitOfWork.SaveChanges();
            return(OperateResult <IEnumerable <Auth_RoleUser> > .Ok("成功", list));
        }
 public ActionResult <OperateResult <IEnumerable <Auth_RoleUser> > > BindUsers([FromBody] RoleBindUsersParam param)
 {
     return(Json(_service.BindUsers(param)));
 }