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