public async Task DeleteAsync(string id) { ContactEntity contact = await GetContactById(id); if (contact is null) { throw new ContactNotFoundException("Contact was not found"); } await _database.DeleteAsync(contact); }
public async Task CreateOrUpdateContactAsync(Contact contact) { if (string.IsNullOrEmpty(contact.Id)) { contact.Id = Guid.NewGuid().ToString(); } ContactEntity contactEntity = await _contactEntityTable.FirstOrDefaultAsync(x => x.Id == contact.Id); if (contactEntity is null) { ContactEntity entity = contact.CreateEntity(); await _database.InsertAsync(entity); } else { contactEntity.Update(contact); await _database.UpdateAsync(contactEntity); } }
private async Task <ContactEntity> GetContactById(string contactId) { ContactEntity contact = await _contactEntityTable.FirstOrDefaultAsync(x => x.Id == contactId); return(contact); }