Last active
July 30, 2020 04:13
-
-
Save PradeepLoganathan/b053a879115cdc0c042eff1f1a6d7e51 to your computer and use it in GitHub Desktop.
CatalogueRepository concrete class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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