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

70 lines
2.1 KiB
C#
Raw Normal View History

2022-09-10 07:12:03 +03:00
using System;
2022-09-10 00:33:17 +03:00
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using BlueWest.Data;
using BlueWest.WebApi.EF;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace BlueWest.WebApi.Context.Users;
/// <summary>
/// Users Repository
/// </summary>
2022-09-11 01:22:04 +03:00
public class UserRepository : UserStore<ApplicationUser,
ApplicationRole,
ApplicationUserDbContext,
string,
ApplicationUserClaim,
ApplicationUserRole,
ApplicationUserLogin,
ApplicationUserToken,
ApplicationRoleClaim>
2022-09-10 00:33:17 +03:00
{
private readonly ApplicationUserDbContext _context;
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));
}
}