public int InsertarPais(Pais pais)
 {
     using (EFDemoEntities context = new EFDemoEntities())
     {
         context.Pais.AddObject(pais);
         return context.SaveChanges();
     }
 }
 public int Modificar(Pais pais)
 {
     using (EFDemoEntities context = new EFDemoEntities())
     {
         context.Pais.ApplyChanges(pais);
         return context.SaveChanges();
     }
 }
Example #3
0
        public static string obtener()
        {
            List<Pais> lista = new List<Pais>();

            string conexionCadena = ConfigurationManager.ConnectionStrings["ConexionComplejo"].ConnectionString;
            SqlConnection con = new SqlConnection();

            string json = "";

            try
            {
                con.ConnectionString = conexionCadena;
                con.Open();
                string sql = "select id_pais, nombre from paises";
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = sql;
                cmd.Connection = con;
                SqlDataReader sda = cmd.ExecuteReader();

                while (sda.Read())
                {
                    Pais pais = new Pais();
                    pais.Id = (int)sda["id_pais"];
                    pais.Nombre = sda["nombre"].ToString();
                    lista.Add(pais);
                }

                JavaScriptSerializer serializer = new JavaScriptSerializer();

                json = serializer.Serialize(lista);

            }
            catch (SqlException ex)
            {
                throw new ApplicationException("" + ex.Message);

            }
            finally
            {
                con.Close();
            }

            return json;
        }
Example #4
0
     private void FixupPais(Pais previousValue)
     {
         if (IsDeserializing)
         {
             return;
         }
 
         if (previousValue != null && previousValue.Ciudad.Contains(this))
         {
             previousValue.Ciudad.Remove(this);
         }
 
         if (Pais != null)
         {
             if (!Pais.Ciudad.Contains(this))
             {
                 Pais.Ciudad.Add(this);
             }
 
             PaisId = Pais.Id;
         }
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("Pais")
                 && (ChangeTracker.OriginalValues["Pais"] == Pais))
             {
                 ChangeTracker.OriginalValues.Remove("Pais");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("Pais", previousValue);
             }
             if (Pais != null && !Pais.ChangeTracker.ChangeTrackingEnabled)
             {
                 Pais.StartTracking();
             }
         }
     }