diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-05-08 16:49:17 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-05-08 16:49:17 +0300 |
| commit | a1e46b76a1299e35b1ac8cae69e77c66d74224a6 (patch) | |
| tree | 068730b87c507df6386ff062ea620811dd6645ae /ExamTemplate/Data | |
| parent | e18090705f9b3d2a4be877743364f77f5effc46c (diff) | |
| download | it-kariera-exam-template-a1e46b76a1299e35b1ac8cae69e77c66d74224a6.tar it-kariera-exam-template-a1e46b76a1299e35b1ac8cae69e77c66d74224a6.tar.gz it-kariera-exam-template-a1e46b76a1299e35b1ac8cae69e77c66d74224a6.zip | |
Moved user repository logic into user service logic (no more repos)
Diffstat (limited to 'ExamTemplate/Data')
| -rw-r--r-- | ExamTemplate/Data/Repositories/UserRepository.cs | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/ExamTemplate/Data/Repositories/UserRepository.cs b/ExamTemplate/Data/Repositories/UserRepository.cs deleted file mode 100644 index 3e5ceaa..0000000 --- a/ExamTemplate/Data/Repositories/UserRepository.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Security.Claims; -using System.Threading.Tasks; -using ExamTemplate.Data.Models; -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; - -namespace ExamTemplate.Data.Repositories -{ - public class UserRepository - { - private readonly TemplateContext _context; - private readonly UserManager<User> _userManager; - private readonly RoleManager<Role> _roleManager; - - public UserRepository(TemplateContext templateContext, UserManager<User> userManager, RoleManager<Role> roleManager) - { - this._context = templateContext; - this._userManager = userManager; - this._roleManager = roleManager; - } - - public async Task<User> GetByUsernameAsync(string username) - { - return await this._userManager.Users - .Include(x => x.Roles) - .FirstOrDefaultAsync(x => x.UserName == username); - } - - public async Task<User> GetByClaimsAsync(ClaimsPrincipal claimsPrincipal) - { - return await this._userManager.GetUserAsync(claimsPrincipal); - } - - public async Task<bool> AddAsync(User user, string password) - { - user.PasswordHash = this._userManager.PasswordHasher.HashPassword(user, password); - IdentityResult result = await this._userManager.CreateAsync(user); - - return result.Succeeded; - } - - public async Task<bool> AddRoleToUserAsync(User user, string roleName) - { - bool succeeded = (await this._userManager.AddToRoleAsync(user, roleName)).Succeeded; - if (succeeded) - { - user.Roles.Add(await this._roleManager.FindByNameAsync(roleName)); - succeeded = await this._context.SaveChangesAsync() >= 1; - } - - return succeeded; - } - - public async Task<bool> EditUserAsync(User user) - { - IdentityResult result = await this._userManager.UpdateAsync(user); - - return result.Succeeded; - } - - public async Task<bool> VerifyPasswordAsync(User user, string password) - { - return await this._userManager.CheckPasswordAsync(user, password); - } - } -} |
