Пример #1
0
 public void Create(Person model)
 {
     using (PersonsPhonesContext context = new PersonsPhonesContext())
     {
         context.Persons.Add(model);
         context.SaveChanges();
     }
 }
Пример #2
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();
     }
 }
Пример #3
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();
     }
 }
Пример #4
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();
     }
 }
Пример #5
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();
     }
 }