コード例 #1
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);
 }
コード例 #2
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);
 }
コード例 #3
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);
        }
コード例 #4
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);
        }