コード例 #1
0
        public Boolean Guardar(clsEmpresaServicio EmpresaServiciocls)
        {
            try
            {
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {
                    EmpSer = new EmpresaServicio()
                    {
                        IdEmpresaServicio = EmpresaServiciocls._IdEmpresaServicio,
                        IdTipoPersona = EmpresaServiciocls._TipoPersona,
                        FechaRegistro = DateTime.Today,
                        RazonSocial = EmpresaServiciocls._RazonSocial,
                        Estado = EmpresaServiciocls._Estado,
                        Direccion = EmpresaServiciocls._Direccion,
                        Email = EmpresaServiciocls._Email,
                        Webpage = EmpresaServiciocls._Website,
                        IdEmpresa = 1,
                        IdUsuario = 11,
                    };
                    ent.AddToEmpresaServicio(EmpSer);
                    ent.SaveChanges();

                    aux = EmpresaServiciocls._DetalleTelefono.Count();
                    for (int i = 0; i <= aux; i++)//Guardando los teléfonos, tanto en la tabla Telefono como en TelefonoEmpresaServicio
                    {
                        valTel = getIdSiguienteTelefono();
                        Tel = new Telefono()
                        {
                            IdTelefono = valTel,
                            IdTipoTelefono = EmpresaServiciocls._DetalleTelefono[i].getTipoTelefono(),
                            Numero = EmpresaServiciocls._DetalleTelefono[i].getNumTelefono(),
                        };
                        ent.AddToTelefono(Tel);
                        ent.SaveChanges();

                        TelEmpServ = new TelefonoEmpresaServicio()
                        {
                            IdEmpresa = EmpresaServiciocls._IdEmpresa,
                            IdEmpresaServicio = EmpresaServiciocls._IdEmpresaServicio,
                            IdTelefono = valTel,
                        };
                        ent.AddToTelefonoEmpresaServicio(TelEmpServ);
                        ent.SaveChanges();
                    }
                    //=============================================================================
                    aux = EmpresaServiciocls._CuentaBancaria.Count();
                    for (int i = 0; i <= aux; i++)//Guardando las cuentas bancarias
                    {
                        CtaBanc = new CuentaBancaria2()
                        {
                            IdEmpresaServicio = EmpresaServiciocls._IdEmpresaServicio,
                            IdEmpresa = EmpresaServiciocls._IdEmpresa,
                            Serie = getIdSiguienteCtaBanc(),
                            IdBanco = EmpresaServiciocls._CuentaBancaria[i].getIdBanco(),
                            TipoCuenta = EmpresaServiciocls._CuentaBancaria[i].getTipoCuenta(),
                            NroCta = EmpresaServiciocls._CuentaBancaria[i].getNroCuenta(),
                        };
                        ent.AddToCuentaBancaria2(CtaBanc);
                        ent.SaveChanges();
                    }
                }

                return true;

            }
            catch (Exception)
            {
                return false;
            }
        }