Exemple #1
0
        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);
        }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
        private async Task <ContactEntity> GetContactById(string contactId)
        {
            ContactEntity contact = await _contactEntityTable.FirstOrDefaultAsync(x => x.Id == contactId);

            return(contact);
        }