public async Task Execute_CorrectCommand_EnablesUserAccount() { //Arrange var usersStub = new List <AppUser> { new AppUser { Id = "6bd969d6-cec7-4383-8aa0-d59b89f77602", Email = "*****@*****.**", FullName = "Mr Test", IsDisabled = false } }; var idStub = "6bd969d6-cec7-4383-8aa0-d59b89f77602"; var userManager = MockUserManager.Build(usersStub, idStub).Object; var command = new EnableUserCommand { Id = idStub }; var handler = new EnableUserCommandHandler(_config.Object, _logger.Object, _context, userManager); //Act await handler.Handle(command); //Assert var user = await userManager.FindByIdAsync(idStub); Assert.AreEqual(user.IsDisabled.Value, false); }
/// <summary> /// 用户启用停用 /// </summary> /// <param name="command"></param> public void Execute(EnableUserCommand command) { SysMember sysMember = memberRepository.GetById(command.Id); sysMember.Enable((short)command.State); memberRepository.SaveChange(sysMember); command.Result = new CommandResult() { Status = true }; }
public GenericCommandResult EnableUser( [FromBody] EnableUserCommand command, [FromServices] UserHandler handler, [FromServices] IUserRepository repository ) { var userAccout = new UserAccount(); userAccout = repository.GetUser(command.User); command.Id = userAccout.Id; return((GenericCommandResult)handler.Handle(command)); }
public ActionResult EditState() { if (Profile != null) { var id = this.RequestInt64("ID") ?? -1; var state = (UserState)(this.RequestInt16("state") ?? 0); var command = new EnableUserCommand(id, 1, state); CommandBus.Instance.Send(command); return(new ActionResult(command.Result.Status, null, null, command.Result.Msg)); } else { return(new ActionResult(false, null, null, "无权操作,你的IP我们已经记录!")); } }
public async Task Handle(EnableUserCommand command) { try { var user = await Repository.GetByKeyAsync<Domain.Models.User>(command.UserId); user.Disable(); await Repository.SaveChangesAsync(); var @event = new UserEnabledEvent(command.UserId); EventBus.RaiseEvent(@event); } catch { throw; } }
//[Authorize(Policy = "Desired.Add")] //TODO: Add a new profile less admin to do that public async Task <IActionResult> EnableUserAsync([FromBody] UserSystemViewModel userSystemViewModel) { if (!IsModelStateValid()) { return(Response()); } var userLoggedInDB = await GetUserDbByIdentityAsync(HttpContext); if (userLoggedInDB == null) { return(Response()); } var cmd = new EnableUserCommand( Mapper.Map <UserViewModel, User>(userLoggedInDB), userSystemViewModel.IdUserIdentity, userSystemViewModel.IdSystems ); await _mediator.SendCommand(cmd); return(Response(cmd)); }
public Task <EnableUserResponse> Enable([FromRoute] EnableUserCommand query) { return(_enableUserCommandHandler.Handle(query)); }