예제 #1
0
 public List <Person> Read()
 {
     using (PersonsPhonesContext context = new PersonsPhonesContext())
     {
         return(context.Persons.Include(p => p.Phones).ToList());
     }
 }
예제 #2
0
 public List <Phone> Read()
 {
     using (PersonsPhonesContext context = new PersonsPhonesContext())
     {
         return(context.Phones.ToList());
     }
 }
예제 #3
0
 public void Create(Person model)
 {
     using (PersonsPhonesContext context = new PersonsPhonesContext())
     {
         context.Persons.Add(model);
         context.SaveChanges();
     }
 }
예제 #4
0
 public void Delete(Phone model)
 {
     using (PersonsPhonesContext context = new PersonsPhonesContext())
     {
         Phone pToDel = context.Phones.First(x => x.Id == model.Id);
         context.Phones.Remove(pToDel);
         context.SaveChanges();
     }
 }
예제 #5
0
 public void Update(Phone model)
 {
     using (PersonsPhonesContext context = new PersonsPhonesContext())
     {
         Phone original = context.Phones.FirstOrDefault(x => x.Id == model.Id);
         context.Entry(original).CurrentValues.SetValues(model);
         context.SaveChanges();
     }
 }
예제 #6
0
 public void Delete(Person model)
 {
     using (PersonsPhonesContext context = new PersonsPhonesContext())
     {
         foreach (var phone in model.Phones)
         {
             phoneDAO.Delete(phone);
         }
         Person pToDel = context.Persons.First(x => x.Id == model.Id);
         context.Persons.Remove(pToDel);
         context.SaveChanges();
     }
 }
예제 #7
0
 public void Update(Person model)
 {
     using (PersonsPhonesContext context = new PersonsPhonesContext())
     {
         foreach (var phone in model.Phones)
         {
             if (phone.Id == 0)
             {
                 phone.Person   = null;
                 phone.PersonId = model.Id;
                 phoneDAO.Create(phone);
             }
         }
         Person original = context.Persons.FirstOrDefault(x => x.Id == model.Id);
         context.Entry(original).CurrentValues.SetValues(model);
         context.SaveChanges();
     }
 }