Remove dependencies of BlueWest.Ef.Methods

This commit is contained in:
Rui Sousa 2023-11-04 15:35:19 +00:00
parent 70dc2afd1f
commit 869a68ee91
46 changed files with 259 additions and 370 deletions

View File

@ -4,7 +4,6 @@ using Microsoft.AspNetCore.Identity;
namespace CodeLiturgy.Data.Application.Users namespace CodeLiturgy.Data.Application.Users
{ {
/// <inheritdoc /> /// <inheritdoc />
[MapFrom(typeof(ApplicationRoleUnique))]
public partial class ApplicationRole : IdentityRole<string> public partial class ApplicationRole : IdentityRole<string>
{ {

View File

@ -2,7 +2,6 @@ using MapTo;
namespace CodeLiturgy.Data.Application.Users namespace CodeLiturgy.Data.Application.Users
{ {
[MapFrom(typeof(ApplicationRole))]
public partial class ApplicationRoleUnique public partial class ApplicationRoleUnique
{ {
public string Id { get; set; } public string Id { get; set; }

View File

@ -6,7 +6,6 @@ namespace CodeLiturgy.Data.Application.Users
{ {
/// <inheritdoc /> /// <inheritdoc />
[MapFrom(typeof(ApplicationRoleClaimUnique))]
public partial class ApplicationRoleClaim : IdentityRoleClaim<string> public partial class ApplicationRoleClaim : IdentityRoleClaim<string>
{ {

View File

@ -2,7 +2,6 @@ using MapTo;
namespace CodeLiturgy.Data.Application.Users namespace CodeLiturgy.Data.Application.Users
{ {
[MapFrom(typeof(ApplicationRoleClaim))]
public partial class ApplicationRoleClaimUnique public partial class ApplicationRoleClaimUnique
{ {
public int Id { get; set; } public int Id { get; set; }

View File

@ -13,8 +13,6 @@ namespace CodeLiturgy.Data.Application.Users
/// <summary> /// <summary>
/// Application User in the Identity System. /// Application User in the Identity System.
/// </summary> /// </summary>
[MapFrom(typeof(ApplicationUserUnique))]
[UseUpdate]
public partial class ApplicationUser : IdentityUser<string> public partial class ApplicationUser : IdentityUser<string>
{ {
public new string Id { get; set; } public new string Id { get; set; }

View File

@ -3,7 +3,6 @@ using MapTo;
namespace CodeLiturgy.Data.Application.Users namespace CodeLiturgy.Data.Application.Users
{ {
[MapFrom(typeof(ApplicationUser))]
public partial class ApplicationUserUnique public partial class ApplicationUserUnique
{ {
public string Id { get; set; } public string Id { get; set; }

View File

@ -3,7 +3,6 @@ using MapTo;
namespace CodeLiturgy.Data.Application.Users namespace CodeLiturgy.Data.Application.Users
{ {
[MapFrom(typeof(ApplicationUserClaimUnique))]
/// <inheritdoc /> /// <inheritdoc />
public partial class ApplicationUserClaim : IdentityUserClaim<string> public partial class ApplicationUserClaim : IdentityUserClaim<string>

View File

@ -2,7 +2,6 @@ using MapTo;
namespace CodeLiturgy.Data.Application.Users namespace CodeLiturgy.Data.Application.Users
{ {
[MapFrom(typeof(ApplicationUserClaim))]
public partial class ApplicationUserClaimUnique public partial class ApplicationUserClaimUnique
{ {
public int Id { get; set; } public int Id { get; set; }

View File

@ -7,7 +7,6 @@ namespace CodeLiturgy.Data.Application.Users
{ {
/// <inheritdoc /> /// <inheritdoc />
[MapFrom(typeof(ApplicationUserRoleUnique))]
public partial class ApplicationUserRole : IdentityUserRole<string> public partial class ApplicationUserRole : IdentityUserRole<string>
{ {

View File

@ -2,7 +2,6 @@ using MapTo;
namespace CodeLiturgy.Data.Application.Users namespace CodeLiturgy.Data.Application.Users
{ {
[MapFrom(typeof(ApplicationUserRole))]
public partial class ApplicationUserRoleUnique public partial class ApplicationUserRoleUnique
{ {
public string UserId { get; set; } public string UserId { get; set; }

View File

@ -6,11 +6,6 @@ using MapTo;
namespace CodeLiturgy.Data.Application namespace CodeLiturgy.Data.Application
{ {
[MapFrom(new []
{
typeof(SiteUnique),
typeof(SiteCreate)
})]
public partial class Site public partial class Site
{ {

View File

@ -2,7 +2,6 @@ using MapTo;
namespace CodeLiturgy.Data.Application namespace CodeLiturgy.Data.Application
{ {
[MapFrom(typeof(Site))]
public partial class SiteCreate public partial class SiteCreate
{ {
public string Id { get; set; } public string Id { get; set; }

View File

@ -4,7 +4,6 @@ using MapTo;
namespace CodeLiturgy.Data.Application namespace CodeLiturgy.Data.Application
{ {
[MapFrom(new [] {typeof(SiteEnvironmentCreate)})]
public partial class SiteEnvironment public partial class SiteEnvironment
{ {

View File

@ -4,7 +4,6 @@ using MapTo;
namespace CodeLiturgy.Data.Application namespace CodeLiturgy.Data.Application
{ {
[MapFrom(typeof(SiteEnvironment))]
public partial class SiteEnvironmentCreate public partial class SiteEnvironmentCreate
{ {
public string Name { get; set; } public string Name { get; set; }

View File

@ -4,7 +4,6 @@ using MapTo;
namespace CodeLiturgy.Data.Application namespace CodeLiturgy.Data.Application
{ {
[MapFrom(typeof(SiteEnvironment))]
public partial class SiteEnvironmentUnique public partial class SiteEnvironmentUnique
{ {
public string Id { get; set; } public string Id { get; set; }

View File

@ -3,8 +3,6 @@ using MapTo;
namespace CodeLiturgy.Data.Application namespace CodeLiturgy.Data.Application
{ {
[MapFrom(typeof(Site))]
public partial class SiteUnique public partial class SiteUnique
{ {
public string Id { get; set; } public string Id { get; set; }

View File

@ -10,7 +10,6 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BlueWest.EfMethods" Version="0.9.9-g05eef7070f" />
<PackageReference Include="MapTo" Version="0.9.41-gcfa46bb014" /> <PackageReference Include="MapTo" Version="0.9.41-gcfa46bb014" />
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.9" /> <PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.11" /> <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.11" />
@ -136,19 +135,12 @@
<ItemGroup> <ItemGroup>
<AdditionalFiles Include="Templates\AddToListTemplate.csx" />
<AdditionalFiles Include="Templates\AddToTemplate.csx" />
<AdditionalFiles Include="Templates\GetListTemplate.csx" />
<AdditionalFiles Include="Templates\GetManyTemplate.csx" />
<AdditionalFiles Include="Templates\GetOneByTemplate.csx" />
<AdditionalFiles Include="Templates\GetOneFromListTemplate.csx" />
<AdditionalFiles Include="Templates\GetOneTemplate.csx" />
<AdditionalFiles Include="Templates\UpdateTemplate.csx" />
<AdditionalFiles Include="Views\Auth\Account.cshtml" /> <AdditionalFiles Include="Views\Auth\Account.cshtml" />
<AdditionalFiles Include="Views\EnvironmentsPage\Index.cshtml" /> <AdditionalFiles Include="Views\Environments\Index.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\include\BlueWest.EfGenerator\src\BlueWest.EfMethods\BlueWest.EfMethods.csproj" />
<ProjectReference Include="..\include\Math-Expression-Evaluator\SimpleExpressionEvaluator\SimpleExpressionEvaluator.csproj" /> <ProjectReference Include="..\include\Math-Expression-Evaluator\SimpleExpressionEvaluator\SimpleExpressionEvaluator.csproj" />
<ProjectReference Include="..\include\Sharp.Augeas\Sharp.Augeas\Sharp.Augeas.csproj" /> <ProjectReference Include="..\include\Sharp.Augeas\Sharp.Augeas\Sharp.Augeas.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -7,7 +7,7 @@ using CodeLiturgy.Views.Utils;
namespace CodeLiturgy.Views.Controllers; namespace CodeLiturgy.Views.Controllers;
public class AccountController : UserController public class AccountController : LoggedInUserController
{ {
public AccountController( public AccountController(
ApplicationUserManager userManager, ApplicationUserManager userManager,

View File

@ -15,7 +15,7 @@ namespace CodeLiturgy.Views.Controllers
[Authorize] [Authorize]
public class ApacheController : ControllerBase public class ApacheController : ControllerBase
{ {
private ILogger<SitesController> _logger; private ILogger<SitesApiController> _logger;
private readonly SiteDbContext _siteDbContext; private readonly SiteDbContext _siteDbContext;
private readonly AugeasManager _augeasManager; private readonly AugeasManager _augeasManager;
@ -28,7 +28,7 @@ namespace CodeLiturgy.Views.Controllers
/// <param name="augeasManager"></param> /// <param name="augeasManager"></param>
public ApacheController( public ApacheController(
ApplicationUserManager userManager, ApplicationUserManager userManager,
ILogger<SitesController> logger, ILogger<SitesApiController> logger,
SiteDbContext siteDbContext, SiteDbContext siteDbContext,
AugeasManager augeasManager) AugeasManager augeasManager)
{ {

View File

@ -11,7 +11,7 @@ using Controller = Microsoft.AspNetCore.Mvc.Controller;
namespace CodeLiturgy.Views.Controllers namespace CodeLiturgy.Views.Controllers
{ {
public class AuthController : UserController public class AuthController : LoggedInUserController
{ {
private readonly IAuthManager _authManager; private readonly IAuthManager _authManager;

View File

@ -3,17 +3,18 @@ using CodeLiturgy.Data.Auth.Context.Users;
using CodeLiturgy.Domain; using CodeLiturgy.Domain;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace CodeLiturgy.Views.Controllers namespace CodeLiturgy.Views.Controllers
{ {
[ApiController] [ApiController]
[Authorize] [Authorize]
public class EnvironmentController : ControllerBase public class EnvironmentsApiController : ControllerBase
{ {
private ApplicationUserManager _userManager; private ApplicationUserManager _userManager;
private ILogger<SitesController> _logger; private ILogger<SitesApiController> _logger;
private readonly SiteDbContext _siteDbContext; private readonly SiteDbContext _siteDbContext;
public EnvironmentController(ApplicationUserManager userManager, ILogger<SitesController> logger, SiteDbContext siteDbContext) public EnvironmentsApiController(ApplicationUserManager userManager, ILogger<SitesApiController> logger, SiteDbContext siteDbContext)
{ {
_logger = logger; _logger = logger;
_userManager = userManager; _userManager = userManager;
@ -22,16 +23,13 @@ namespace CodeLiturgy.Views.Controllers
[HttpGet("/api/environments")] [HttpGet("/api/environments")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status401Unauthorized)]
public ActionResult GetEnvironments( public async Task<ActionResult> GetEnvironments(
int skip = 0, int take = 50, int orderDir = 1) int skip = 0, int take = 50, int orderDir = 1)
{ {
var (success, sites) = _siteDbContext.GetEnvironments(skip, take, orderDir); var sites = _siteDbContext.Environments.Skip(skip).Take(take).ToListAsync();
if (!success) return new NotFoundResult();
return Ok(sites); return Ok(sites);
} }
@ -41,13 +39,16 @@ namespace CodeLiturgy.Views.Controllers
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
public ActionResult AddEnvironment(SiteEnvironmentCreate siteEnvironmentCreate) public async Task<ActionResult> AddEnvironment(SiteEnvironmentCreate siteEnvironmentCreate)
{ {
var (success, result) = _siteDbContext.AddSiteEnvironment(siteEnvironmentCreate); var newEnvironment= new SiteEnvironment();
newEnvironment.Name = siteEnvironmentCreate.Name;
_siteDbContext.Environments.Add(newEnvironment);
var success = await _siteDbContext.SaveChangesAsync() >= 0;
if (success) if (success)
{ {
return Ok(result); return Ok(newEnvironment);
} }
return BadRequest(); return BadRequest();
@ -64,11 +65,11 @@ namespace CodeLiturgy.Views.Controllers
[ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status403Forbidden)]
[HttpGet("/api/environments/{environmentId}", Name = nameof(GetEnvironmentById))] [HttpGet("/api/environments/{environmentId}", Name = nameof(GetEnvironmentById))]
public ActionResult GetEnvironmentById(string siteId) public async Task<ActionResult> GetEnvironmentById(string siteId)
{ {
var (success, environment) = _siteDbContext.GetOneSiteById(siteId); var environment = await _siteDbContext.Environments.Where(x => x.Id == siteId).FirstOrDefaultAsync();
if (success) if (environment != null)
{ {
return Ok(environment); return Ok(environment);
} }

View File

@ -6,11 +6,11 @@ using Microsoft.AspNetCore.Mvc;
namespace CodeLiturgy.Views.Controllers; namespace CodeLiturgy.Views.Controllers;
public class EnvironmentsPageController : UserController public class EnvironmentsController : LoggedInUserController
{ {
public EnvironmentsPageController( public EnvironmentsController(
ApplicationUserManager userManager, ApplicationUserManager userManager,
ILogger<UserController> logger) ILogger<LoggedInUserController> logger)
: base(userManager, logger) { } : base(userManager, logger) { }
public override void OnInitialization() public override void OnInitialization()

View File

@ -7,7 +7,7 @@ namespace CodeLiturgy.Views.Controllers;
[System.Web.Mvc.Route("/")] [System.Web.Mvc.Route("/")]
[System.Web.Mvc.Authorize] [System.Web.Mvc.Authorize]
public class HomeController : UserController public class HomeController : LoggedInUserController
{ {
public HomeController( public HomeController(
ApplicationUserManager userManager, ApplicationUserManager userManager,

View File

@ -10,15 +10,18 @@ using Microsoft.AspNetCore.Mvc;
namespace CodeLiturgy.Views.Controllers; namespace CodeLiturgy.Views.Controllers;
public class UserController : Controller /// <summary>
/// Base controller class for Views.
/// </summary>
public class LoggedInUserController : Controller
{ {
protected ILogger<UserController> _logger; protected ILogger<LoggedInUserController> _logger;
protected ApplicationUserManager _userManager; protected ApplicationUserManager _userManager;
private List<Url> _footerMenu; private List<Url> _footerMenu;
private List<Url> _headerMenu; private List<Url> _headerMenu;
public UserController(ApplicationUserManager userManager, ILogger<UserController> logger) public LoggedInUserController(ApplicationUserManager userManager, ILogger<LoggedInUserController> logger)
{ {
_logger = logger; _logger = logger;
_userManager = userManager; _userManager = userManager;
@ -76,7 +79,15 @@ public class UserController : Controller
ApplicationUser user = await _userManager.GetUserAsync(User); ApplicationUser user = await _userManager.GetUserAsync(User);
if (user != null) if (user != null)
{ {
return new ApplicationUserUnique(user); var dto = new ApplicationUserUnique()
{
Email = user.Email,
EmailConfirmed = user.EmailConfirmed,
NormalizedEmail = user.NormalizedEmail,
UserName = user.UserName,
LockoutEnabled = user.LockoutEnabled
};
return dto;
} }
} }

View File

@ -0,0 +1,119 @@
using CodeLiturgy.Data.Auth.Context.Users;
using CodeLiturgy.Data.Application;
using CodeLiturgy.Domain;
using CodeLiturgy.Views.Augeas;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace CodeLiturgy.Views.Controllers
{
/// <summary>
/// Controller responsible for managing websites.
/// </summary>
[Route("api/sites")]
[ApiController]
[Authorize]
public class SitesApiController : ControllerBase
{
private ApplicationUserManager _userManager;
private ILogger<SitesApiController> _logger;
private readonly SiteDbContext _siteDbContext;
private readonly AugeasManager _augeasManager;
/// <summary>
/// Sites controller constructor.
/// </summary>
/// <param name="userManager"></param>
/// <param name="logger"></param>
/// <param name="siteDbContext"></param>
/// <param name="augeasManager"></param>
public SitesApiController(
ApplicationUserManager userManager,
ILogger<SitesApiController> logger,
SiteDbContext siteDbContext,
AugeasManager augeasManager)
{
_logger = logger;
_userManager = userManager;
_siteDbContext = siteDbContext;
_augeasManager = augeasManager;
}
/// <summary>
/// Gets the sites stored in the database.
/// </summary>
/// <param name="skip"></param>
/// <param name="take"></param>
/// <param name="orderDir"></param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<ActionResult> GetSites(
int skip = 0, int take = 50, int orderDir = 1)
{
var result = await _siteDbContext
.Sites.Skip(skip)
.Take(take)
.ToListAsync();
return Ok(result);
}
/// <summary>
/// Gets a site by Id.
/// </summary>
/// <param name="siteId">Site id.</param>
/// <returns></returns>
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[HttpGet("{siteId}", Name = nameof(GetSiteById))]
public async Task<ActionResult> GetSiteById(string siteId)
{
var site = await _siteDbContext.Sites.Where(x => x.Id == siteId).FirstOrDefaultAsync();
if (site != null)
{
return Ok(site);
}
return new NotFoundResult();
}
/// <summary>
/// Adds a site to the database.
/// </summary>
/// <param name="siteToCreate"></param>
/// <returns></returns>
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status406NotAcceptable)]
[HttpPost]
public async Task<ActionResult> AddSite(SiteCreate siteToCreate)
{
var site = new Site()
{
Domain = siteToCreate.Domain,
CreatedDate = DateTime.Today,
SiteType = siteToCreate.SiteType
};
_siteDbContext.Sites.Add(site);
var success = await _siteDbContext.SaveChangesAsync() >= 0;
if (!success) return new BadRequestResult();
return CreatedAtRoute(nameof(GetSiteById), new {Id = site.Id}, site);
}
}
}

View File

@ -1,108 +1,12 @@
using CodeLiturgy.Data.Auth.Context.Users;
using CodeLiturgy.Data.Application;
using CodeLiturgy.Domain;
using CodeLiturgy.Views.Augeas;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace CodeLiturgy.Views.Controllers;
namespace CodeLiturgy.Views.Controllers public class SitesController : Controller
{ {
/// <summary> // GET
/// Controller responsible for managing websites. public IActionResult Index()
/// </summary>
[Route("api/sites")]
[ApiController]
[Authorize]
public class SitesController : ControllerBase
{ {
private ApplicationUserManager _userManager; return View();
private ILogger<SitesController> _logger;
private readonly SiteDbContext _siteDbContext;
private readonly AugeasManager _augeasManager;
/// <summary>
/// Sites controller constructor.
/// </summary>
/// <param name="userManager"></param>
/// <param name="logger"></param>
/// <param name="siteDbContext"></param>
/// <param name="augeasManager"></param>
public SitesController(
ApplicationUserManager userManager,
ILogger<SitesController> logger,
SiteDbContext siteDbContext,
AugeasManager augeasManager)
{
_logger = logger;
_userManager = userManager;
_siteDbContext = siteDbContext;
_augeasManager = augeasManager;
}
/// <summary>
/// Gets the sites stored in the database.
/// </summary>
/// <param name="skip"></param>
/// <param name="take"></param>
/// <param name="orderDir"></param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public ActionResult GetSites(
int skip = 0, int take = 50, int orderDir = 1)
{
var (success, sites) = _siteDbContext.GetSites(skip, take, orderDir);
if (!success) return new NotFoundResult();
return Ok(sites);
}
/// <summary>
/// Gets a site by Id.
/// </summary>
/// <param name="siteId">Site id.</param>
/// <returns></returns>
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[HttpGet("{siteId}", Name = nameof(GetSiteById))]
public ActionResult GetSiteById(string siteId)
{
var (success, site) = _siteDbContext.GetOneSiteById(siteId);
if (success)
{
return Ok(site);
}
return new NotFoundResult();
}
/// <summary>
/// Adds a site to the database.
/// </summary>
/// <param name="siteToCreate"></param>
/// <returns></returns>
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status406NotAcceptable)]
[HttpPost]
public ActionResult AddSite(SiteCreate siteToCreate)
{
var (success, site) = _siteDbContext.AddSite(siteToCreate);
if (!success) return new BadRequestResult();
return CreatedAtRoute(nameof(GetSiteById), new {countryId = site.Id}, site);
}
} }
} }

View File

@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc;
namespace CodeLiturgy.Views.Controllers namespace CodeLiturgy.Views.Controllers
{ {
public class SystemController : UserController public class SystemController : LoggedInUserController
{ {
public SystemController(ApplicationUserManager userManager, ILogger<SystemController> logger) : base(userManager, logger) public SystemController(ApplicationUserManager userManager, ILogger<SystemController> logger) : base(userManager, logger)
{ {

View File

@ -9,7 +9,6 @@ namespace CodeLiturgy.Domain
/// <summary> /// <summary>
/// Application User Db Context /// Application User Db Context
/// </summary> /// </summary>
[EfGenerator]
public class ApplicationUserDbContext : IdentityDbContext< public class ApplicationUserDbContext : IdentityDbContext<
ApplicationUser, ApplicationUser,
ApplicationRole, ApplicationRole,
@ -21,23 +20,17 @@ namespace CodeLiturgy.Domain
ApplicationUserToken> ApplicationUserToken>
{ {
/// <inheritdoc /> /// <inheritdoc />
[EfGetMany(typeof(ApplicationUserClaimUnique))]
public sealed override DbSet<ApplicationUserClaim> UserClaims { get; set; } public sealed override DbSet<ApplicationUserClaim> UserClaims { get; set; }
/// <inheritdoc /> /// <inheritdoc />
[EfGetMany(typeof(ApplicationUserRoleUnique))]
public sealed override DbSet<ApplicationUserRole> UserRoles { get; set; } public sealed override DbSet<ApplicationUserRole> UserRoles { get; set; }
/// <inheritdoc /> /// <inheritdoc />
[EfGetMany(typeof(ApplicationRoleUnique))]
public sealed override DbSet<ApplicationRole> Roles { get; set; } public sealed override DbSet<ApplicationRole> Roles { get; set; }
/// <inheritdoc /> /// <inheritdoc />
[EfGetMany(typeof(ApplicationRoleClaimUnique))]
public sealed override DbSet<ApplicationRoleClaim> RoleClaims { get; set; } public sealed override DbSet<ApplicationRoleClaim> RoleClaims { get; set; }
[EfGetMany(typeof(ApplicationUserUnique))]
[EfUpdateMethods( updateType: typeof(ApplicationUserUnique), returnType: typeof(ApplicationUserUnique), keyPropertyMemberName: nameof(ApplicationUserUnique.Id))]
public sealed override DbSet<ApplicationUser> Users { get; set; } public sealed override DbSet<ApplicationUser> Users { get; set; }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -5,20 +5,12 @@ using CodeLiturgy.Domain.Model;
namespace CodeLiturgy.Domain namespace CodeLiturgy.Domain
{ {
[EfGenerator]
public class SiteDbContext: DbContext public class SiteDbContext: DbContext
{ {
[EfGetOneBy(nameof(Site.Id), typeof(SiteUnique))]
[EfGetOne(typeof(SiteUnique))]
[EfGetMany(typeof(SiteUnique))]
[EfAddMethods(typeof(SiteCreate), typeof(SiteUnique))]
public DbSet<Site> Sites { get; set; } public DbSet<Site> Sites { get; set; }
[EfGetOneBy(nameof(SiteEnvironment.Id), typeof(SiteEnvironmentUnique))]
[EfGetOne(typeof(SiteEnvironmentUnique))]
[EfGetMany(typeof(SiteEnvironmentUnique))]
[EfAddMethods(typeof(SiteEnvironmentCreate), typeof(SiteEnvironmentUnique))]
public DbSet<SiteEnvironment> Environments { get; set; } public DbSet<SiteEnvironment> Environments { get; set; }
/// <summary> /// <summary>

View File

@ -0,0 +1,18 @@
@model dynamic
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>title</title>
</head>
<body>
<div>
</div>
</body>
</html>

View File

@ -22,6 +22,11 @@ internal class LayoutCache
RootLocation, RootLocation,
nameof(HomeController), nameof(HomeController),
new List<RouteRecord>() new List<RouteRecord>()
{
new RouteRecord("Environments", "envs0", "environments", nameof(EnvironmentsApiController), new List<RouteRecord>()),
new RouteRecord("Standalone Sites", "sites0", "sites", nameof(SitesApiController), new List<RouteRecord>()),
}
, ViewType.Root); , ViewType.Root);
#endregion Route Tree #endregion Route Tree
@ -43,6 +48,7 @@ internal class LayoutCache
{ {
var menuToShow = new List<Url>(); var menuToShow = new List<Url>();
// Add Root URL
menuToShow.Add(Root.ToUrl()); menuToShow.Add(Root.ToUrl());
if (!userAuthenticated) if (!userAuthenticated)
@ -50,6 +56,12 @@ internal class LayoutCache
return menuToShow; return menuToShow;
} }
var rootChildrenUrls = Root.Children.Select(x => x.ToUrl()).ToList();
menuToShow = menuToShow
.Concat(rootChildrenUrls)
.ToList();
if (dictionary[HeaderMenuId] is List<Url> headerMenu) if (dictionary[HeaderMenuId] is List<Url> headerMenu)
{ {
menuToShow = menuToShow menuToShow = menuToShow

View File

@ -1,19 +1,46 @@
namespace CodeLiturgy.Views.Utils namespace CodeLiturgy.Views.Utils
{ {
/// <summary>
/// Url container.
/// </summary>
public class Url public class Url
{ {
public string Name; /// <summary>
public string Location; /// Name of the URL
/// </summary>
public readonly string Name;
/// <summary>
/// Location of the URL (URI).
/// </summary>
public readonly string Location;
/// <summary>
/// Url constructor.
/// </summary>
/// <param name="name">Name of the URL</param>
/// <param name="location">Location of the URL (URI).</param>
public Url(string name, string location) public Url(string name, string location)
{ {
Name = name; Name = name;
Location = location; Location = location;
} }
} }
/// <summary>
/// A record representing a main view on the site
/// </summary>
/// <param name="Name">The name of the view</param>
/// <param name="RouteKey">A unique key for this view.</param>
/// <param name="Location">The unique URL for this view.</param>
/// <param name="ControllerName">Controller name.</param>
/// <param name="Children">Children views of this view.</param>
/// <param name="ViewType">Type of this view.</param>
public record RouteRecord(string Name, string RouteKey, string Location, string ControllerName, List<RouteRecord> Children, ViewType ViewType = ViewType.Undefined) public record RouteRecord(string Name, string RouteKey, string Location, string ControllerName, List<RouteRecord> Children, ViewType ViewType = ViewType.Undefined)
{ {
/// <summary>
/// Children to Url List.
/// </summary>
/// <returns></returns>
public List<Url> ChildrenToUrl() public List<Url> ChildrenToUrl()
{ {
return Children.Select(x => x.ToUrl()).ToList(); return Children.Select(x => x.ToUrl()).ToList();

View File

@ -9,7 +9,6 @@ namespace CodeLiturgy.Views
Environments, Environments,
Root, Root,
Undefined Undefined
} }
} }

View File

@ -1,26 +0,0 @@
/// <summary>
/// Adds a new item into {listPropertyName} from {entityTypeName}.
/// </summary>
/// <param name="dbContext">The database context.</param>
/// <param name="{primaryKeyVarName}">The {entityTypeName} key to get</param>
/// <param name="{listItemCreateVarName}">The item to add to {listPropertyName}.</param>
/// <returns>The success of the operation, a message, and a projection of the added item. </returns>
public static (bool, string, {returnTypeFullName}) Add{listEntityTypeName}To{entityTypeName}(this {contextFullName} dbContext,
{primaryKeyFullName} {primaryKeyVarName}, {listEntityCreateFullName} {listItemCreateVarName})
{
var entityQuery = from aEntity in dbContext.{propertyName}
where aEntity.{primaryKeyPropertyName} == {primaryKeyVarName}
let itemsInList = aEntity.{listPropertyName}
select aEntity;
var entity = entityQuery.FirstOrDefault();
if (entity == null) return (false, $"{entityTypeName} Not found.", null);
var newListItem = new {listEntityFullName}({listItemCreateVarName});
entity.{listPropertyName}.Add(newListItem);
var success = dbContext.SaveChanges() >= 0;
return !success ? (false, "Error saving changes in the Database. Action: Create {listEntityTypeName} in {entityTypeName}.", null) :
(true, string.Empty, new {returnTypeFullName}(newListItem));
}

View File

@ -1,13 +0,0 @@
/// <summary>
/// Adds a new {entityTypeName} and returns a projection of type {returnTypeFullName}.
/// </summary>
/// <param name="dbContext">The database context.</param>
/// <param name="{toCreateVarName}">Projection data of {entityTypeName}</param>
/// <returns>The added data.</returns>
public static (bool, {returnTypeFullName}) Add{entityTypeName}(this {contextFullName} dbContext, {createTypeFullName} {toCreateVarName})
{
var {newEntityVarName} = new {entityTypeFullName}({toCreateVarName});
dbContext.{propertyName}.Add({newEntityVarName});
var success = dbContext.SaveChanges() >= 0;
return (success, new {returnTypeFullName}({newEntityVarName}));
}

View File

@ -1,33 +0,0 @@
/// <summary>
/// Gets {listPropertyName} in {entityTypeName}.
/// </summary>
/// <param name="dbContext">The database context.</param>
/// <param name="{primaryKeyVarName}">The {entityTypeName} key to get</param>
/// <param name="skip">How many {propertyName} to skip.</param>
/// <param name="take">How many {propertyName} to take. (Default = 50)</param>
/// <param name="orderDir">Optional Order direction</param>
/// <param name="orderBy">Optional order by predicate.</param>
/// <returns>A bool if there's at least one record found and the resulting array. </returns>
public static (bool, {returnTypeFullName}[]) Get{entityTypeName}{listPropertyName}(this {contextFullName} dbContext, {primaryKeyFullName} {primaryKeyVarName},
int skip = 0, int take = 50, int orderDir = 1,
Expression<Func<{returnTypeFullName}, bool>> orderBy = null)
{
var {entityObjectVarName} = dbContext.{propertyName}.FirstOrDefault(d => d.{primaryKeyPropertyName} == {primaryKeyVarName});
if ({entityObjectVarName} == null) return (false, null);
var currentTake = take;
if (take > 200) currentTake = 200;
var query = dbContext
.{propertyName}
.Where(data => data.{primaryKeyPropertyName} == {primaryKeyVarName})
.SelectMany(o => o.{listPropertyName})
.Select(x => new {returnTypeFullName}(x))
.Skip(skip)
.Take(currentTake);
if(orderBy != null) query = orderDir == 1 ? query.OrderBy(orderBy) : query.OrderByDescending(orderBy);
return (query.Any(), query.ToArray());
}

View File

@ -1,25 +0,0 @@
/// <summary>
/// Gets {propertyName}.
/// </summary>
/// <param name="dbContext">The database context.</param>
/// <param name="skip">How many {propertyName} to skip.</param>
/// <param name="take">How many {propertyName} to take. (Default = 50)</param>
/// <param name="orderDir">Optional Order direction</param>
/// <param name="where">Optional where predicate.</param>
/// <param name="orderBy">Optional order by predicate.</param>
/// <returns>A bool if the result is successful and a projection of the first occurrence of {propertyName}. </returns>
public static (bool, System.Collections.Generic.List<{returnTypeFullName}>) Get{propertyName}(this {contextFullName} dbContext, int skip = 0, int take = 50, int orderDir = 1)
{
if (take > 200) take = 200;
var query = dbContext
.{propertyName}
.Skip(skip)
.Take(take)
.Select(x => new {returnTypeFullName}(x));
var result = query.ToList();
return (result.Any(), result);
}

View File

@ -1,15 +0,0 @@
/// <summary>
/// Gets the first result in the table, and returns a projection of <see cref="{returnTypeFullName}"></see>
/// </summary>
/// <param name="dbContext">The database context.</param>
/// <param name="{byParamVarName}">By {byParamPropertyName} parameter type.</param>
/// <returns>A projection of {entityTypeName}> </returns>
public static (bool, {returnTypeFullName}) GetOne{entityTypeName}By{byParamPropertyName} (this {contextFullName} dbContext, {byParamFullType} {byParamVarName})
{
var {findEntityVarName} = dbContext.{propertyName}
.Where(x => x.{byParamPropertyName} == {byParamVarName})
.Select(x => new {returnTypeFullName}(x))
.FirstOrDefault();
return ({findEntityVarName} != null, {findEntityVarName});
}

View File

@ -1,20 +0,0 @@
/// <summary>
/// Gets a projection of the first <see cref="{returnTypeFullName}">{listItemTypeName}</see> occurrence.
/// </summary>
/// <param name="dbContext">The <see cref="{contextFullName}">Database</see> context.</param>
/// <param name="{primaryKeyVarName}">{entityTypeName} lookup key.</param>
/// <param name="{listPrimaryKeyVarName}">{listItemTypeName} lookup key.</param>
/// <returns>A <see cref="{returnTypeFullName}">projection</see> of {listItemTypeName} </returns>
public static (bool, {returnTypeFullName}) Get{listItemTypeName}From{entityTypeName} (this {contextFullName} dbContext, {primaryKeyFullName} {primaryKeyVarName},
{listPrimaryKeyFullName} {listPrimaryKeyVarName})
{
var query =
from mainEntity in dbContext.{propertyName}
where mainEntity.{primaryKeyPropertyName} == {primaryKeyVarName}
let list = mainEntity.{listPropertyName}
from listItem in list
where listItem.{listPrimaryKeyPropertyName} == {listPrimaryKeyVarName}
select new {returnTypeFullName}(listItem);
return (query.Any(), query.FirstOrDefault());
}

View File

@ -1,17 +0,0 @@
/// <summary>
/// Gets the first result following the query with a expression.
/// </summary>
/// <param name="dbContext">The database context.</param>
/// <param name="with">FirstOrDefault argument to pass.</param>
/// <returns>A bool if the first occurrence of {returnTypeName} is returned.</returns>
public static (bool, {returnTypeFullName}) Get{entityTypeName}With (this {contextFullName} dbContext,
Expression<Func<{returnTypeFullName},bool>> with)
{
var {findEntityVarName} =
dbContext.{propertyName}
.Select(x => new {returnTypeFullName}(x))
.FirstOrDefault(with);
return ({findEntityVarName} != null, {findEntityVarName});
}

View File

@ -1,16 +0,0 @@
/// <summary>
/// Updates {entityTypeName} in the DbSet of <see cref="{contextFullName}"></see>.
/// </summary>
/// <param name="dbContext">Database context</param>
/// <param name="{updateVarName}">The data type with the add data to update {entityTypeName}</param>
/// <param name="{keyVarName}"> The primary key.</param>
/// <returns>Returns the current data.</returns>
public static (bool, {returnTypeFullName}) Update{entityTypeName}( this {contextFullName} dbContext, {updateTypeFullName} {updateVarName}, {keyTypeFullName} {keyVarName})
{
var {existingEntityVarName} = dbContext.{propertyName}.FirstOrDefault(x => x.{keyPropertyName} == {keyVarName});
if ({existingEntityVarName} == null) return (false, null);
{existingEntityVarName}.Update({updateVarName});
dbContext.{propertyName}.Update({existingEntityVarName});
var result = dbContext.SaveChanges() >= 0;
return (result, new {returnTypeFullName}({existingEntityVarName}));
}

View File

@ -0,0 +1,5 @@
<link rel="stylesheet" asp-append-version="true" href="~/static/envs/envs.css" />
<script asp-append-version="true" src="~/static/envs/envs.js" defer></script>
<div id="app"></div>

View File

@ -1,4 +0,0 @@
@*<link rel="stylesheet" asp-append-version="true" href="~/static/envs/index.3635012e.css" />
<script src="~/static/envs/index.e56c5746.js" defer/>*@
<div id="app"></div>

View File

@ -1,35 +1,42 @@
@using CodeLiturgy.Views.Utils @using CodeLiturgy.Views.Utils
@using CodeLiturgy.Data.Auth @using CodeLiturgy.Data.Auth
@using Duende.IdentityServer.Extensions @using Duende.IdentityServer.Extensions
@using Microsoft.Extensions.Hosting.Internal
@{ @{
Layout = null; Layout = null;
var userAuthenticated = User.IsAuthenticated(); var userAuthenticated = User.IsAuthenticated();
var user = ViewData.GetUserViewData(); var user = ViewData.GetUserViewData();
var rootUrl = SessionConstants.CookieDomain; var rootUrl = SessionConstants.CookieDomain;
var menu = LayoutCache.GetDefaultHeaderMenu(ViewData, User.IsAuthenticated()); var menu = LayoutCache.GetDefaultHeaderMenu(ViewData, User.IsAuthenticated());
var isDevelopment = false;
#if DEBUG
isDevelopment = true;
#endif
} }
<div class="menu top"> <div class="menu top">
<div class="row no-wrap middle-align"> <div class="row no-wrap middle-align">
<div class="col">
<nav class="left-align">
@if (menu is {Count: > 0 }) @if (menu is {Count: > 0 })
{ {
@foreach (var record in menu) @foreach (var record in menu)
{ {
<div class="col">
<nav class="left-align">
<a href="@record.Location" class="white-text"> <a href="@record.Location" class="white-text">
@record.Name @record.Name
</a> </a>
}
}
</nav> </nav>
</div> </div>
} <div class="col">
}
@*<div class="col">
<nav class="right-align"> <nav class="right-align">
<a href="#" @if (isDevelopment)
target="_blank"> {
<button class="events-button">See Full Events Calendar</button> <a href="/api/swagger" target="_blank" class="white-text">
Swagger API
</a> </a>
}
</nav> </nav>
</div>*@ </div>
</div> </div>
</div> </div>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long