Ejemplo n.º 1
0
        protected void GuardarContacto_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Contacto nuevoContacto = new Contacto()
                {
                    NombreApellido = NombreApellidoContacto.Text,
                    Genero         = ComboGenero.SelectedValue,
                    Pais           = new Pais()
                    {
                        id = Convert.ToInt32(Paises.SelectedValue)
                    },
                    Localidad        = Localidad.Text,
                    Contacto_interno = new SiNo()
                    {
                        id = Convert.ToInt32(ContactoInternoList.SelectedValue)
                    },
                    Organizacion = OrganizacionBox.Text,
                    Area         = new Area()
                    {
                        id = Convert.ToInt32(AreaList.SelectedValue)
                    },
                    Fecha_ingreso = DateTime.Now,
                    Activo        = new SiNo()
                    {
                        id = Convert.ToInt32(ActivoList.SelectedValue)
                    },
                    Direccion        = DireccionContacto.Text,
                    Telefono_fijo    = Int64.Parse(TelFijoContacto.Text),
                    Telefono_celular = Int64.Parse(CelContacto.Text),
                    Email            = MailContacto.Text,
                    Skype            = CuentaSkype.Text
                };

                ContactoBLL contactoBLL = new ContactoBLL();
                string      accion      = (string)Application["accion"];

                if (accion == "editar")
                {
                    //le agrego el id a contacto
                    nuevoContacto.id = Convert.ToInt32(AgregarContacto.Attributes["id"]);
                    contactoBLL.Update(nuevoContacto);

                    redireccion();
                }
                else
                {
                    ServicioContacto servicioContacto = new ServicioContacto();
                    try
                    {
                        string cuil = servicioContacto.ObtenerCuil(nuevoContacto.NombreApellido, nuevoContacto.Genero);

                        nuevoContacto.Cuil = cuil;

                        contactoBLL.Insert(nuevoContacto);

                        redireccion();
                    } catch (Exception ex)
                    {
                        // mostrar mensaje de error en front end de no existe contacto
                    }
                }
            }
        }