コード例 #1
0
 public List <Country> GetCountries()
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         return((from c in context.Countries
                 select c).ToList());
     }
 }
コード例 #2
0
 public List <Province> GetProvinces()
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         return((from c in context.Provinces
                 select c).ToList());
     }
 }
コード例 #3
0
 public Country GetCountry(int id)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         return((from c in context.Countries
                 where c.Id == id
                 select c).FirstOrDefault());
     }
 }
コード例 #4
0
 public Province GetProvince(int id)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         return((from c in context.Provinces
                 where c.Id == id
                 select c).FirstOrDefault());
     }
 }
コード例 #5
0
 public Country AddCountry(Country entity)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         context.Add(entity);
         context.SaveChanges();
     }
     return(entity);
 }
コード例 #6
0
 public List <Province> GetProvinces(Country country)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         return((from c in context.Provinces
                 .Include(c => c.Country)
                 select c).ToList());
     }
 }
コード例 #7
0
 public Province AddProvince(Province entity)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         context.Entry(entity.Country).State = EntityState.Unchanged;
         context.Add(entity);
         context.SaveChanges();
     }
     return(entity);
 }
コード例 #8
0
 public City AddCity(City entity)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         context.Entry(entity.Province).State = EntityState.Unchanged;
         context.Add(entity);
         context.SaveChanges();
     }
     return(entity);
 }
コード例 #9
0
 public List <City> GetCities(Country country)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         return((from c in context.Cities
                 .Include(c => c.Province.Country)
                 where c.Province.Country.Id == country.Id
                 select c).ToList());
     }
 }
コード例 #10
0
 //City
 public City GetCities(int id)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         return((from c in context.Cities
                 .Include(c => c.Province)
                 where c.Id == id
                 select c).FirstOrDefault());
     }
 }
コード例 #11
0
        public Country DeleteCountry(int idToSearch)
        {
            Country found = null;

            using (PropertyHubContext context = new PropertyHubContext())
            {
                found = context.Find <Country>(idToSearch);
                context.Remove(found);
                context.SaveChanges();
            }
            return(found);
        }
コード例 #12
0
        public Province DeleteProvince(int idToSearch)
        {
            Province found = null;

            using (PropertyHubContext context = new PropertyHubContext())
            {
                found = context.Find <Province>(idToSearch);
                context.Remove(found);
                context.SaveChanges();
            }
            return(found);
        }
コード例 #13
0
        public Province UpdateProvince(int idToSearch, Province entity)
        {
            Province found = null;

            using (PropertyHubContext context = new PropertyHubContext())
            {
                found      = context.Find <Province>(idToSearch);
                found.Name = entity.Name;
                if (entity.Country?.Id > 0)
                {
                    found.Country = entity.Country;
                }
                context.SaveChanges();
            }
            return(found);
        }
コード例 #14
0
        public Country UpdateCountry(int idToSearch, Country entity)
        {
            Country found = null;

            using (PropertyHubContext context = new PropertyHubContext())
            {
                found = context.Find <Country>(idToSearch);
                if (entity.Code.HasValue && entity.Code != 0)
                {
                    found.Code = entity.Code;
                }
                if (!string.IsNullOrEmpty(entity.Name))
                {
                    found.Name = entity.Name;
                }
                context.SaveChanges();
            }
            return(entity);
        }
コード例 #15
0
        public Province UpdateProvince(int idToSearch, Province entity)
        {
            Province found = null;

            using (PropertyHubContext context = new PropertyHubContext())
            {
                found = context.Provinces.Find(idToSearch);
                if (!string.IsNullOrEmpty(entity.Name))
                {
                    found.Name = entity.Name;
                }
                if (entity.Country?.Id != 0)
                {
                    found.Country = entity.Country;
                }

                context.Entry(found.Country).State = EntityState.Unchanged;
                context.SaveChanges();
            }
            return(found);
        }
コード例 #16
0
        public City UpdateCity(int idToSearch, City neighborhood)
        {
            City found = null;

            using (PropertyHubContext context = new PropertyHubContext())
            {
                found = context.Cities.Find(idToSearch);
                if (!string.IsNullOrEmpty(neighborhood.Name))
                {
                    found.Name = neighborhood.Name;
                }
                if (neighborhood.Province?.Id != 0)
                {
                    found.Province = neighborhood.Province;
                }

                context.Entry(found.Province).State = EntityState.Unchanged;
                context.SaveChanges();
            }
            return(neighborhood);
        }