CodeLiturgy.Dashboard/BlueWest.Api/Users/UserRepository.cs

70 lines
2.1 KiB
C#
Raw Normal View History

2022-09-10 00:33:17 +03:00
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
2022-09-19 05:50:15 +03:00
using BlueWest.Domain;
2022-09-10 00:33:17 +03:00
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
2022-09-18 04:00:24 +03:00
namespace BlueWest.WebApi.Context.Users
2022-09-10 00:33:17 +03:00
{
2022-09-18 04:00:24 +03:00
/// <summary>
/// Users Repository
/// </summary>
public class UserRepository : UserStore<ApplicationUser,
ApplicationRole,
ApplicationUserDbContext,
string,
ApplicationUserClaim,
ApplicationUserRole,
ApplicationUserLogin,
ApplicationUserToken,
ApplicationRoleClaim>
{
private readonly ApplicationUserDbContext _context;
2022-09-10 00:33:17 +03:00
2022-09-11 01:22:04 +03:00
/// <summary>
/// User repository
/// </summary>
/// <param name="context"></param>
/// <param name="describer"></param>
2022-09-10 00:33:17 +03:00
public UserRepository(ApplicationUserDbContext context, IdentityErrorDescriber describer = null) : base(context, describer)
{
_context = context;
}
/// <summary>
/// Get Application Users
/// </summary>
/// <returns></returns>
public async Task<IEnumerable<ApplicationUser>> GetUsers()
{
var users = await _context.Users.ToListAsync();
return users;
}
/// <inheritdoc />
public override Task<string> GetPasswordHashAsync(ApplicationUser user, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<string>(cancellationToken);
}
return Task.FromResult(user.PasswordHash);
}
/// <inheritdoc />
public override Task<bool> HasPasswordAsync(ApplicationUser user, CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<bool>(cancellationToken);
}
return Task.FromResult(!string.IsNullOrEmpty(user.PasswordHash));
}
2022-09-18 04:00:24 +03:00
}
}