public Country AddCountry(Country country)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         context.Add(country);
         context.SaveChanges();
     }
     return(country);
 }
예제 #2
0
 public void signup(User entity)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         context.Entry(entity.Role).State = EntityState.Unchanged;
         context.Add(entity);
         context.SaveChanges();
     }
 }
 public Province AddProvince(Province province)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         context.Entry(province.Country).State = EntityState.Unchanged;
         context.Add(province);
         context.SaveChanges();
     }
     return(province);
 }
 public City DeleteCity(int id)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         City found = context.Find <City>(id);
         context.Remove(found);
         context.SaveChanges();
         return(found);
     }
 }
 public City AddCity(City city)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         context.Entry(city.Province).State = EntityState.Unchanged;
         context.Add(city);
         context.SaveChanges();
     }
     return(city);
 }
 public City UpdateCity(int idToSearch, City city)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         context.Entry(city.Province).State = EntityState.Unchanged;
         City found = context.Find <City>(idToSearch);
         found.Name     = (!string.IsNullOrWhiteSpace(city.Name)) ? city.Name : found.Name;
         found.Province = (city.Province != null && city.Province.Id > 0) ? city.Province : found.Province;
         context.SaveChanges();
         return(found);
     }
 }
 public Country UpdateCountry(int idToSearch, Country country)
 {
     using (PropertyHubContext context = new PropertyHubContext())
     {
         Country found = context.Find <Country>(idToSearch);
         //context.Update(country);
         if (!string.IsNullOrWhiteSpace(country.Name))
         {
             found.Name = country.Name;
         }
         if (country.Code != null && country.Code > 0)
         {
             found.Code = country.Code;
         }
         context.SaveChanges();
         return(found);
     }
 }