Exemplo n.º 1
0
        //Método Update
        public Contacto2 Update(Contacto2 context)
        {
            using (Ejercicio01Context contexto = new Ejercicio01Context())
            {
                Direccion direccion = new Direccion();
                Contacto  contacto  = new Contacto();

                try
                {
                    direccion.Calle     = context.Calle;
                    direccion.Ciudad    = context.Ciudad;
                    direccion.Entidad   = context.Entidad;
                    direccion.Colonia   = context.Colonia;
                    direccion.NumeroExt = context.NumeroExt;
                    direccion.Cp        = context.Cp;
                    direccion.Id        = context.DireccionId;

                    contacto.Nombre      = context.Nombre;
                    contacto.Telefono    = context.Telefono;
                    contacto.Id          = context.Id;
                    contacto.DireccionId = context.DireccionId;
                    contacto.Estado      = context.Estado;

                    contexto.Entry(contacto).State = EntityState.Modified;
                    contexto.SaveChanges();
                    contexto.Entry(direccion).State = EntityState.Modified;
                    contexto.SaveChanges();
                    return(context);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 2
0
        public int Delete(Contacto2 modelo)
        {
            using (Ejercicio01Context contexto = new Ejercicio01Context())
            {
                int    direccion = modelo.DireccionId;
                int    contacto  = modelo.Id;
                string estado    = modelo.Estado;
                int    a         = 0;
                var    comprobar = modelo.Estado;
                try
                {
                    if (comprobar == "")
                    {
                        estado = null;
                    }

                    Contacto  remove1 = contexto.Contactos.Find(contacto);
                    Direccion remove2 = contexto.Direccions.Find(direccion);
                    if (estado != null)
                    {
                        contexto.Entry(remove1).State = EntityState.Deleted;
                        contexto.Entry(remove2).State = EntityState.Deleted;
                        contexto.SaveChanges();
                        return(a = 1);
                    }
                    else
                    {
                        return(a = 0);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }