Example #1
0
        public async Task AddToRole(AddUserToRoleCommand 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.AddToRoleAsync(user, command.RoleName);

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

            await _userApplicationService.AddToRole(command);

            return(CreateResponse());
        }
        public async Task <StatusCodeResult> AddUserToRole(int userId, [FromBody] AddUserToRoleModel model, CancellationToken cancellationToken)
        {
            var command = new AddUserToRoleCommand()
            {
                UserId = userId,
                RoleId = model.RoleId
            };

            await mediator.Send(command, cancellationToken);

            return(StatusCode(StatusCodes.Status200OK));
        }
        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();
        }
Example #5
0
        public void AddUserToRole(AddUserToRoleCommand command)
        {
            var service = NcqrsEnvironment.Get <ICommandService>();

            service.Execute(command);
        }
        public async Task <ActionResult> AddUserToRole([FromBody] AddUserToRoleCommand addUserToRole)
        {
            string username = await Mediator.Send(addUserToRole);

            return(RedirectToAction("GetUser", new { username = username }));
        }
 public async Task <IActionResult> AddUserToRole([FromBody] AddUserToRoleCommand addUserToRoleCommand)
 => await ExecuteCommand(addUserToRoleCommand);