public async Task <bool> DeleteAsync(int id) { Entities.ContactListEntryEntity entityToDelete = await database.ContactListEntry .Where(c => c.Id == id) .FirstOrDefaultAsync(); if (entityToDelete is null) { return(false); } database.ContactListEntry.Remove(entityToDelete); int rowsDeleted = await database.SaveChangesAsync(); return(rowsDeleted > 0); }
public async Task <bool> UpdateAsync(int id, ContactListEntry updatedEntry) { Entities.ContactListEntryEntity entityToUpdate = await database.ContactListEntry .Where(c => c.Id == id) .FirstOrDefaultAsync(); if (entityToUpdate is null) { return(false); } entityToUpdate.Type = updatedEntry.Type; entityToUpdate.Name = updatedEntry.Name; entityToUpdate.DateOfBirth = updatedEntry.DateOfBirth; entityToUpdate.Address = updatedEntry.Address; entityToUpdate.PhoneNumber = updatedEntry.PhoneNumber; entityToUpdate.Email = updatedEntry.Email; int rowsUpdated = await database.SaveChangesAsync(); return(rowsUpdated > 0); }
public async Task <ContactListEntry> GetByIdAsync(int id) { Entities.ContactListEntryEntity entity = await database.ContactListEntry .Where(c => c.Id == id) .FirstOrDefaultAsync(); if (entity is null) { return(null); } return(new ContactListEntry { Id = entity.Id, Type = entity.Type, Name = entity.Name, DateOfBirth = entity.DateOfBirth, Address = entity.Address, PhoneNumber = entity.PhoneNumber, Email = entity.Email }); }