Adding role creation during startup + minor fixes in tests

This commit is contained in:
2025-03-16 22:41:44 +01:00
parent 7f5178883d
commit 18e713153b
48 changed files with 1449 additions and 340 deletions

View File

@@ -1,23 +1,43 @@
using BasicDotnetTemplate.MainProject.Core.Database;
using BasicDotnetTemplate.MainProject.Models.Api.Common.User;
using BasicDotnetTemplate.MainProject.Models.Settings;
namespace BasicDotnetTemplate.MainProject.Services;
public class BaseService
{
private readonly IHttpContextAccessor _httpContextAccessor;
protected readonly IConfiguration _configuration;
protected readonly AppSettings _appSettings;
protected readonly SqlServerContext _sqlServerContext;
public BaseService(
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration,
SqlServerContext sqlServerContext
)
{
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
_appSettings = new AppSettings();
_configuration.GetSection("AppSettings").Bind(_appSettings);
_sqlServerContext = sqlServerContext;
}
protected int? GetCurrentUserId()
{
int? userId = null;
var user = this.GetCurrentUser();
if (user != null)
{
userId = this._sqlServerContext.Users.Where(x => !x.IsDeleted && x.Guid == user.Guid).FirstOrDefault()?.Id;
}
return userId;
}
protected AuthenticatedUser? GetCurrentUser()
{
return _httpContextAccessor.HttpContext?.Items["User"] as AuthenticatedUser;
}
}