public async Task <bool> Handle(AddUserRoleCommand request, CancellationToken cancellationToken) { var user = await _userRepository.GetUserByIdIncludeRolesAsync(request.UserId); if (user == null) { await _bus.RaiseEvent( new DomainNotification(request.UserId.ToString(), "未找到对应的数据", StatusCodes.Status404NotFound), cancellationToken); return(false); } var roles = await _roleRepository.GetWhereAsync(x => request.RoleIds.Contains(x.Id)); user.Roles.AddRange(roles); if (await Commit()) { var key = GirvsEntityCacheDefaults <User> .ByIdCacheKey.Create(user.Id.ToString()); _bus.RaiseEvent(new RemoveCacheEvent(key), cancellationToken); _bus.RaiseEvent(new RemoveCacheListEvent(GirvsEntityCacheDefaults <User> .ListCacheKey.Create()), cancellationToken); _bus.RaiseEvent(new RemoveServiceCacheEvent(), cancellationToken); } return(true); }
public void AddUserRole(Guid userId, Guid roleId) { userContext.CheckPermission(Permissions.UserMaintenance); var command = new AddUserRoleCommand(userId, roleId); commandBus.Value.Send(Envelope.Create(command)); }
public void AddUserRoleCommandTest() { var userRoleCommand = new AddUserRoleCommand { UserId = "0674dc4c-dd3e-4eb4-8eb0-163664e60a24", RoleTypeId = "SYS_MODEL", UserLoginId = "00622e41-b4ca-4670-a3e9-b06a2b619e65" }; var result = _service.InvokeCommand(userRoleCommand); }
public async Task <IActionResult> AddRole([FromBody] AddUserRoleCommand command) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _mediator.Send(command); return(Ok(result)); }
public async Task AddUserRole(Guid userId, [FromForm] EditUserRoleViewModel model) { var command = new AddUserRoleCommand( userId, model.RoleIds ); await _bus.SendCommand(command); if (_notifications.HasNotifications()) { var errorMessage = _notifications.GetNotificationMessage(); throw new GirvsException(StatusCodes.Status400BadRequest, errorMessage); } }
public IHttpActionResult AddUserRole(Guid userId, AddUserRoleCommand command) { if (userId == Guid.Empty) { throw new ArgumentException("userId must be defined."); } if (command == null) { throw new ArgumentNullException("command"); } if (command.RoleId == Guid.Empty) { throw new ArgumentException("User role id must be defined."); } identityManagementService.AddUserRole(userId, command.RoleId); return(Ok()); }
public async Task <IActionResult> AddUserRoleAsync(AddUserRoleCommand command) { await Mediator.Send(command); return(NoContent()); }
private void AddRole(Guid userId, Guid roleId) { var command = new AddUserRoleCommand(userId, roleId); commandBus.Value.Send(Envelope.Create(command)); }
private void AddRole(Guid userId, Guid roleId) { var command = new AddUserRoleCommand(userId, roleId); commandBus.Value.Send(Envelope.Create(command)); }