public int Add(Models.ModelContact value) { var entity = new Contact { Id = value.Id, Name = value.Name, DateAdded = DateTime.UtcNow }; if (value.Phones != null) { foreach (var phone in value.Phones) { entity.ContactPhones.Add(new ContactPhone { PhoneNumber = phone.Number, PhoneType = phone.PhoneType.ToString() }); } } db.Contacts.Add(entity); db.SaveChanges(); return(entity.Id); }
public void UpdateById(int id, Models.ModelContact value) { var entity = db.Contacts.SingleOrDefault(t => t.Id == id); if (entity != null) { entity.Name = value.Name; //contact.Phones = value.Phones; db.SaveChanges(); } }