Beispiel #1
0
        public async Task <ServicoFuncionario> CreateAsync(ServicoFuncionario funcionario)
        {
            this._logger.LogDebug("Starting CreateAsync");

            var existFuncionarioServico = await _sqlService.ExistsAsync(ServicoFuncionarioQuery.EXIST_SERVICO_FUNCIONARIOID, new
            {
                Id = funcionario.FuncionarioId
            });

            if (existFuncionarioServico)
            {
                this._logger.LogDebug("Funcionario already exists in servico, triggering 400");

                this._validationService.Throw("Funcionario", "There is already another funcionario in servico with that id", funcionario.FuncionarioId, Validation.FuncionarioExists);
            }

            this._logger.LogDebug("Inserting new Funcionario");

            funcionario.FuncionarioId = await _sqlService.CreateAsync(ServicoFuncionarioQuery.INSERT, new
            {
                FUNCIONARIOID = funcionario.FuncionarioId,
                SERVICOID     = funcionario.ServicoId,
                COMISSAO      = funcionario.Comissao
            });

            this._logger.LogDebug("Ending CreateAsync");

            return(funcionario);
        }
Beispiel #2
0
        public async Task <Servico> CreateAsync(Servico servico)
        {
            this._logger.LogDebug("Starting CreateAsync");

            var existsProduct = await _sqlService.ExistsAsync(ServicosQuery.EXIST_SERVICO_ID, new
            {
                Id = servico.ServicoId
            });

            if (existsProduct)
            {
                this._logger.LogDebug("Servico already exists, triggering 400");

                this._validationService.Throw("Servico", "There is already another servico with that Id", servico.ServicoId, Validation.UserRepeatedDocument);
            }

            this._logger.LogDebug("Inserting new servico");

            servico.ServicoId = await _sqlService.CreateAsync(ServicosQuery.INSERT, new
            {
                VEICULOID     = servico.VeiculoId,
                DATAINICIO    = servico.DataInicio,
                DATAFIM       = servico.DataFim,
                QUILOMETRAGEM = servico.Quilometragem,
                PRECOTOTAL    = servico.PrecoTotal
            });

            this._logger.LogDebug("Ending CreateAsync");

            return(servico);
        }
Beispiel #3
0
        public async Task <EnderecoFuncionario> CreateAsync(EnderecoFuncionario enderecosCliente)
        {
            this._logger.LogDebug("Starting CreateAsync");

            var existCep = await _sqlService.ExistsAsync(EnderecosFunQuery.EXIST_ENDERECO_CEP, new
            {
                CEP           = enderecosCliente.CEP,
                FUNCIONARIOID = enderecosCliente.FuncionarioId
            });

            if (existCep)
            {
                this._logger.LogDebug("Endereco already exists, triggering 400");

                this._validationService.Throw("Endereco", "There is already another Endereco with that Cep", enderecosCliente.CEP, Validation.EnderecoExist);
            }

            this._logger.LogDebug("Inserting new Endereco");

            enderecosCliente.EnderecoFunId = await _sqlService.CreateAsync(EnderecosFunQuery.INSERT, new
            {
                FUNCIONARIOID = enderecosCliente.FuncionarioId,
                LOGRADOURO    = enderecosCliente.Logradouro,
                BAIRRO        = enderecosCliente.Bairro,
                CIDADE        = enderecosCliente.Cidade,
                UF            = enderecosCliente.Uf,
                CEP           = enderecosCliente.CEP
            });

            this._logger.LogDebug("Ending CreateAsync");

            return(enderecosCliente);
        }
