コード例 #1
0
 public void AddCountry(Country country)
 {
     using (GarmentsContext context = new GarmentsContext())
     {
         context.Countries.Add(country);
         context.SaveChanges();
     }
 }
コード例 #2
0
 public List <Country> GetCountries()
 {
     using (GarmentsContext context = new GarmentsContext())
     {
         return((from c in context.Countries
                 select c).ToList());
     }
 }
コード例 #3
0
 public List <Province> GetProvinces(Country country)
 {
     using (GarmentsContext context = new GarmentsContext())
     {
         return((from p in context.Provinces
                 where p.Country.Id == country.Id
                 select p).ToList());
     }
 }
コード例 #4
0
 public void AddProvince(Province province)
 {
     using (GarmentsContext context = new GarmentsContext())
     {
         context.Entry(province.Country).State = EntityState.Unchanged;
         context.Provinces.Add(province);
         context.SaveChanges();
     }
 }
コード例 #5
0
 public void DeleteCountry(Country country)
 {
     using (GarmentsContext context = new GarmentsContext())
     {
         Country found = context.Countries.Find(country.Id);
         context.Countries.Remove(found);
         context.SaveChanges();
     }
 }
コード例 #6
0
 public Country GetCountry(int id)
 {
     using (GarmentsContext context = new GarmentsContext())
     {
         return((from c in context.Countries
                 where c.Id == id
                 select c).FirstOrDefault());
     }
 }
コード例 #7
0
 public void UpdateCountry(int idToSearch, Country country)
 {
     using (GarmentsContext context = new GarmentsContext())
     {
         Country found = context.Countries.Find(idToSearch);
         if (!(string.IsNullOrWhiteSpace(country.Name)))
         {
             found.Name = country.Name;
         }
         found.Code = country.Code;
         context.SaveChanges();
     }
 }
コード例 #8
0
 public Province GetProvince(int id)
 {
     //Province found = null;
     using (GarmentsContext context = new GarmentsContext())
     {
         //context.Configuration.LazyLoadingEnabled = true;
         Province found = (from p in context.Provinces
                           .Include(p => p.Country)
                           where p.Id == id
                           select p).FirstOrDefault();
         return(found);
         //string name = found.Country.Name;
     }
 }