Esempio n. 1
0
 public void AddDistrict(District district)
 {
     using (finalSQLEntities se = new finalSQLEntities())
     {
         se.Districts.Add(district);
         se.SaveChanges();
     };
 }
Esempio n. 2
0
 public void AddCity(City city)
 {
     using (finalSQLEntities se = new finalSQLEntities())
     {
         se.Cities.Add(city);
         se.SaveChanges();
     };
 }
Esempio n. 3
0
        public void DeleteDistrict(int id)
        {
            using (finalSQLEntities se = new finalSQLEntities())
            {
                se.Districts.Remove(se.Districts.First(_ => _.ID == id));

                se.SaveChanges();
            };
        }
Esempio n. 4
0
 public void DeleteCityAll()
 {
     using (finalSQLEntities se = new finalSQLEntities())
     {
         se.Database.ExecuteSqlCommand
             ($"delete from Cities ");
         se.SaveChanges();
     };
 }
Esempio n. 5
0
 public void UpdateDistrict(int id, District district)
 {
     using (finalSQLEntities se = new finalSQLEntities())
     {
         district.ID = id;
         se.Districts.AddOrUpdate(district);
         se.SaveChanges();
     };
 }
Esempio n. 6
0
 public void UpdateCity(int id, City city)
 {
     using (finalSQLEntities se = new finalSQLEntities())
     {
         city.ID = id;
         se.Cities.AddOrUpdate(city);
         se.SaveChanges();
     };
 }
Esempio n. 7
0
 public void FillDistrictPopulation(int districtId)
 {
     using (finalSQLEntities se = new finalSQLEntities())
     {
         int districtPopulation = se.Cities.Where(c => c.District.ID == districtId).Sum(c => c.Population).Value;
         se.Database.ExecuteSqlCommand
             ($"update [dbo].[Districts] set [Population]={districtPopulation} where [ID]={districtId}");
         se.SaveChanges();
     };
 }
Esempio n. 8
0
 public void DeleteDistrictsAll()
 {
     using (finalSQLEntities se = new finalSQLEntities())
     {
         se.Database.ExecuteSqlCommand
             ($"delete from [dbo].[Cities];" +
             $"delete from [dbo].[Districts]");
         se.SaveChanges();
     };
 }