2024-11-12 00:00:31 -06:00
|
|
|
|
using AutoMapper;
|
|
|
|
|
|
using AutoMapper.QueryableExtensions;
|
|
|
|
|
|
using LANCommander.Server.Data;
|
2024-11-25 22:29:56 -06:00
|
|
|
|
using LANCommander.Server.Data.Enums;
|
2024-08-21 19:40:27 -05:00
|
|
|
|
using LANCommander.Server.Data.Models;
|
2024-10-16 18:32:48 -05:00
|
|
|
|
using LANCommander.Server.Services.Factories;
|
2024-10-18 19:15:05 -05:00
|
|
|
|
using LANCommander.Server.Services.Models;
|
2024-10-16 16:29:55 -05:00
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
2024-10-18 19:15:05 -05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-10-07 18:04:26 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2024-10-18 19:15:05 -05:00
|
|
|
|
using System.Linq.Expressions;
|
2025-01-22 20:54:41 -06:00
|
|
|
|
using LANCommander.Server.Services.Exceptions;
|
2025-02-08 12:32:44 -06:00
|
|
|
|
using ZiggyCreatures.Caching.Fusion;
|
2024-08-21 19:40:27 -05:00
|
|
|
|
|
|
|
|
|
|
namespace LANCommander.Server.Services
|
|
|
|
|
|
{
|
2024-10-18 19:15:05 -05:00
|
|
|
|
public class UserService : BaseService, IBaseDatabaseService<User>
|
2024-08-21 19:40:27 -05:00
|
|
|
|
{
|
2024-11-08 00:38:47 -06:00
|
|
|
|
private readonly IdentityContext IdentityContext;
|
2025-01-12 02:54:41 -06:00
|
|
|
|
private readonly CollectionService CollectionService;
|
2024-11-12 00:00:31 -06:00
|
|
|
|
private readonly IMapper Mapper;
|
2025-02-08 12:32:44 -06:00
|
|
|
|
private readonly IFusionCache Cache;
|
2024-08-21 19:40:27 -05:00
|
|
|
|
|
2024-08-28 20:33:59 -05:00
|
|
|
|
public UserService(
|
|
|
|
|
|
ILogger<UserService> logger,
|
2024-11-12 00:00:31 -06:00
|
|
|
|
IMapper mapper,
|
2025-02-08 12:32:44 -06:00
|
|
|
|
IFusionCache cache,
|
2025-01-12 02:54:41 -06:00
|
|
|
|
CollectionService collectionService,
|
2024-10-18 19:15:05 -05:00
|
|
|
|
IdentityContextFactory identityContextFactory) : base(logger)
|
2024-08-21 19:40:27 -05:00
|
|
|
|
{
|
2024-11-08 00:38:47 -06:00
|
|
|
|
IdentityContext = identityContextFactory.Create();
|
2025-01-12 02:54:41 -06:00
|
|
|
|
CollectionService = collectionService;
|
2024-11-12 00:00:31 -06:00
|
|
|
|
Mapper = mapper;
|
2025-02-09 01:23:40 -06:00
|
|
|
|
Cache = cache;
|
2024-08-21 19:40:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<User> GetAsync(string userName)
|
2024-08-21 19:40:27 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return await IdentityContext.UserManager.FindByNameAsync(userName);
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<T> GetAsync<T>(string userName)
|
2024-11-12 00:00:31 -06:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var user = await IdentityContext.UserManager.FindByNameAsync(userName);
|
2024-11-12 00:00:31 -06:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return Mapper.Map<T>(user);
|
2024-11-12 00:00:31 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
public async Task<IEnumerable<Role>> GetRolesAsync(User user)
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var roles = await Cache.GetOrSetAsync($"User/{user.Id}/Roles", async _ =>
|
2024-10-16 18:32:48 -05:00
|
|
|
|
{
|
2025-02-08 23:23:06 -06:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
user = await IdentityContext.UserManager.FindByIdAsync(user.Id.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
var roleNames = await IdentityContext.UserManager.GetRolesAsync(user);
|
|
|
|
|
|
|
|
|
|
|
|
return await IdentityContext.RoleManager.Roles.Where(r => roleNames.Contains(r.Name)).ToListAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, "Could not get roles for user {Username}", user.UserName);
|
|
|
|
|
|
return new List<Role>();
|
|
|
|
|
|
}
|
2025-02-09 01:37:31 -06:00
|
|
|
|
}, tags: ["User/Security", "User/Roles", $"User/{user.Id}"]);
|
2025-02-08 12:32:44 -06:00
|
|
|
|
|
|
|
|
|
|
return roles;
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
public async Task<bool> IsInRoleAsync(User user, string roleName)
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var roles = await GetRolesAsync(user);
|
|
|
|
|
|
|
|
|
|
|
|
return roles.Any(r => r.Name == roleName);
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
public async Task<IEnumerable<Collection>> GetCollectionsAsync(User user)
|
2025-01-12 02:54:41 -06:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var roles = await GetRolesAsync(user);
|
2025-01-12 02:54:41 -06:00
|
|
|
|
var roleIds = roles.Select(r => r.Id).ToList();
|
|
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
if (roles.Any(r => r.Name.Equals(RoleService.AdministratorRoleName, StringComparison.OrdinalIgnoreCase)))
|
2025-01-12 02:54:41 -06:00
|
|
|
|
return await CollectionService.GetAsync();
|
|
|
|
|
|
else
|
|
|
|
|
|
return await CollectionService
|
2025-02-08 12:32:44 -06:00
|
|
|
|
.Include(c => c.Roles)
|
|
|
|
|
|
.GetAsync(c => c.Roles.Any(r => roleIds.Contains(r.Id)));
|
2025-01-12 02:54:41 -06:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
_logger.LogError(ex, "Could not get collections for user {UserName}", user.UserName);
|
2025-01-12 02:54:41 -06:00
|
|
|
|
return new List<Collection>();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<User> AddAsync(User user)
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var result = await IdentityContext.UserManager.CreateAsync(user);
|
|
|
|
|
|
|
|
|
|
|
|
if (result.Succeeded)
|
|
|
|
|
|
return await IdentityContext.UserManager.FindByNameAsync(user.UserName);
|
|
|
|
|
|
else
|
|
|
|
|
|
throw new UserRegistrationException(result, "Could not create user");
|
2024-10-16 16:29:55 -05:00
|
|
|
|
}
|
2024-10-16 01:54:51 -05:00
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task AddToRoleAsync(string userName, string roleName)
|
2024-10-16 16:29:55 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var user = await IdentityContext.UserManager.FindByNameAsync(userName);
|
2024-11-08 00:38:47 -06:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
await IdentityContext.UserManager.AddToRoleAsync(user, roleName);
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task AddToRolesAsync(string userName, IEnumerable<string> roleNames)
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var user = await IdentityContext.UserManager.FindByNameAsync(userName);
|
2024-11-08 00:38:47 -06:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var result = await IdentityContext.UserManager.AddToRolesAsync(user, roleNames);
|
2025-01-22 20:54:41 -06:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
|
throw new AddRoleException(result, "Could not add roles");
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-18 19:15:05 -05:00
|
|
|
|
public async Task RemoveFromRole(string userName, string roleName)
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var user = await IdentityContext.UserManager.FindByNameAsync(userName);
|
2024-10-18 19:15:05 -05:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
await IdentityContext.UserManager.RemoveFromRoleAsync(user, roleName);
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-18 19:15:05 -05:00
|
|
|
|
public async Task<bool> CheckPassword(string userName, string password)
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var user = await IdentityContext.UserManager.FindByNameAsync(userName);
|
2024-10-18 19:15:05 -05:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return await IdentityContext.UserManager.CheckPasswordAsync(user, password);
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-18 19:15:05 -05:00
|
|
|
|
public async Task<IdentityResult> ChangePassword(string userName, string currentPassword, string newPassword)
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var user = await IdentityContext.UserManager.FindByNameAsync(userName);
|
2024-11-08 00:38:47 -06:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var result = await IdentityContext.UserManager.ChangePasswordAsync(user, currentPassword, newPassword);
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return result;
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-18 19:15:05 -05:00
|
|
|
|
public async Task<IdentityResult> ChangePassword(string userName, string newPassword)
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var user = await IdentityContext.UserManager.FindByNameAsync(userName);
|
2024-10-18 19:15:05 -05:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var token = await IdentityContext.UserManager.GeneratePasswordResetTokenAsync(user);
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return await IdentityContext.UserManager.ResetPasswordAsync(user, token, newPassword);
|
WIP fix for MySQL connection concurrency issues
This is a large commit. There are a number of things that this commit does to try to fix various issues that were occurring when the database provider was set to MySQL:
- The DAL `Repository` has been completely refactored to follow best practices. The repository is now being injected into services instead of the database context itself. This allows the DI to handle the repository's lifetime instead of creating a new repository for every transaction and sharing the context across repositories. As part of these changes, there is no more allowed usage of `IQueryable` and all service/repository methods must actually execute database queries before their return. This is to ensure that the context does not stay open longer than it needs to. Abusing `IQueryable`s by tossing them into Blazor components seems to be a big no-no.
- Some deletion behaviors on relationships have been tweaked as MySQL wasn't able to apply migrations with behaviors that were contradictory.
- A `ConnectionInterceptor` was added to try to keep track of `DatabaseContext` lifetimes. This is really only for debugging and should be put into `#if DEBUG` regions. This helped identify some potential issues where some contexts were basically never closing, causing the MySQL connector to not function.
- Docs for generating migrations have been updated to reflect the addition of being able to specify the database provider and connection string when adding a migration, avoiding the need to edit `Settings.yml`
- The application can now be put into a pause state on startup by adding the `--debugger` argument when used from the command line. When a debugger is attached, it resumes execution.
- The application can now log to Seq when using debug build
- Service lifetime on `DatabaseContext` has switched to transient. This may be reverted in the future.
- Lazy loading has been disabled for debugging purposes. It didn't directly help the concurrency issues, but it needs to be tested individually to be re-enabled.
- All usage of `UserManager`, `RoleManager`, and `SignInManager` have been removed from all controllers, pages, and Blazor components. Functionality has been moved to `UserService` and `RoleService`. This might have done the most amount of help, but could probably be improved upon in the future by not relying on them and instead having our own implementation.
- Application startup migrations and server autostarts have been disabled temporarily. There might be an issue of `DatabaseContext` lifetimes that spawn from this.
2024-10-13 20:42:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task SignOut()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-10-18 19:15:05 -05:00
|
|
|
|
|
2025-02-16 13:24:23 -06:00
|
|
|
|
public IBaseDatabaseService<User> AsSplitQuery()
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<ICollection<User>> GetAsync()
|
2024-10-18 19:15:05 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return await IdentityContext.UserManager.Users.ToListAsync();
|
2024-10-18 19:15:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<ICollection<T>> GetAsync<T>()
|
2024-11-12 00:00:31 -06:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return await IdentityContext
|
|
|
|
|
|
.UserManager
|
|
|
|
|
|
.Users
|
|
|
|
|
|
.ProjectTo<T>(Mapper.ConfigurationProvider)
|
|
|
|
|
|
.ToListAsync();
|
2024-11-12 00:00:31 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<User> GetAsync(Guid id)
|
2024-10-18 19:15:05 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return await IdentityContext
|
|
|
|
|
|
.UserManager
|
|
|
|
|
|
.FindByIdAsync(id.ToString());
|
2024-10-18 19:15:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<T> GetAsync<T>(Guid id)
|
2024-11-12 00:00:31 -06:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var user = await IdentityContext
|
|
|
|
|
|
.UserManager
|
|
|
|
|
|
.FindByIdAsync(id.ToString());
|
2024-11-12 00:00:31 -06:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return Mapper.Map<T>(user);
|
2024-11-12 00:00:31 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<ICollection<User>> GetAsync(Expression<Func<User, bool>> predicate)
|
2024-10-18 19:15:05 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return await IdentityContext
|
|
|
|
|
|
.UserManager
|
|
|
|
|
|
.Users
|
|
|
|
|
|
.Where(predicate)
|
|
|
|
|
|
.ToListAsync();
|
2024-10-18 19:15:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<ICollection<T>> GetAsync<T>(Expression<Func<User, bool>> predicate)
|
2024-11-12 00:00:31 -06:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return await IdentityContext
|
|
|
|
|
|
.UserManager
|
|
|
|
|
|
.Users
|
|
|
|
|
|
.Where(predicate)
|
|
|
|
|
|
.ProjectTo<T>(Mapper.ConfigurationProvider)
|
|
|
|
|
|
.ToListAsync();
|
2024-11-12 00:00:31 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<User> FirstOrDefaultAsync(Expression<Func<User, bool>> predicate)
|
2024-10-18 19:15:05 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return await IdentityContext
|
|
|
|
|
|
.UserManager
|
|
|
|
|
|
.Users
|
|
|
|
|
|
.FirstOrDefaultAsync(predicate);
|
2024-10-18 19:15:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<T> FirstOrDefaultAsync<T>(Expression<Func<User, bool>> predicate)
|
2024-11-12 00:00:31 -06:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return await IdentityContext
|
|
|
|
|
|
.UserManager
|
|
|
|
|
|
.Users
|
|
|
|
|
|
.Where(predicate)
|
|
|
|
|
|
.ProjectTo<T>(Mapper.ConfigurationProvider)
|
|
|
|
|
|
.FirstOrDefaultAsync();
|
2024-11-12 00:00:31 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<User> FirstOrDefaultAsync<TKey>(Expression<Func<User, bool>> predicate, Expression<Func<User, TKey>> orderKeySelector)
|
2024-10-18 19:15:05 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return await IdentityContext
|
|
|
|
|
|
.UserManager
|
|
|
|
|
|
.Users
|
|
|
|
|
|
.Where(predicate)
|
|
|
|
|
|
.OrderBy(orderKeySelector)
|
|
|
|
|
|
.FirstOrDefaultAsync();
|
2024-11-12 00:00:31 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<T> FirstOrDefaultAsync<T, TKey>(Expression<Func<User, bool>> predicate, Expression<Func<T, TKey>> orderKeySelector)
|
2024-11-12 00:00:31 -06:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return await IdentityContext
|
|
|
|
|
|
.UserManager
|
|
|
|
|
|
.Users
|
|
|
|
|
|
.Where(predicate)
|
|
|
|
|
|
.ProjectTo<T>(Mapper.ConfigurationProvider)
|
|
|
|
|
|
.OrderBy(orderKeySelector)
|
|
|
|
|
|
.FirstOrDefaultAsync();
|
2024-10-18 19:15:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<bool> ExistsAsync(Guid id)
|
2024-10-18 19:15:05 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var user = await IdentityContext
|
|
|
|
|
|
.UserManager
|
|
|
|
|
|
.FindByIdAsync(id.ToString());
|
2024-10-18 19:15:05 -05:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return user != null;
|
2024-10-18 19:15:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<ExistingEntityResult<User>> AddMissingAsync(Expression<Func<User, bool>> predicate, User entity)
|
2024-10-18 19:15:05 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var result = new ExistingEntityResult<User>();
|
2024-10-18 19:15:05 -05:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var user = await IdentityContext
|
|
|
|
|
|
.UserManager
|
|
|
|
|
|
.Users
|
|
|
|
|
|
.FirstOrDefaultAsync(predicate);
|
2024-10-18 19:15:05 -05:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
if (user == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
await IdentityContext.UserManager.CreateAsync(entity);
|
2024-10-18 19:15:05 -05:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
result.Existing = false;
|
|
|
|
|
|
result.Value = await IdentityContext.UserManager.FindByNameAsync(user.UserName);
|
2024-10-18 19:15:05 -05:00
|
|
|
|
}
|
2025-02-08 12:32:44 -06:00
|
|
|
|
else
|
2024-11-08 00:38:47 -06:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
result.Existing = true;
|
|
|
|
|
|
result.Value = user;
|
2024-11-08 00:38:47 -06:00
|
|
|
|
}
|
2025-02-08 12:32:44 -06:00
|
|
|
|
|
|
|
|
|
|
return result;
|
2024-10-18 19:15:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task<User> UpdateAsync(User entity)
|
2024-10-18 19:15:05 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var user = await IdentityContext
|
|
|
|
|
|
.UserManager
|
|
|
|
|
|
.FindByIdAsync(entity.Id.ToString());
|
2024-10-18 19:15:05 -05:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
user.UserName = entity.UserName;
|
|
|
|
|
|
user.PhoneNumber = entity.PhoneNumber;
|
|
|
|
|
|
user.Email = entity.Email;
|
|
|
|
|
|
user.TwoFactorEnabled = entity.TwoFactorEnabled;
|
|
|
|
|
|
user.Alias = entity.Alias;
|
|
|
|
|
|
user.Approved = entity.Approved;
|
|
|
|
|
|
user.ApprovedOn = entity.ApprovedOn;
|
2024-10-18 19:15:05 -05:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
await IdentityContext.UserManager.UpdateAsync(user);
|
2024-10-18 19:15:05 -05:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
return user;
|
2024-10-18 19:15:05 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-12 18:32:46 -06:00
|
|
|
|
public async Task DeleteAsync(User entity)
|
2024-10-18 19:15:05 -05:00
|
|
|
|
{
|
2025-02-08 12:32:44 -06:00
|
|
|
|
var user = await IdentityContext
|
|
|
|
|
|
.UserManager
|
|
|
|
|
|
.FindByIdAsync(entity.Id.ToString());
|
2024-11-08 00:38:47 -06:00
|
|
|
|
|
2025-02-08 12:32:44 -06:00
|
|
|
|
await IdentityContext.UserManager.DeleteAsync(user);
|
2024-10-18 19:15:05 -05:00
|
|
|
|
}
|
2024-11-11 18:22:30 -06:00
|
|
|
|
|
|
|
|
|
|
public IBaseDatabaseService<User> Include(Expression<Func<User, object>> includeExpression)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
2024-11-25 22:29:56 -06:00
|
|
|
|
|
|
|
|
|
|
public IBaseDatabaseService<User> Query(Func<IQueryable<User>, IQueryable<User>> modifier)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IBaseDatabaseService<User> Include(params Expression<Func<User, object>>[] expressions)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IBaseDatabaseService<User> SortBy(Expression<Func<User, object>> expression, SortDirection direction)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-01 02:21:34 -06:00
|
|
|
|
public IBaseDatabaseService<User> AsNoTracking()
|
2024-11-25 22:29:56 -06:00
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Task<PaginatedResults<User>> PaginateAsync(Expression<Func<User, bool>> expression, int pageNumber, int pageSize)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
2024-08-21 19:40:27 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|