Пример #1
0
        /// <summary>
        /// On va insérer les données relatives aux départements
        /// </summary>
        /// <param name="dpt">Le département</param>
        public static void insertionDonneesDepartement(Departement dpt)
        {
            using (var context = new election_municipaleEntities())
            {
                context.Configuration.LazyLoadingEnabled = false;
                short query;
                try
                {
                    query = (from dept in context.Departement
                             where dept.code_du_departement == dpt.code_du_departement
                             select dept.code_du_departement).Single();
                }


                catch (InvalidOperationException e)
                {
                    Console.WriteLine("query catch exception");
                    if (dpt.code_du_departement != 0)
                    {
                        context.Departement.Add(dpt);
                        try
                        {
                            Console.WriteLine(dpt.code_du_departement);
                            context.SaveChanges();
                        }
                        catch (System.Data.Entity.Validation.DbEntityValidationException a)
                        {
                            foreach (var eve in a.EntityValidationErrors)
                            {
                                Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                  eve.Entry.Entity.GetType().Name, eve.Entry.State);
                                foreach (var ve in eve.ValidationErrors)
                                {
                                    Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                      ve.PropertyName, ve.ErrorMessage);
                                }
                            }
                            throw;
                        }
                    }


                    //foreach (var departement in context.Departement)
                    //{
                    //	Console.WriteLine(departement.code_du_departement);
                    //}
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Insertion Données de la commune
        /// </summary>
        /// <param name="com"></param>
        public static void insertionDonneesCommune(Commune com, Departement dept)
        {
            using (var context = new election_municipaleEntities())
            {
                context.Configuration.LazyLoadingEnabled = false;
                string query;

                try
                {
                    query = (from comm in context.Commune
                             where comm.insee == com.insee
                             select com.insee).Single();
                }
                catch (InvalidOperationException e)
                {
                    context.Commune.Add(com);

                    //try
                    //{
                    //	context.SaveChanges();
                    //}

                    //catch (System.Data.Entity.Validation.DbEntityValidationException a)
                    //{
                    //	foreach (var eve in a.EntityValidationErrors)
                    //	{
                    //		Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                    //			eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    //		foreach (var ve in eve.ValidationErrors)
                    //		{
                    //			Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                    //				ve.PropertyName, ve.ErrorMessage);
                    //		}
                    //	}
                    //	throw;
                    //}
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Permet de réinitialiser un objet Département à null
 /// </summary>
 /// <param name="dept">Département</param>
 /// <returns></returns>
 public static Departement reinitialisationDepartement(Departement dept)
 {
     dept = null;
     return(dept);
 }