Ejemplo n.º 1
0
        public async Task <IActionResult> AddUserAndRoleAsync(UserAndRoleDto model)
        {
            try
            {
                //获取到用户信息
                IEnumerable <R_UserInfo> r_UserInfos = await dbContext.r_UserInfoRepository.GetAllInfoAsync();

                //根据名称查找到这一条数据
                R_UserInfo user = r_UserInfos.ToList().Where(s => s.UserName.Equals(model.User_Name)).FirstOrDefault();
                if (user == null)
                {
                    throw new Exception("没有找到这一条信息");
                }
                User_Role m = new User_Role()
                {
                    RoleID = model.RoleId, UserID = user.UserID
                };
                dbContext.user_RoleRepository.CreateInfo(m);
                if (await dbContext.user_RoleRepository.SaveAsync())
                {
                    return(Ok(1));
                }
                _logger.LogInformation($"{DateTime.Now.ToString("yyyyMMddHHmmssfff")}同时添加用户和角色信息");
                return(Ok("添加失败"));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public RemoveRoleFromUserCommandTest()
        {
            user = new AppUser {
                UserName = ""
            };
            userDto = new UserAndRoleDto {
                Username = "", Role = ""
            };

            identityService = new Mock <IIdentityService>();
            stringLocalizer = new Mock <IStringLocalizer <UsersResource> >();
            var roleStore = new Mock <IRoleStore <IdentityRole> >();

            roleManager = new Mock <RoleManager <IdentityRole> >(roleStore.Object, null, null, null, null);
        }
Ejemplo n.º 3
0
 public RemoveRoleFromUserCommand(UserAndRoleDto request)
 {
     Username = request.Username;
     Role     = request.Role;
 }
Ejemplo n.º 4
0
        public async Task <ActionResult> AddRoleToUser(UserAndRoleDto userRole)
        {
            await Mediator.Send(new AddRoleToUserCommand(userRole));

            return(NoContent());
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> RemoveRoleFromUser(UserAndRoleDto userRole)
        {
            await Mediator.Send(new RemoveRoleFromUserCommand(userRole));

            return(NoContent());
        }
 public AddRoleToUserCommand(UserAndRoleDto request)
 {
     Username = request.Username;
     Role     = request.Role;
 }