From 7f250088599064efb9ccb278b0fa684232f845c6 Mon Sep 17 00:00:00 2001 From: Danail Dimitrov Date: Wed, 16 Dec 2020 22:56:36 +0200 Subject: Adding TechnologyRepository and Technology model --- src/DevHive.Data/Models/Technology.cs | 2 + .../Repositories/TechnologyRepository.cs | 73 ++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/DevHive.Data/Repositories/TechnologyRepository.cs (limited to 'src/DevHive.Data') diff --git a/src/DevHive.Data/Models/Technology.cs b/src/DevHive.Data/Models/Technology.cs index 0b031e3..2e0aeed 100644 --- a/src/DevHive.Data/Models/Technology.cs +++ b/src/DevHive.Data/Models/Technology.cs @@ -5,5 +5,7 @@ namespace DevHive.Data.Models public class Technology : IModel { public Guid Id { get; set; } + + public string Name { get; set; } } } 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 + { + private readonly DbContext _context; + + public TechnologyRepository(DbContext context) + { + this._context = context; + } + + //Create + public async Task AddAsync(Technology entity) + { + await this._context + .Set() + .AddAsync(entity); + + return await RepositoryMethods.SaveChangesAsync(this._context); + } + + //Read + public async Task GetByIdAsync(Guid id) + { + return await this._context + .Set() + .FindAsync(id); + } + + public async Task DoesTechnologyNameExist(string technologyName) + { + return await this._context + .Set() + .AsNoTracking() + .AnyAsync(r => r.Name == technologyName); + } + + public async Task DoesTechnologyExist(Guid id) + { + return await this._context + .Set() + .AsNoTracking() + .AnyAsync(r => r.Id == id); + } + + //Edit + public async Task EditAsync(Technology newEntity) + { + this._context + .Set() + .Update(newEntity); + + return await RepositoryMethods.SaveChangesAsync(this._context); + } + + //Delete + public async Task DeleteAsync(Technology entity) + { + this._context + .Set() + .Remove(entity); + + return await RepositoryMethods.SaveChangesAsync(this._context); + } + } +} \ No newline at end of file -- cgit v1.2.3