Skip to content

Instantly share code, notes, and snippets.

@ozgurrgul
Last active October 29, 2017 11:47
Show Gist options
  • Save ozgurrgul/3adc53011f020a754ea369eaa81e9a5f to your computer and use it in GitHub Desktop.
Save ozgurrgul/3adc53011f020a754ea369eaa81e9a5f to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Threading.Tasks;
namespace SimpleCrudApi.Entities
{
public interface ISimpleCrudService<T, TKey>
where T : class
where TKey : IEquatable<TKey>
{
Task<IQueryable<T>> List();
Task<T> Get(TKey id);
Task Create(T t);
Task Update(T t);
Task Delete(TKey id);
}
public class SimpleCrudService<T, TKey> : ISimpleCrudService<T, TKey>
where T : class
where TKey : IEquatable<TKey>
{
private readonly IRepository<T, TKey> _repository;
public SimpleCrudService(ApplicationDbContext dbContext)
{
_repository = new Repository<T, TKey>(dbContext);
}
public async Task<IQueryable<T>> List()
{
return await _repository.List();
}
public async Task<T> Get(TKey id)
{
return await _repository.Get(id);
}
public async Task Create(T t)
{
await _repository.Create(t);
}
public async Task Update(T t)
{
await _repository.Update(t);
}
public async Task Delete(TKey id)
{
await _repository.Delete(id);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment