public async Task <PhoneNumber> UpdateByIdAsync(int id, PhoneNumber newPhone) { PhoneNumber phoneNumber = await FindById(id); if (phoneNumber == null) { return(null); } phoneNumber.DDD = newPhone.DDD; phoneNumber.Number = newPhone.Number; phoneNumber.Contact = newPhone.Contact; _dbCtx.Update(phoneNumber); await _dbCtx.SaveChangesAsync(); return(phoneNumber); }
public async Task <Contact> UpdateById(int id, Contact newContact) { Contact currentContact = await FindById(id); if (currentContact == null) { return(null); } currentContact.Name = newContact.Name; if (newContact.PhoneNumbers.Count > 0) { currentContact.PhoneNumbers = newContact.PhoneNumbers; } _dbCtx.Update(currentContact); await _dbCtx.SaveChangesAsync(); return(currentContact); }