Пример #1
1
        //adds a new country to the database if it is not already in it
        public static void createLand(string land)
        {
            using (DBEntities dbConnection = new DBEntities())
            {
                List<Land> foundLand = dbConnection.Land.Where(x => x.landName.Equals(land)).ToList();
                if (foundLand.Count > 0)
                {

                }
                else
                {
                    Land newLand = new Land();
                    newLand.landName = land;
                    dbConnection.Land.Add(newLand);
                    dbConnection.SaveChanges();
                }
            }
        }
Пример #2
0
        //creates a new city in the database if it is not already in it
        public static void createStadt(string stadt, int plz, string land)
        {
            using (DBEntities dbConnection = new DBEntities())
            {
                List<Land> foundLand = dbConnection.Land.Where(x => x.landName.Equals(land)).ToList();
                int landID;
                Land newLand = new Land();

                if (foundLand.Count > 0)
                {
                    landID = foundLand.First().landID;
                }
                else
                {
                    newLand.landName = land;
                    dbConnection.Land.Add(newLand);
                    dbConnection.SaveChanges();
                    landID = newLand.landID;
                }

                List<Stadt> foundStadt = dbConnection.Stadt.Where(x => x.stadtName.Equals(stadt)).ToList();
                Stadt newStadt = new Stadt();

                if (foundStadt.Count > 0)
                {
                }
                else
                {
                    newStadt.stadtName = stadt;
                    newStadt.stadtPLZ = plz;
                    newStadt.landID = landID;
                    dbConnection.Stadt.Add(newStadt);
                    dbConnection.SaveChanges();
                }
            }
        }