Home / Example of Service class

Code Example

The data in this demo uses the following code in the Service class. Replace the {...} in the code with your own logic. This can be an HttpClient, gRPC calls or in this demo it is a list in memory with random generated data.

C#

public class ContactsService : IEZRecordsetService<Contact>
{
    private readonly ContactsRepository _repository;

    public ContactsLocalService(ContactsRepository repository)
    {
        _repository = repository;
    }
    
    public async Task<EZActionResult<Contact?>> CreateAsync(Contact createdRecord)
    {
        return await Task.Run(() => _repository.PostContact(createdRecord));
    }

    public async Task<EZActionResult<bool>> DeleteAsync(Contact deleteRecord)
    {
        return await Task.Run(() => _repository.DeleteContact(deleteRecord.Id));
    }

    public async Task<EZActionResult<List<Contact>?>> GetAllAsync()
    {
        return await Task.Run(() => _repository.GetContacts());
    }

    public async Task<EZActionResult<Contact?>> GetAsync(Contact readRecord)
    {
        return await Task.Run(() => _repository.GetContact(readRecord.Id));
    }

    public async Task<EZActionResult<List<Contact>?>> GetAllWhereAsync(string? where)
    {
        return await Task.Run(() => _repository.GetContactsWhere(null, null, null, null, null, null));
    }

    public async Task<EZActionResult<Contact?>> UpdateAsync(Contact updatedRecord)
    {
        return await Task.Run(() => _repository.PutContact(updatedRecord));
    }
}
                            
An error has occurred. This application may no longer respond until reloaded. Reload 🗙