Beispiel #4
0
        public async Task <ContatoCliente> CreateAsync(ContatoCliente contatoCliente)
        {
            this._logger.LogDebug("Starting CreateAsync");

            var existContatoEmail = await _sqlService.ExistsAsync(ContatoClienteQuery.EXIST_CONTATOCLIENTE_EMAIL, new
            {
                EMAIL = contatoCliente.Email
            });

            var existContatoTelefone = await _sqlService.ExistsAsync(ContatoClienteQuery.EXIST_CONTATOCLIENTE_TELEFONE, new
            {
                TELEFONE = contatoCliente.Email
            });

            if (existContatoEmail && existContatoTelefone)
            {
                this._logger.LogDebug("Contato already exists, triggering 400");

                this._validationService.Throw("Contato", "There is already another funcionario with that Email or Telefone", contatoCliente, Validation.ContatoExists);
            }

            this._logger.LogDebug("Inserting new Contato");

            contatoCliente.ContatoCliId = await _sqlService.CreateAsync(ContatoClienteQuery.INSERT, new
            {
                CLIENTEID = contatoCliente.ClienteId,
                EMAIL     = contatoCliente.Email,
                TELEFONE  = contatoCliente.Telefone
            });

            this._logger.LogDebug("Ending CreateAsync");

            return(contatoCliente);
        }
        public async Task <Veiculo> CreateAsync(Veiculo veiculo)
        {
            this._logger.LogDebug("Starting CreateAsync");

            var existVeiculo = await _sqlService.ExistsAsync(VeiculoQuery.EXIST_VEICULO_DO_CLIENTE, new
            {
                Placa     = veiculo.Placa,
                ClienteId = veiculo.ClienteId
            });

            if (existVeiculo)
            {
                this._logger.LogDebug("veiculo already exists, triggering 400");

                this._validationService.Throw("veiculo", "There is already another veiculo with that placa", veiculo.Placa, Validation.FuncionarioExists);
            }

            this._logger.LogDebug("Inserting new veiculo");

            veiculo.VeiculoId = await _sqlService.CreateAsync(VeiculoQuery.INSERT, new
            {
                CLIENTEID = veiculo.ClienteId,
                MODELO    = veiculo.Modelo,
                MARCA     = veiculo.Marca,
                ANO       = veiculo.Ano,
                PLACA     = veiculo.Placa,
                COR       = veiculo.Cor
            });

            this._logger.LogDebug("Ending CreateAsync");

            return(veiculo);
        }
        public async Task <Cliente> CreateAsync(Cliente cliente)
        {
            this._logger.LogDebug("Starting CreateAsync");

            var existCliente = await _sqlService.ExistsAsync(ClienteQuery.EXIST_CLIENTE, new
            {
                Cpf = cliente.Documento
            });

            if (existCliente)
            {
                this._logger.LogDebug("Cliente already exists, triggering 400");

                this._validationService.Throw("Cliente", "There is already another cliente with that Cpf", cliente.Documento, Validation.ClienteExists);
            }

            this._logger.LogDebug("Inserting new Funcionario");

            cliente.ClienteId = await _sqlService.CreateAsync(ClienteQuery.INSERT, new
            {
                Nome           = cliente.Nome,
                Documento      = cliente.Documento,
                DataNascimento = cliente.DataNascimento,
                Ativo          = cliente.Ativo
            });

            this._logger.LogDebug("Ending CreateAsync");

            return(cliente);
        }
        public async Task <ServicoProduto> CreateAsync(ServicoProduto produto)
        {
            this._logger.LogDebug("Starting CreateAsync");

            var existProdutoServico = await _sqlService.ExistsAsync(ServicoProdutoQuery.EXIST_SERVICO_PRODUTOID, new
            {
                Id = produto.ProdutoId
            });

            if (existProdutoServico)
            {
                this._logger.LogDebug("Produto already exists in servico, triggering 400");

                this._validationService.Throw("Produto", "There is already another Produto in servico with that Id", produto.ProdutoId, Validation.ProductExists);
            }

            this._logger.LogDebug("Inserting new produto in servico");

            produto.ProdutoId = await _sqlService.CreateAsync(ServicoProdutoQuery.INSERT, new
            {
                SERVICOID  = produto.ServicoId,
                PRODUTOID  = produto.ProdutoId,
                QUANTIDADE = produto.Quantidade
            });

            this._logger.LogDebug("Ending CreateAsync");

            return(produto);
        }
