diff options
Diffstat (limited to 'API/Database')
| -rw-r--r-- | API/Database/DbRepository.cs | 12 | ||||
| -rw-r--r-- | API/Database/UserDbRepository.cs | 32 |
2 files changed, 37 insertions, 7 deletions
diff --git a/API/Database/DbRepository.cs b/API/Database/DbRepository.cs index 184adb4..a24be36 100644 --- a/API/Database/DbRepository.cs +++ b/API/Database/DbRepository.cs @@ -11,6 +11,7 @@ namespace API.Database where TEntity : class { private readonly DbContext _context; + public DbRepository(DbContext context) { _context = context; @@ -34,23 +35,18 @@ namespace API.Database .FindAsync(id); } - public IEnumerable<TEntity> Query() + public IEnumerable<TEntity> Query(int count) { return this._context .Set<TEntity>() .AsNoTracking() + .Take(count) .AsEnumerable(); } - public IEnumerable<TEntity> Query(int count) - { - return this.Query().Take(count); - } - //Update public async Task EditAsync(object id, TEntity newEntity) { - //Set the Id property to the given id TEntity entity = await FindByIdAsync(id); this._context.Entry(entity) @@ -69,5 +65,7 @@ namespace API.Database await this._context.SaveChangesAsync(); } + + public DbSet<TEntity> DbSet => this._context.Set<TEntity>(); } } diff --git a/API/Database/UserDbRepository.cs b/API/Database/UserDbRepository.cs new file mode 100644 index 0000000..a4a3ac0 --- /dev/null +++ b/API/Database/UserDbRepository.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Models.Interfaces.Database; +using Microsoft.EntityFrameworkCore; +using Models.Classes; + +namespace API.Database +{ + public class UserDbRepository : DbRepository<User> + { + private readonly DbRepository<User> _dbRepository; + + public UserDbRepository(DbContext context) + : base (context) + { + this._dbRepository = new DbRepository<User>(context); + } + + public bool DoesUsernameExist(string username) + { + return this._dbRepository.DbSet + .Any(x => x.UserName == username); + } + + public bool DoesUserExist(int id) + { + return this._dbRepository.DbSet + .Any(x => x.Id == id); + } + } +}
\ No newline at end of file |
