コード例 #1
0
        public async Task <ICommandResult> Handle(UpdateNameUserCommand command)
        {
            //validar command
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Ops, algo errado aconteceu!", command.Notifications));
            }

            //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 name = new Name(command.FirstName, command.LastName);

            AddNotifications(name);

            if (Invalid)
            {
                return(new GenericCommandResult(false, "Ops, algo errado aconteceu!", Notifications));
            }

            user.UpdateName(name);
            _ = _repository.Update(user);

            user.Password.HidePassword();
            //Retorna valores
            return(new GenericCommandResult(true, "Nome atualizado", new { user }));
        }
コード例 #2
0
        public Task <ICommandResult> PutName([FromBody] UpdateNameUserCommand command)
        {
            command.Id    = Guid.Parse(User.FindFirst(ClaimTypes.Sid)?.Value);
            command.Email = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var result = _handler.Handle(command);

            return(result);
        }