Beispiel #8
0
        public async Task <Funcionario> CreateAsync(Funcionario funcionario)
        {
            this._logger.LogDebug("Starting CreateAsync");

            var existFuncionario = await _sqlService.ExistsAsync(FuncionarioQuery.EXIST_FUNCIONARIO, new
            {
                Cpf = funcionario.Documento
            });

            if (existFuncionario)
            {
                this._logger.LogDebug("Funcionario already exists, triggering 400");

                this._validationService.Throw("Funcionario", "There is already another funcionario with that Cpf", funcionario.Documento, Validation.FuncionarioExists);
            }

            this._logger.LogDebug("Inserting new Funcionario");

            funcionario.FuncionarioId = await _sqlService.CreateAsync(FuncionarioQuery.INSERT, new
            {
                FUNCIONARIOID = funcionario.FuncionarioId,
                NOME          = funcionario.Nome,
                DOCUMENTO     = funcionario.Documento,
                SALARIO       = funcionario.Salario,
                ATIVO         = funcionario.Ativo
            });

            this._logger.LogDebug("Ending CreateAsync");

            return(funcionario);
        }
        public async Task <Product> CreateAsync(Product product)
        {
            this._logger.LogDebug("Starting CreateAsync");

            var existsProduct = await _sqlService.ExistsAsync(ProductQuery.EXIST_PRODUCT, new
            {
                CodProduct = product.Codigo
            });

            if (existsProduct)
            {
                this._logger.LogDebug("Product already exists, triggering 400");

                this._validationService.Throw("Product", "There is already another product with that CodProduct", product.Codigo, Validation.UserRepeatedDocument);
            }

            this._logger.LogDebug("Inserting new Product");

            product.ProdutoId = await _sqlService.CreateAsync(ProductQuery.INSERT, new
            {
                IdProduct   = product.ProdutoId,
                CodProduct  = product.Codigo,
                ProductName = product.Nome,
                Descricao   = product.Descricao,
                Quant       = product.Quantidade,
                Value       = product.Valor,
                ProdType    = product.Tipo,
                Active      = product.Ativo
            });

            this._logger.LogDebug("Ending CreateAsync");

            return(product);
        }
Beispiel #10
0
        public async Task <User> CreateAsync(User user)
        {
            this._logger.LogDebug("Starting CreateAsync");

            this._logger.LogDebug("Validating payload");

            await _userValidator.ValidateAndThrowAsync(user);

            this._logger.LogDebug("Checking if that document already exists");

            var existsDocument = await _sqlService.ExistsAsync(UserQuery.EXISTS_DOCUMENT, new
            {
                Document = user.Document
            });

            if (existsDocument)
            {
                this._logger.LogDebug("Document already exists, triggering 400");

                this._validationService.Throw("Document", "There is already another user with that document", user.Document, Validation.UserRepeatedDocument);
            }

            this._logger.LogDebug("Checking if that email already exists");

            var existsEmail = await _sqlService.ExistsAsync(UserQuery.EXISTS_EMAIL, new
            {
                Email = user.Email
            });

            if (existsEmail)
            {
                this._logger.LogDebug("Email already exists, triggering 400");

                this._validationService.Throw("Email", "There is already another user with that email", user.Email, Validation.UserRepeatedEmail);
            }

            this._logger.LogDebug("Inserting new user");

            user.Id = await _sqlService.CreateAsync(UserQuery.INSERT, new
            {
                IdProfile = user.Profile,
                IdCountry = user.Country,
                CreatedBy = _authenticatedService.Token().Subject,
                Name      = user.Name,
                Email     = user.Email,
                Document  = user.Document,
                Birthdate = user.Birthdate,
                Active    = user.Active
            });

            this._logger.LogDebug("Ending CreateAsync");

            return(user);
        }