Exemplo n.º 1
0
        public async Task <bool> Handle(IdentifiedCommand <CadastroCommand, bool> request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException();
            }

            var command = request.Command;
            var guid    = request.Id;

            if (command == null)
            {
                throw new ArgumentNullException();
            }

            if (guid == Guid.Empty)
            {
                throw new ArgumentException();
            }

            if (string.IsNullOrWhiteSpace(command.UsuarioId) ||
                string.IsNullOrWhiteSpace(command.Nome) ||
                string.IsNullOrWhiteSpace(command.Email) ||
                string.IsNullOrWhiteSpace(command.Telefone) ||
                string.IsNullOrWhiteSpace(command.Endereco) ||
                string.IsNullOrWhiteSpace(command.Complemento) ||
                string.IsNullOrWhiteSpace(command.Bairro) ||
                string.IsNullOrWhiteSpace(command.Municipio) ||
                string.IsNullOrWhiteSpace(command.UF) ||
                string.IsNullOrWhiteSpace(command.CEP)
                )
            {
                throw new InvalidUserDataException();
            }

            try
            {
                IDictionary <string, string> claims = new Dictionary <string, string>
                {
                    ["name"]            = command.Nome,
                    ["email"]           = command.Email,
                    ["address"]         = command.Endereco,
                    ["address_details"] = command.Complemento,
                    ["phone"]           = command.Telefone,
                    ["neighborhood"]    = command.Bairro,
                    ["city"]            = command.Municipio,
                    ["state"]           = command.UF,
                    ["zip_code"]        = command.CEP
                };

                await _claimsManager.AddUpdateClaim(command.UsuarioId, claims);

                return(true);
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                throw;
            }
        }
Exemplo n.º 2
0
        public async Task <bool> Handle(IdentifiedCommand <RegistrationCommand, bool> request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                throw new ArgumentNullException();
            }

            var command = request.Command;
            var guid    = request.Id;

            if (command == null)
            {
                throw new ArgumentNullException();
            }

            if (guid == Guid.Empty)
            {
                throw new ArgumentException();
            }

            if (string.IsNullOrWhiteSpace(command.UserId) ||
                string.IsNullOrWhiteSpace(command.Nome) ||
                string.IsNullOrWhiteSpace(command.Email) ||
                string.IsNullOrWhiteSpace(command.Phone) ||
                string.IsNullOrWhiteSpace(command.Address) ||
                string.IsNullOrWhiteSpace(command.AdditionalAddress) ||
                string.IsNullOrWhiteSpace(command.District) ||
                string.IsNullOrWhiteSpace(command.City) ||
                string.IsNullOrWhiteSpace(command.State) ||
                string.IsNullOrWhiteSpace(command.ZipCode)
                )
            {
                throw new InvalidUserDataException();
            }

            try
            {
                IDictionary <string, string> claims = new Dictionary <string, string>
                {
                    ["name"]            = command.Nome,
                    ["email"]           = command.Email,
                    ["address"]         = command.Address,
                    ["address_details"] = command.AdditionalAddress,
                    ["phone"]           = command.Phone,
                    ["district"]        = command.District,
                    ["city"]            = command.City,
                    ["state"]           = command.State,
                    ["zip_code"]        = command.ZipCode
                };

                await _claimsManager.AddUpdateClaim(command.UserId, claims);

                return(true);
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                throw;
            }
        }