diff options
| -rw-r--r-- | API/Database/UserDbRepository.cs | 14 | ||||
| -rw-r--r-- | API/Service/UserService.cs | 8 |
2 files changed, 11 insertions, 11 deletions
diff --git a/API/Database/UserDbRepository.cs b/API/Database/UserDbRepository.cs index 7a11621..a51e3a8 100644 --- a/API/Database/UserDbRepository.cs +++ b/API/Database/UserDbRepository.cs @@ -17,16 +17,16 @@ namespace API.Database this._dbRepository = new DbRepository<User>(context); } - public async Task<bool> DoesUsernameExist(string username) + public bool DoesUsernameExist(string username) { - return await this._dbRepository.DbSet - .SingleAsync(x => x.UserName == username) == null; + return this._dbRepository.DbSet + .Any(x => x.UserName == username); } - public async Task<bool> DoesUserExist(int id) + public bool DoesUserExist(int id) { - return await this._dbRepository.DbSet - .SingleAsync(x => x.Id == id) == null; + return this._dbRepository.DbSet + .Any(x => x.Id == id); } } -}
\ No newline at end of file +} diff --git a/API/Service/UserService.cs b/API/Service/UserService.cs index 931010e..d32b31f 100644 --- a/API/Service/UserService.cs +++ b/API/Service/UserService.cs @@ -22,7 +22,7 @@ namespace API.Service public async Task<HttpStatusCode> CreateUser(UserDTO userDTO) { - if(await this._userDbRepository.DoesUsernameExist(userDTO.UserName)) + if(this._userDbRepository.DoesUsernameExist(userDTO.UserName)) return HttpStatusCode.Forbidden; User user = this._userMapper.Map<User>(userDTO); @@ -41,10 +41,10 @@ namespace API.Service public async Task<HttpStatusCode> UpdateUser(int id, UserDTO userDTO) { - if (!await this._userDbRepository.DoesUserExist(id)) + if (!this._userDbRepository.DoesUserExist(id)) return HttpStatusCode.NotFound; - if(await this._userDbRepository.DoesUsernameExist(userDTO.UserName)) + if (this._userDbRepository.DoesUsernameExist(userDTO.UserName)) return HttpStatusCode.Forbidden; User user = this._userMapper.Map<User>(userDTO); @@ -55,7 +55,7 @@ namespace API.Service public async Task<HttpStatusCode> DeleteUser(int id) { - if (!await this._userDbRepository.DoesUserExist(id)) + if (!this._userDbRepository.DoesUserExist(id)) return HttpStatusCode.Forbidden; await this._userDbRepository.DeleteAsync(id); |
