From dee2e37a4a8759108390c664e06bf147b8385cbf Mon Sep 17 00:00:00 2001 From: transtrike Date: Mon, 14 Dec 2020 23:29:14 +0200 Subject: Stabalized project for compilation. Next step after init architecture --- src/DevHive.Data/Repositories/DevHiveContext.cs | 26 ++++++++++ src/DevHive.Data/Repositories/IRepository.cs | 24 +++++++++ src/DevHive.Data/Repositories/UserRepository.cs | 69 +++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 src/DevHive.Data/Repositories/DevHiveContext.cs create mode 100644 src/DevHive.Data/Repositories/IRepository.cs create mode 100644 src/DevHive.Data/Repositories/UserRepository.cs (limited to 'src/DevHive.Data/Repositories') diff --git a/src/DevHive.Data/Repositories/DevHiveContext.cs b/src/DevHive.Data/Repositories/DevHiveContext.cs new file mode 100644 index 0000000..be5cc56 --- /dev/null +++ b/src/DevHive.Data/Repositories/DevHiveContext.cs @@ -0,0 +1,26 @@ +using System; +using DevHive.Data.Models; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; + +namespace DevHive.Data.Repositories +{ + public class DevHiveContext : IdentityDbContext, Guid> + { + public DevHiveContext(DbContextOptions options) + : base(options) { } + + public DbSet Technologies { get; set; } + public DbSet Languages { get; set; } + + protected override void OnModelCreating(ModelBuilder builder) + { + builder.Entity() + .HasIndex(x => x.UserName) + .IsUnique(); + + base.OnModelCreating(builder); + } + } +} diff --git a/src/DevHive.Data/Repositories/IRepository.cs b/src/DevHive.Data/Repositories/IRepository.cs new file mode 100644 index 0000000..81a1a35 --- /dev/null +++ b/src/DevHive.Data/Repositories/IRepository.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Data.Models.Interfaces.Database +{ + public interface IRepository + where TEntity : class + { + //Add Entity to database + Task AddAsync(TEntity entity); + + //Return *count* instances of Entity from the database + IEnumerable Query(int count); + + //Find entity by id + Task FindByIdAsync(object id); + + //Modify Entity from database + Task EditAsync(object id, TEntity newEntity); + + //Delete Entity from database + Task DeleteAsync(object id); + } +} \ No newline at end of file diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs new file mode 100644 index 0000000..5bd9d97 --- /dev/null +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Data.Models.Interfaces.Database; +using DevHive.Data.Models; + +namespace DevHive.Data.Repositories +{ + public class UserRepository : IRepository + { + /* private readonly UserRepository _dbRepository; + + public UserRepository(DbContext context) + : base (context) + { + this._dbRepository = new DbRepository(context); + } + + public User FindByUsername(string username) + { + return this._dbRepository.DbSet + .FirstOrDefault(usr => usr.UserName == username); + } + + public bool DoesUsernameExist(string username) + { + return this._dbRepository.DbSet + .Any(x => x.UserName == username); + } + + public bool DoesUserExist(Guid id) + { + return this._dbRepository.DbSet + .Any(x => x.Id == id); + } + + public bool HasThisUsername(Guid id, string username) + { + return this._dbRepository.DbSet + .Any(x => x.Id == id && + x.UserName == username); + } */ + + public Task AddAsync(User entity) + { + throw new System.NotImplementedException(); + } + + public IEnumerable Query(int count) + { + throw new System.NotImplementedException(); + } + + public Task FindByIdAsync(object id) + { + throw new System.NotImplementedException(); + } + + public Task EditAsync(object id, User newEntity) + { + throw new System.NotImplementedException(); + } + + public Task DeleteAsync(object id) + { + throw new System.NotImplementedException(); + } + } +} -- cgit v1.2.3