Exemplo n.º 1
0
 public void AddCountry(Country country)
 {
     using (GarmentsContext context = new GarmentsContext())
     {
         context.Countries.Add(country);
         context.SaveChanges();
     }
 }
Exemplo n.º 2
0
 public List <Country> GetCountries()
 {
     using (GarmentsContext context = new GarmentsContext())
     {
         return((from c in context.Countries
                 select c).ToList());
     }
 }
Exemplo n.º 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());
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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());
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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;
     }
 }