diff options
| author | transtrike <transtrike@gmail.com> | 2020-12-15 10:23:46 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2020-12-15 10:23:46 +0200 |
| commit | 09c8fc48a6a49c3c36df69ba2747088ac652054b (patch) | |
| tree | 9b25a521cf3effb63d1a06eb8496475eb201b8aa | |
| parent | 86800d2c5bcee9aae5162eb71c846ca5f91df761 (diff) | |
| download | DevHive-09c8fc48a6a49c3c36df69ba2747088ac652054b.tar DevHive-09c8fc48a6a49c3c36df69ba2747088ac652054b.tar.gz DevHive-09c8fc48a6a49c3c36df69ba2747088ac652054b.zip | |
Changed object to Guid in IRepository
| -rw-r--r-- | src/DevHive.Data/Repositories/IRepository.cs | 7 | ||||
| -rw-r--r-- | src/DevHive.Data/Repositories/UserRepository.cs | 23 | ||||
| -rw-r--r-- | src/DevHive.Services/Services/UserService.cs | 2 | ||||
| -rw-r--r-- | src/DevHive.Web/Controllers/UserController.cs | 8 |
4 files changed, 25 insertions, 15 deletions
diff --git a/src/DevHive.Data/Repositories/IRepository.cs b/src/DevHive.Data/Repositories/IRepository.cs index 81a1a35..f9ad2c5 100644 --- a/src/DevHive.Data/Repositories/IRepository.cs +++ b/src/DevHive.Data/Repositories/IRepository.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -13,12 +14,12 @@ namespace Data.Models.Interfaces.Database IEnumerable<TEntity> Query(int count); //Find entity by id - Task<TEntity> FindByIdAsync(object id); + Task<TEntity> FindByIdAsync(Guid id); //Modify Entity from database - Task EditAsync(object id, TEntity newEntity); + Task EditAsync(Guid id, TEntity newEntity); //Delete Entity from database - Task DeleteAsync(object id); + Task DeleteAsync(Guid id); } }
\ No newline at end of file diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index b884732..2363200 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -9,12 +10,11 @@ namespace DevHive.Data.Repositories { public class UserRepository : IRepository<User> { - private readonly UserRepository _dbRepository; + private readonly DbContext _context; public UserRepository(DbContext context) - : base (context) { - this._dbRepository = new DbRepository<User>(context); + this._context = context; } /* public User FindByUsername(string username) @@ -42,17 +42,26 @@ namespace DevHive.Data.Repositories x.UserName == username); } */ - public Task AddAsync(User entity) + public async Task AddAsync(User entity) { - throw new System.NotImplementedException(); + await this._context + .Set<User>() + .AddAsync(entity); + + await this._context.SaveChangesAsync(); } public IEnumerable<User> Query(int count) { - throw new System.NotImplementedException(); + return this._context + .Set<User>() + .AsNoTracking() + .Take(count) + .AsEnumerable(); + } - public Task<User> FindByIdAsync(object id) + public Task<User> FindByIdAsync(Guid id) { throw new System.NotImplementedException(); } diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index 0c849b1..d235755 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -25,7 +25,7 @@ namespace DevHive.Services.Services this._jwtOptions = jwtOptions; } - public async Task<IActionResult> LoginUser(LoginDTO loginDTO) + public async Task<IActionResult> LoginUser(LoginWebModel loginDTO) { User user = this._userRepository.FindByUsername(loginDTO.UserName); diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs index d8f078f..14ecb73 100644 --- a/src/DevHive.Web/Controllers/UserController.cs +++ b/src/DevHive.Web/Controllers/UserController.cs @@ -2,7 +2,6 @@ using System; using System.Threading.Tasks; using AutoMapper; using DevHive.Data.Repositories; -using DevHive.Services.Models.Identity; using DevHive.Services.Options; using DevHive.Services.Services; using DevHive.Web.Models.Identity.User; @@ -19,15 +18,16 @@ namespace DevHive.Web.Controllers public UserController(DevHiveContext context, IMapper mapper, JWTOptions jwtOptions) { - //this._service = new UserService(context, mapper, jwtOptions); + this._service = new UserService(context, mapper, jwtOptions); } [HttpPost] [Route("Login")] public async Task<IActionResult> Login([FromBody] LoginWebModel loginWebModel) { - //return await this._service.LoginUser(loginDTO); - throw new NotImplementedException(); + var loginDTO = + return await this._service.LoginUser(loginDTO); + //throw new NotImplementedException(); } [HttpPost] |
