diff options
| author | Danail Dimitrov <danaildimitrov321@gmail.com> | 2020-12-16 22:56:36 +0200 |
|---|---|---|
| committer | Danail Dimitrov <danaildimitrov321@gmail.com> | 2020-12-16 22:56:36 +0200 |
| commit | 7f250088599064efb9ccb278b0fa684232f845c6 (patch) | |
| tree | b8dbf8e9872897634ddd8c1f3ddfb2078cc942c5 /src/DevHive.Data/Repositories/TechnologyRepository.cs | |
| parent | cd02428e748e691a0005b2687edf69a99766aac6 (diff) | |
| download | DevHive-7f250088599064efb9ccb278b0fa684232f845c6.tar DevHive-7f250088599064efb9ccb278b0fa684232f845c6.tar.gz DevHive-7f250088599064efb9ccb278b0fa684232f845c6.zip | |
Adding TechnologyRepository and Technology model
Diffstat (limited to 'src/DevHive.Data/Repositories/TechnologyRepository.cs')
| -rw-r--r-- | src/DevHive.Data/Repositories/TechnologyRepository.cs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/DevHive.Data/Repositories/TechnologyRepository.cs b/src/DevHive.Data/Repositories/TechnologyRepository.cs new file mode 100644 index 0000000..debfd3e --- /dev/null +++ b/src/DevHive.Data/Repositories/TechnologyRepository.cs @@ -0,0 +1,73 @@ +using System; +using System.Threading.Tasks; +using Data.Models.Interfaces.Database; +using DevHive.Data.Models; +using Microsoft.EntityFrameworkCore; +using DevHive.Common.Models.Data; + +namespace DevHive.Data.Repositories +{ + public class TechnologyRepository : IRepository<Technology> + { + private readonly DbContext _context; + + public TechnologyRepository(DbContext context) + { + this._context = context; + } + + //Create + public async Task<bool> AddAsync(Technology entity) + { + await this._context + .Set<Technology>() + .AddAsync(entity); + + return await RepositoryMethods.SaveChangesAsync(this._context); + } + + //Read + public async Task<Technology> GetByIdAsync(Guid id) + { + return await this._context + .Set<Technology>() + .FindAsync(id); + } + + public async Task<bool> DoesTechnologyNameExist(string technologyName) + { + return await this._context + .Set<Technology>() + .AsNoTracking() + .AnyAsync(r => r.Name == technologyName); + } + + public async Task<bool> DoesTechnologyExist(Guid id) + { + return await this._context + .Set<Technology>() + .AsNoTracking() + .AnyAsync(r => r.Id == id); + } + + //Edit + public async Task<bool> EditAsync(Technology newEntity) + { + this._context + .Set<Technology>() + .Update(newEntity); + + return await RepositoryMethods.SaveChangesAsync(this._context); + } + + //Delete + public async Task<bool> DeleteAsync(Technology entity) + { + this._context + .Set<Technology>() + .Remove(entity); + + return await RepositoryMethods.SaveChangesAsync(this._context); + } + } +}
\ No newline at end of file |
