Пример #1
0
        public async Task DeleteAsync(int id)
        {
            this._logger.LogDebug("Starting DeleteAsync");

            this._logger.LogDebug("Retriving the endereco wants to delete");

            var endereco = await GetAsync(id);

            var temEndereco = await _sqlService.ExistsAsync(EnderecosFunQuery.EXIST_ENDERECO_ID, new { ID = endereco.EnderecoFunId });

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

                this._validationService.Throw("Endereco", "There is already another endereco with that Id", endereco.FuncionarioId, Validation.EnderecoNotExists);
            }


            this._logger.LogDebug("Deleting endereco");

            await _sqlService.ExecuteAsync(EnderecosFunQuery.DELETE, new
            {
                Id = endereco.EnderecoFunId
            });

            this._logger.LogDebug("Ending DeleteAsync");
        }
Пример #2
0
        public async Task DeleteAsync(int id)
        {
            this._logger.LogDebug("Starting DeleteAsync");

            this._logger.LogDebug("Retriving the product wants to delete");

            var funcionarioServico = await GetAsync(id);

            var temFuncionarioServico = await _sqlService.ExistsAsync(ServicoFuncionarioQuery.EXIST_SERVICO_ID, new { Id = funcionarioServico.ServicoFuncionarioId });

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

                this._validationService.Throw("Funcionario", "There is already another funcionario in servico with that Id", funcionarioServico.ServicoFuncionarioId, Validation.FuncionarioNotExists);
            }

            this._logger.LogDebug("Deleting funcionario in servico");

            await _sqlService.ExecuteAsync(ServicoFuncionarioQuery.DELETE, new
            {
                Id = funcionarioServico.ServicoFuncionarioId
            });

            this._logger.LogDebug("Ending DeleteAsync");
        }
Пример #3
0
        public async Task DeleteAsync(int id)
        {
            this._logger.LogDebug("Starting DeleteAsync");

            this._logger.LogDebug("Retriving the Veiculo wants to delete");

            var veiculo = await GetAsync(id);

            var temVeiculo = await _sqlService.ExistsAsync(VeiculoQuery.EXIST_VEICULO_ID, new { Id = veiculo.VeiculoId });

            if (!temVeiculo)
            {
                this._logger.LogDebug("Veiculo already exists, triggering 400");

                this._validationService.Throw("Veiculo", "There is already another Veiculo with that Id", veiculo.ClienteId, Validation.ClienteNotExists);
            }


            this._logger.LogDebug("Deleting product");

            await _sqlService.ExecuteAsync(VeiculoQuery.DELETE, new
            {
                Id = veiculo.VeiculoId
            });

            this._logger.LogDebug("Ending DeleteAsync");
        }
Пример #4
0
        public async Task DeleteAsync(int id)
        {
            this._logger.LogDebug("Starting DeleteAsync");

            this._logger.LogDebug("Retriving the servico wants to delete");

            var servico = await GetAsync(id);

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

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

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

            this._logger.LogDebug("Deleting Servico");

            await _sqlService.ExecuteAsync(ServicosQuery.DELETE, new
            {
                ID = id
            });

            this._logger.LogDebug("Ending DeleteAsync");
        }
Пример #5
0
        public async Task DeleteAsync(int id)
        {
            this._logger.LogDebug("Starting DeleteAsync");

            this._logger.LogDebug("Retriving the product wants to delete");

            var cliente = await GetAsync(id);

            var temCliente = await _sqlService.ExistsAsync(ClienteQuery.EXIST_CLIENTE_ID, new { Id = cliente.ClienteId });

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

                this._validationService.Throw("Cliente", "There is already another cliente with that Id", (object)cliente.ClienteId, Validation.ClienteNotExists);
            }


            this._logger.LogDebug("Deleting product");

            await _sqlService.ExecuteAsync(ClienteQuery.DELETE, new
            {
                Id = cliente.ClienteId
            });

            this._logger.LogDebug("Ending DeleteAsync");
        }
Пример #6
0
        public async Task DeleteAsync(int codProduct)
        {
            this._logger.LogDebug("Starting DeleteAsync");

            this._logger.LogDebug("Retriving the product wants to delete");

            var product = await GetAsync(codProduct);

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

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

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

            this._logger.LogDebug("Deleting product");

            await _sqlService.ExecuteAsync(ProductQuery.DELETE, new
            {
                CodProduct = codProduct
            });

            this._logger.LogDebug("Ending DeleteAsync");
        }
Пример #7
0
        public async Task <ContatoCliente> UpdateAsync(int id, ContatoCliente contatoCliente)
        {
            this._logger.LogDebug("Starting UpdateAsync");

            var oldContato = await GetAsync(id);

            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.Telefone
            });

            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);
            }

            var existContato = await _sqlService.ExistsAsync(ContatoClienteQuery.EXIST_CONTATOCLIENTE_ID, new
            {
                Id = oldContato.ContatoCliId
            });

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

            if (!existContato)
            {
                this._logger.LogDebug("Contato already exists, triggering 400");

                this._validationService.Throw("Contato", "There is already another user with that id", contatoCliente.ContatoCliId, Validation.ContatoNotExists);
            }

            this._logger.LogDebug("Updating contato");

            await _sqlService.ExecuteAsync(ContatoClienteQuery.UPDATE, new
            {
                Id        = id,
                CLIENTEID = contatoCliente.ClienteId,
                EMAIL     = contatoCliente.Email,
                TELEFONE  = contatoCliente.Telefone
            });

            contatoCliente.ContatoCliId = oldContato.ContatoCliId;

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

            return(contatoCliente);
        }
Пример #8
0
        public async Task <User> UpdateAsync(int id, User user)
        {
            this._logger.LogDebug("Starting UpdateAsync");

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

            await _userValidator.ValidateAndThrowAsync(user);

            this._logger.LogDebug("Retriving the user the user wants to update");

            var oldUser = await GetAsync(id);

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

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

            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.UserRepeatedDocument);
            }

            this._logger.LogDebug("Updating user");

            await _sqlService.ExecuteAsync(UserQuery.UPDATE, new
            {
                Id        = oldUser.Id,
                IdProfile = user.Profile,
                IdCountry = user.Country,
                Name      = user.Name,
                Email     = user.Email,
                Birthdate = user.Birthdate,
                Active    = user.Active
            });

            user.Id = oldUser.Id;

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

            return(user);
        }
Пример #9
0
        public async Task UpdateAsync(int id, User user)
        {
            _logger.LogDebug($"User {_authenticatedService.GetUserKey()} is updating User {id} - {user}");

            await _sqlService.ExecuteAsync(UserQuery.UPDATE, CommandType.Text, new
            {
                id        = id,
                name      = user.Name,
                email     = user.Email,
                password  = user.Password,
                active    = user.Active,
                confirmed = user.Confirmed,
                created   = user.Created,
                createdby = user.CreatedBy,
                updated   = user.Updated,
                updatedby = user.UpdatedBy
            });

            _logger.LogDebug($"User {id} updated");
        }