示例#1
0
        public async Task RemoveFromRole(RemoveUserFromRoleCommand command)
        {
            command.Validate();

            if (AddNotifications(command))
            {
                return;
            }

            LedgerIdentityUser user = await GetByEmail(command.Email);

            if (NotifyNullUser(user))
            {
                return;
            }

            if (await NotifyNullRole(command.RoleName))
            {
                return;
            }

            IdentityResult result = await _userManager.RemoveFromRoleAsync(user, command.RoleName);

            if (!result.Succeeded)
            {
                AddNotifications(result);
            }
            else
            {
                await Publish(new UserRemovedFromRoleIntegrationEvent(user.Id, command.RoleName));
            }
        }
示例#2
0
        public async Task <IActionResult> RemoveFromRole(string email, [FromBody] RemoveUserFromRoleCommand command)
        {
            command.Email = email;

            await _userApplicationService.RemoveFromRole(command);

            return(CreateResponse());
        }
示例#3
0
        public async Task Handle(RemoveUserFromRoleCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return;
            }

            // Businness logic here
            var result = await _userService.RemoveUserFromRole(request.Name, request.Username);

            if (result)
            {
                await Bus.RaiseEvent(new UserRemovedFromRoleEvent(request.Name, request.Username));
            }
        }
示例#4
0
        public async Task <bool> Handle(RemoveUserFromRoleCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                NotifyValidationErrors(request);
                return(false);
            }

            var result = await _userService.RemoveUserFromRole(request.Name, request.Username);

            if (result)
            {
                await Bus.RaiseEvent(new UserRemovedFromRoleEvent(request.Name, request.Username));

                return(true);
            }
            return(false);
        }
        public static async Task MainAsync(IWebHost host, string[] args)
        {
            String command = "";

            if (args.Count() > 0)
            {
                command = args[0];
            }

            if (command == "SetUserRole")
            {
                var runner = new AddUserToRoleCommand();
                await runner.RunAsync(host, args.Skip(1).ToArray());
            }
            else if (command == "RemoveUserRole")
            {
                var runner = new RemoveUserFromRoleCommand();
                await runner.RunAsync(host, args.Skip(1).ToArray());
            }
            else if (command == "SeedDb")
            {
                var runner = new SeedDbCommand();
                await runner.RunAsync(host, args.Skip(1).ToArray());
            }
            else if (command == "ImportEnglishText")
            {
                var runner = new ImportEnglishTextCommand();
                await runner.RunAsync(host, args.Skip(1).ToArray());
            }
            else
            {
                Console.WriteLine("Command Not Found.");
            }

            Console.ReadLine();
        }
示例#6
0
        public void RemoveUserFromRole(RemoveUserFromRoleCommand command)
        {
            var service = NcqrsEnvironment.Get <ICommandService>();

            service.Execute(command);
        }
        public async Task <ActionResult> RemoveUserFromRole([FromBody] RemoveUserFromRoleCommand removeUserFromRole)
        {
            string userId = await Mediator.Send(removeUserFromRole);

            return(RedirectToAction("GetUser", new { username = userId }));
        }
示例#8
0
        public async Task <IActionResult> RemoveUserFromRole([FromQuery] RemoveUserFromRoleCommand command)
        {
            var result = await Mediator.Send(command);

            return(result.Successful == true?Ok(result) : BadRequest(result.Exception.InnerException.Message ?? result.Exception.Message));
        }