Skip to content

Instantly share code, notes, and snippets.

@PradeepLoganathan
Last active July 30, 2020 04:13
Show Gist options
  • Select an option

  • Save PradeepLoganathan/b053a879115cdc0c042eff1f1a6d7e51 to your computer and use it in GitHub Desktop.

Select an option

Save PradeepLoganathan/b053a879115cdc0c042eff1f1a6d7e51 to your computer and use it in GitHub Desktop.
CatalogueRepository concrete class
using System.Collections.Generic;
using System.Threading.Tasks;
using BookStore.Domain.CatalogueAggregate;
using Microsoft.EntityFrameworkCore;
namespace BookStore.Repository
{
class CatalogueRepository : ICatalogueRepository
{
private readonly BookStoreDbContext _context;
public CatalogueRepository(BookStoreDbContext context)
{
_context = context;
}
public async Task<int> Add(Catalogue entity)
{
await _context.Catalogues.AddAsync(entity);
return 1;
}
public async Task<int> Delete(int id)
{
var catalogue = await _context.Catalogues.FindAsync(id);
_context.Catalogues.Remove(catalogue);
return 1;
}
public async Task<Catalogue> Get(int id)
{
return await _context.Catalogues.FindAsync(id);
}
public async Task<IEnumerable<Catalogue>> GetAll()
{
return await _context.Catalogues.ToListAsync();
}
public async Task<int> Update(Catalogue entity)
{
var catalogue = await _context.Catalogues.FindAsync(entity);
this._context.Entry(catalogue).CurrentValues.SetValues(entity);
return 1;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment