Example #1
0
        public async Task <QueryResModel <CliForDTO> > UpdateAsync(CliForModel data)
        {
            QueryResModel <CliForDTO> queryResult = new QueryResModel <CliForDTO>();

            int changes = -1;

            if (await DbContext.Clifor.AnyAsync(cf => cf.Id == data.Id).ConfigureAwait(false))
            {
                DbContext.Clifor.Update(data);
                changes = await DbContext
                          .SaveChangesAsync()
                          .ConfigureAwait(false);
            }

            if (changes <= 0)
            {
                queryResult.Succeeded = false;
                queryResult.Error     = changes == -1 ? "Error: CliFor not found" : "Error: Update failed.";
                return(queryResult);
            }
            else
            {
                CliForModel cliFor = await DbContext.Clifor
                                     .Where(cf => cf.Id == data.Id)
                                     .AsNoTracking()
                                     .FirstAsync()
                                     .ConfigureAwait(false);

                queryResult.Data = Mapper.Map <CliForModel, CliForDTO>(cliFor);

                return(queryResult);
            }
        }
Example #2
0
        public async Task <IActionResult> UpdateCliForAsync([FromBody] CliForModel cliFor)
        {
            QueryResModel <CliForDTO> qrm = await InvService.UpdateAsync(cliFor).ConfigureAwait(false);

            if (qrm.Succeeded)
            {
                return(Ok(qrm.Data));
            }
            else
            {
                return(BadRequest(qrm.Error));
            }
        }
Example #3
0
 public bool SameIdIvaOrFiscale(CliForModel clifor1, CliForModel clifor2)
 {
     if (((clifor1.IdPaese != null && clifor2.IdPaese != null) &&
          (clifor1.IdCodice != null & clifor2.IdCodice != null) &&
          clifor1.IdPaese == clifor2.IdPaese &&
          clifor1.IdCodice == clifor2.IdCodice) ||
         (clifor1.CodiceFiscale != null && clifor2.CodiceFiscale != null &&
          clifor1.CodiceFiscale == clifor2.CodiceFiscale))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #4
0
        public bool EitherIsOwner(CliForModel cliFor1, CliForModel cliFor2 = null)
        {
            if (InvoicesOptions.Owner.IdPaese == cliFor1.IdPaese &&
                InvoicesOptions.Owner.IdCodice == cliFor1.IdCodice)
            {
                return(true);
            }
            else if (cliFor2 != null &&
                     InvoicesOptions.Owner.IdPaese == cliFor2.IdPaese &&
                     InvoicesOptions.Owner.IdCodice == cliFor2.IdCodice)
            {
                return(true);
            }

            return(false);
        }
Example #5
0
        private void tsSalvar_Click(object sender, EventArgs e)
        {
            CliFor   cli  = new CliFor();
            Endereco end  = new Endereco();
            Email    mail = new Email();
            Telefone tel  = new Telefone();



            //cliente/fornecedor
            cli.Razao    = txtRazao.Text;
            cli.Fantasia = txtFantasia.Text;
            cli.Ie       = txtInscEstadual.Text;
            cli.Im       = txtInscMunicipal.Text;

            //endereço
            end.Cep        = txtCep.Text;
            end.Logradouro = txtLogradouro.Text;
            end.Cidade     = txtMunicipio.Text;
            end.Bairro     = txtBairro.Text;
            end.Uf         = txtUF.Text;
            end.Numero     = txtNumero.Text;

            //telefone
            tel.Fixo    = txtTel.Text;
            tel.Celular = txtCel.Text;

            //email
            mail.Mail = txtEmail.Text;


            try
            {
                CliForModel forn     = new CliForModel();
                string      mensagem = forn.salvar(cli, end, mail, tel);
                if (mensagem != "")
                {
                    MessageBox.Show(mensagem);
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex);
            }
        }
Example #6
0
        private void AlteraCliFor_Load(object sender, EventArgs e)
        {
            CliForModel um = new CliForModel();

            List <string> lista = um.Dados(cod);

            txtIdentificacao.Text = lista[0].ToString();
            txtRazao.Text         = lista[1].ToString();
            txtFantasia.Text      = lista[2].ToString();
            txtEmail.Text         = lista[3].ToString();
            txtCep.Text           = lista[4].ToString();
            txtNumero.Text        = lista[6].ToString();
            txtLogradouro.Text    = lista[5].ToString();
            txtBairro.Text        = lista[7].ToString();
            txtMunicipio.Text     = lista[9].ToString();
            txtUF.Text            = lista[8].ToString();
            txtTel.Text           = lista[10].ToString();
            txtCel.Text           = lista[11].ToString();
        }
Example #7
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            CliFor imb = new CliFor();

            imb.Id = Convert.ToInt32(cod);

            try
            {
                CliForModel login    = new CliForModel();
                string      mensagem = login.deletar(imb);
                if (mensagem != "")
                {
                    MessageBox.Show(mensagem);
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex);
            }
        }
Example #8
0
        private void tsSalvar_Click(object sender, EventArgs e)
        {
            CliFor   clfr = new CliFor();
            Endereco end  = new Endereco();
            Email    mail = new Email();
            Telefone tel  = new Telefone();

            //usuario
            clfr.Id       = Convert.ToInt32(cod);
            clfr.Fantasia = txtFantasia.Text;

            //endereço
            end.Cep        = txtCep.Text;
            end.Logradouro = txtLogradouro.Text;
            end.Cidade     = txtMunicipio.Text;
            end.Bairro     = txtBairro.Text;

            //telefone
            tel.Fixo    = txtTel.Text;
            tel.Celular = txtCel.Text;

            //email
            mail.Mail = txtEmail.Text;

            try
            {
                CliForModel login    = new CliForModel();
                string      mensagem = login.alterar(clfr, end, mail, tel);
                if (mensagem != "")
                {
                    MessageBox.Show(mensagem);
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex);
            }
        }
Example #9
0
        private void tsSalvar_Click(object sender, EventArgs e)
        {
            var      cli  = new CliFor();
            Endereco end  = new Endereco();
            Email    mail = new Email();
            Telefone tel  = new Telefone();

            //usuario
            cli.Id = Convert.ToInt32(cod);
            if (maskCpf.Visible == false)
            {
                cli.Identificacao = maskCnpj.Text;
            }
            else
            {
                cli.Identificacao = maskCpf.Text;
            }
            if (cbCliente.Checked == true && cbFornecedor.Checked == true)
            {
                cli.Tipo = "Cliente/Fornecedor";
            }
            else if (cbCliente.Checked == true && cbFornecedor.Checked == false)
            {
                cli.Tipo = "Cliente";
            }
            else if (cbCliente.Checked == false && cbFornecedor.Checked == true)
            {
                cli.Tipo = "Fornecedor";
            }
            //imobiliaria
            if (txtRazao.Enabled)
            {
                cli.Razao = txtRazao.Text;
            }
            else
            {
                cli.Razao = "";
            }
            cli.Fantasia = txtFantasia.Text;


            //endereço
            end.Cep        = txtCep.Text;
            end.Logradouro = txtLogradouro.Text;
            end.Cidade     = txtMunicipio.Text;
            end.Bairro     = txtBairro.Text;
            end.Uf         = cbUF.Text;
            end.Numero     = txtNumero.Text;

            //telefone
            tel.Fixo    = txtTel.Text;
            tel.Celular = txtCel.Text;

            //email
            mail.Mail = txtEmail.Text;

            try
            {
                var    login    = new CliForModel();
                string mensagem = login.alterar(cli, end, mail, tel);
                MessageBox.Show(mensagem);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex);
            }
        }
Example #10
0
        public async Task <int?> AddCliForAsync(CliForModel cliFor)
        {
            if (cliFor.CodiceFiscale == null && (cliFor.IdPaese == null || cliFor.IdCodice == null))
            {
                return(null);
            }

            if (cliFor.RappresentanteFiscale != null)
            {
                cliFor.RappresentanteFiscaleId = await this
                                                 .AddCliForAsync(cliFor.RappresentanteFiscale)
                                                 .ConfigureAwait(false);

                cliFor.RappresentanteFiscale = null;
            }

            if (cliFor.IdPaese != null && cliFor.IdCodice != null)
            {
                if (await DbContext.Clifor
                    .AnyAsync(cf => cf.IdPaese == cliFor.IdPaese && cf.IdCodice == cliFor.IdCodice)
                    .ConfigureAwait(false)
                    )
                {
                    var retrievedCliFor = await DbContext.Clifor
                                          .Where(cf => cf.IdPaese == cliFor.IdPaese && cf.IdCodice == cliFor.IdCodice)
                                          .FirstOrDefaultAsync()
                                          .ConfigureAwait(false);

                    // Add NumeroLicenzaGuida to Clifor
                    if (retrievedCliFor.NumeroLicenzaGuida == null && cliFor.NumeroLicenzaGuida != null)
                    {
                        retrievedCliFor.NumeroLicenzaGuida = cliFor.NumeroLicenzaGuida;
                        DbContext.Clifor.Update(retrievedCliFor);
                    }

                    return(retrievedCliFor.Id);
                }
            }

            if (cliFor.CodiceFiscale != null)
            {
                if (await DbContext.Clifor
                    .AnyAsync(cf => cf.CodiceFiscale == cliFor.CodiceFiscale)
                    .ConfigureAwait(false)
                    )
                {
                    var retrievedCliFor = await DbContext.Clifor
                                          .Where(cf => cf.CodiceFiscale == cliFor.CodiceFiscale)
                                          .FirstOrDefaultAsync()
                                          .ConfigureAwait(false);

                    // Add NumeroLicenzaGuida to Clifor
                    if (retrievedCliFor.NumeroLicenzaGuida == null && cliFor.NumeroLicenzaGuida != null)
                    {
                        retrievedCliFor.NumeroLicenzaGuida = cliFor.NumeroLicenzaGuida;
                        DbContext.Clifor.Update(retrievedCliFor);
                    }

                    return(retrievedCliFor.Id);
                }
            }

            DbContext.Clifor.Add(cliFor);
            await DbContext
            .SaveChangesAsync()
            .ConfigureAwait(false);

            int id = cliFor.IdPaese != null & cliFor.IdCodice != null ?
                     await DbContext.Clifor
                     .Where(cf => cf.IdPaese == cliFor.IdPaese && cf.IdCodice == cliFor.IdCodice)
                     .Select(cf => cf.Id)
                     .FirstOrDefaultAsync()
                     .ConfigureAwait(false)
                    :
                     await DbContext.Clifor
                     .Where(cf => cf.CodiceFiscale == cliFor.CodiceFiscale)
                     .Select(cf => cf.Id)
                     .FirstOrDefaultAsync()
                     .ConfigureAwait(false);

            return(id);
        }
