public Task <ICommandResult> PutEmail([FromBody] UpdateEmailUserCommand command) { command.Id = Guid.Parse(User.FindFirst(ClaimTypes.Sid)?.Value); command.Email = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; var result = _handler.Handle(command); return(result); }
public async Task <ICommandResult> Handle(UpdateEmailUserCommand command) { //validar command command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Ops, algo errado aconteceu!", command.Notifications)); } //CheckNewEmail if (await _repository.CheckEmail(command.NewEmail)) { AddNotification("Check.Email", "Este e-mail já está cadastrado"); } //GetUser var user = await _repository.GetUser(command.Id, command.Email); if (user == null) { return(new GenericCommandResult(false, "Usuário não encontrado", null)); } //Criar VO's var email = new Email(command.NewEmail); AddNotifications(email); if (Invalid) { return(new GenericCommandResult(false, "Ops, algo errado aconteceu!", Notifications)); } user.UpdateEmail(email); _ = _repository.Update(user); //Async update user.Password.HidePassword(); //Retorna valores return(new GenericCommandResult(true, "E-mail atualziado", new { user })); }