Exemplo n.º 1
0
 public void Create(Person model)
 {
     using (PersonsPhonesContext context = new PersonsPhonesContext())
     {
         context.Persons.Add(model);
         context.SaveChanges();
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
     }
 }