Example #11
0
        // @Clifor
        public async Task <QueryResModel <CliForDTO> > GetOneCliForAsync(int id)
        {
            QueryResModel <CliForDTO> queryResult = new QueryResModel <CliForDTO>();
            CliForModel cliFor = await DbContext.Clifor
                                 .Where(cf => cf.Id == id)
                                 .Include(cf => cf.Contatti)
                                 .Include(cf => cf.ContiBancari)
                                 .Include(cf => cf.Sedi)
                                 .AsNoTracking()
                                 .FirstOrDefaultAsync()
                                 .ConfigureAwait(false);

            if (cliFor.Id != 0)
            {
                cliFor.BodyModelCP = await DbContext.Bodies
                                     .Where(b => b.CedentePrestatoreId == cliFor.Id)
                                     .Include(b => b.Causale)
                                     .Include(b => b.DatiDDT)
                                     .ThenInclude(ddt => ddt.RiferimentoNumeroLinea)
                                     .Include(b => b.DatiPagamento)
                                     .ThenInclude(dp => dp.DettaglioPagamento)
                                     .Include(b => b.DatiRiepilogo)
                                     .Include(b => b.DettaglioLinee)
                                     .ThenInclude(dl => dl.CodiceArticolo)
                                     .Include(b => b.DettaglioLinee)
                                     .ThenInclude(dl => dl.ScontoMaggiorazione)
                                     .Include(b => b.DatiBeniServizi)
                                     .Include(b => b.CedentePrestatore)
                                     .ThenInclude(cp => cp.ContiBancari)
                                     .Include(b => b.CessionarioCommittente)
                                     .ThenInclude(cc => cc.ContiBancari)
                                     .OrderByDescending(b => b.Data)
                                     .Take(5)
                                     .ToListAsync();

                cliFor.BodyModelCC = await DbContext.Bodies
                                     .Where(b => b.CessionarioCommittenteId == cliFor.Id)
                                     .Include(b => b.Causale)
                                     .Include(b => b.DatiDDT)
                                     .ThenInclude(ddt => ddt.RiferimentoNumeroLinea)
                                     .Include(b => b.DatiPagamento)
                                     .ThenInclude(dp => dp.DettaglioPagamento)
                                     .Include(b => b.DatiRiepilogo)
                                     .Include(b => b.DettaglioLinee)
                                     .ThenInclude(dl => dl.CodiceArticolo)
                                     .Include(b => b.DettaglioLinee)
                                     .ThenInclude(dl => dl.ScontoMaggiorazione)
                                     .Include(b => b.DatiBeniServizi)
                                     .Include(b => b.CedentePrestatore)
                                     .ThenInclude(cp => cp.ContiBancari)
                                     .Include(b => b.CedentePrestatore)
                                     .ThenInclude(cp => cp.ContiBancari)
                                     .OrderByDescending(b => b.Data)
                                     .Take(5)
                                     .ToListAsync();

                foreach (var inv in cliFor.BodyModelCP)
                {
                    inv.CedentePrestatore = null;
                    inv.CessionarioCommittente.BodyModelCC = null;
                    inv.CessionarioCommittente.BodyModelCP = null;

                    if (inv.ImportoTotaleDocumento == null)
                    {
                        inv.ImportoTotaleDocumento = 0;
                        foreach (var pagamento in inv.DatiPagamento)
                        {
                            foreach (var dettaglio in pagamento.DettaglioPagamento)
                            {
                                inv.ImportoTotaleDocumento += dettaglio.ImportoPagamento;
                            }
                        }
                    }
                }

                foreach (var inv in cliFor.BodyModelCC)
                {
                    inv.CessionarioCommittente        = null;
                    inv.CedentePrestatore.BodyModelCC = null;
                    inv.CedentePrestatore.BodyModelCP = null;

                    if (inv.ImportoTotaleDocumento == null)
                    {
                        inv.ImportoTotaleDocumento = 0;
                        foreach (var pagamento in inv.DatiPagamento)
                        {
                            foreach (var dettaglio in pagamento.DettaglioPagamento)
                            {
                                inv.ImportoTotaleDocumento += dettaglio.ImportoPagamento;
                            }
                        }
                    }
                }

                queryResult.Data = Mapper.Map <CliForModel, CliForDTO>(cliFor);
            }
            else
            {
                queryResult.Data      = null;
                queryResult.Succeeded = false;
                queryResult.Error     = "Resource not found";
            }

            return(queryResult);
        }