Remove dependencies of BlueWest.Ef.Methods
This commit is contained in:
parent
70dc2afd1f
commit
869a68ee91
|
@ -4,7 +4,6 @@ using Microsoft.AspNetCore.Identity;
|
|||
namespace CodeLiturgy.Data.Application.Users
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[MapFrom(typeof(ApplicationRoleUnique))]
|
||||
|
||||
public partial class ApplicationRole : IdentityRole<string>
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@ using MapTo;
|
|||
|
||||
namespace CodeLiturgy.Data.Application.Users
|
||||
{
|
||||
[MapFrom(typeof(ApplicationRole))]
|
||||
public partial class ApplicationRoleUnique
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
|
|
@ -6,7 +6,6 @@ namespace CodeLiturgy.Data.Application.Users
|
|||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
[MapFrom(typeof(ApplicationRoleClaimUnique))]
|
||||
|
||||
public partial class ApplicationRoleClaim : IdentityRoleClaim<string>
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@ using MapTo;
|
|||
|
||||
namespace CodeLiturgy.Data.Application.Users
|
||||
{
|
||||
[MapFrom(typeof(ApplicationRoleClaim))]
|
||||
public partial class ApplicationRoleClaimUnique
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
|
|
@ -13,8 +13,6 @@ namespace CodeLiturgy.Data.Application.Users
|
|||
/// <summary>
|
||||
/// Application User in the Identity System.
|
||||
/// </summary>
|
||||
[MapFrom(typeof(ApplicationUserUnique))]
|
||||
[UseUpdate]
|
||||
public partial class ApplicationUser : IdentityUser<string>
|
||||
{
|
||||
public new string Id { get; set; }
|
||||
|
|
|
@ -3,7 +3,6 @@ using MapTo;
|
|||
|
||||
namespace CodeLiturgy.Data.Application.Users
|
||||
{
|
||||
[MapFrom(typeof(ApplicationUser))]
|
||||
public partial class ApplicationUserUnique
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
|
|
@ -3,7 +3,6 @@ using MapTo;
|
|||
|
||||
namespace CodeLiturgy.Data.Application.Users
|
||||
{
|
||||
[MapFrom(typeof(ApplicationUserClaimUnique))]
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class ApplicationUserClaim : IdentityUserClaim<string>
|
||||
|
|
|
@ -2,7 +2,6 @@ using MapTo;
|
|||
|
||||
namespace CodeLiturgy.Data.Application.Users
|
||||
{
|
||||
[MapFrom(typeof(ApplicationUserClaim))]
|
||||
public partial class ApplicationUserClaimUnique
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace CodeLiturgy.Data.Application.Users
|
|||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
[MapFrom(typeof(ApplicationUserRoleUnique))]
|
||||
|
||||
public partial class ApplicationUserRole : IdentityUserRole<string>
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@ using MapTo;
|
|||
|
||||
namespace CodeLiturgy.Data.Application.Users
|
||||
{
|
||||
[MapFrom(typeof(ApplicationUserRole))]
|
||||
public partial class ApplicationUserRoleUnique
|
||||
{
|
||||
public string UserId { get; set; }
|
||||
|
|
|
@ -6,11 +6,6 @@ using MapTo;
|
|||
namespace CodeLiturgy.Data.Application
|
||||
{
|
||||
|
||||
[MapFrom(new []
|
||||
{
|
||||
typeof(SiteUnique),
|
||||
typeof(SiteCreate)
|
||||
})]
|
||||
|
||||
public partial class Site
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@ using MapTo;
|
|||
|
||||
namespace CodeLiturgy.Data.Application
|
||||
{
|
||||
[MapFrom(typeof(Site))]
|
||||
public partial class SiteCreate
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
|
|
@ -4,7 +4,6 @@ using MapTo;
|
|||
|
||||
namespace CodeLiturgy.Data.Application
|
||||
{
|
||||
[MapFrom(new [] {typeof(SiteEnvironmentCreate)})]
|
||||
|
||||
public partial class SiteEnvironment
|
||||
{
|
||||
|
|
|
@ -4,7 +4,6 @@ using MapTo;
|
|||
|
||||
namespace CodeLiturgy.Data.Application
|
||||
{
|
||||
[MapFrom(typeof(SiteEnvironment))]
|
||||
public partial class SiteEnvironmentCreate
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
|
|
@ -4,7 +4,6 @@ using MapTo;
|
|||
|
||||
namespace CodeLiturgy.Data.Application
|
||||
{
|
||||
[MapFrom(typeof(SiteEnvironment))]
|
||||
public partial class SiteEnvironmentUnique
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
|
|
@ -3,8 +3,6 @@ using MapTo;
|
|||
|
||||
namespace CodeLiturgy.Data.Application
|
||||
{
|
||||
|
||||
[MapFrom(typeof(Site))]
|
||||
public partial class SiteUnique
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BlueWest.EfMethods" Version="0.9.9-g05eef7070f" />
|
||||
<PackageReference Include="MapTo" Version="0.9.41-gcfa46bb014" />
|
||||
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.9" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.11" />
|
||||
|
@ -136,19 +135,12 @@
|
|||
|
||||
|
||||
<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\EnvironmentsPage\Index.cshtml" />
|
||||
<AdditionalFiles Include="Views\Environments\Index.cshtml" />
|
||||
</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\Sharp.Augeas\Sharp.Augeas\Sharp.Augeas.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -7,7 +7,7 @@ using CodeLiturgy.Views.Utils;
|
|||
|
||||
namespace CodeLiturgy.Views.Controllers;
|
||||
|
||||
public class AccountController : UserController
|
||||
public class AccountController : LoggedInUserController
|
||||
{
|
||||
public AccountController(
|
||||
ApplicationUserManager userManager,
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace CodeLiturgy.Views.Controllers
|
|||
[Authorize]
|
||||
public class ApacheController : ControllerBase
|
||||
{
|
||||
private ILogger<SitesController> _logger;
|
||||
private ILogger<SitesApiController> _logger;
|
||||
private readonly SiteDbContext _siteDbContext;
|
||||
private readonly AugeasManager _augeasManager;
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace CodeLiturgy.Views.Controllers
|
|||
/// <param name="augeasManager"></param>
|
||||
public ApacheController(
|
||||
ApplicationUserManager userManager,
|
||||
ILogger<SitesController> logger,
|
||||
ILogger<SitesApiController> logger,
|
||||
SiteDbContext siteDbContext,
|
||||
AugeasManager augeasManager)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ using Controller = Microsoft.AspNetCore.Mvc.Controller;
|
|||
|
||||
namespace CodeLiturgy.Views.Controllers
|
||||
{
|
||||
public class AuthController : UserController
|
||||
public class AuthController : LoggedInUserController
|
||||
{
|
||||
|
||||
private readonly IAuthManager _authManager;
|
||||
|
|
|
@ -3,17 +3,18 @@ using CodeLiturgy.Data.Auth.Context.Users;
|
|||
using CodeLiturgy.Domain;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace CodeLiturgy.Views.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class EnvironmentController : ControllerBase
|
||||
public class EnvironmentsApiController : ControllerBase
|
||||
{
|
||||
private ApplicationUserManager _userManager;
|
||||
private ILogger<SitesController> _logger;
|
||||
private ILogger<SitesApiController> _logger;
|
||||
private readonly SiteDbContext _siteDbContext;
|
||||
public EnvironmentController(ApplicationUserManager userManager, ILogger<SitesController> logger, SiteDbContext siteDbContext)
|
||||
public EnvironmentsApiController(ApplicationUserManager userManager, ILogger<SitesApiController> logger, SiteDbContext siteDbContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_userManager = userManager;
|
||||
|
@ -22,16 +23,13 @@ namespace CodeLiturgy.Views.Controllers
|
|||
|
||||
[HttpGet("/api/environments")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
|
||||
public ActionResult GetEnvironments(
|
||||
public async Task<ActionResult> GetEnvironments(
|
||||
|
||||
int skip = 0, int take = 50, int orderDir = 1)
|
||||
{
|
||||
var (success, sites) = _siteDbContext.GetEnvironments(skip, take, orderDir);
|
||||
|
||||
if (!success) return new NotFoundResult();
|
||||
var sites = _siteDbContext.Environments.Skip(skip).Take(take).ToListAsync();
|
||||
|
||||
return Ok(sites);
|
||||
}
|
||||
|
@ -41,13 +39,16 @@ namespace CodeLiturgy.Views.Controllers
|
|||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[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)
|
||||
{
|
||||
return Ok(result);
|
||||
return Ok(newEnvironment);
|
||||
}
|
||||
|
||||
return BadRequest();
|
||||
|
@ -64,11 +65,11 @@ namespace CodeLiturgy.Views.Controllers
|
|||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||
|
||||
[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);
|
||||
}
|
|
@ -6,11 +6,11 @@ using Microsoft.AspNetCore.Mvc;
|
|||
namespace CodeLiturgy.Views.Controllers;
|
||||
|
||||
|
||||
public class EnvironmentsPageController : UserController
|
||||
public class EnvironmentsController : LoggedInUserController
|
||||
{
|
||||
public EnvironmentsPageController(
|
||||
public EnvironmentsController(
|
||||
ApplicationUserManager userManager,
|
||||
ILogger<UserController> logger)
|
||||
ILogger<LoggedInUserController> logger)
|
||||
: base(userManager, logger) { }
|
||||
|
||||
public override void OnInitialization()
|
|
@ -7,7 +7,7 @@ namespace CodeLiturgy.Views.Controllers;
|
|||
|
||||
[System.Web.Mvc.Route("/")]
|
||||
[System.Web.Mvc.Authorize]
|
||||
public class HomeController : UserController
|
||||
public class HomeController : LoggedInUserController
|
||||
{
|
||||
public HomeController(
|
||||
ApplicationUserManager userManager,
|
||||
|
|
|
@ -10,15 +10,18 @@ using Microsoft.AspNetCore.Mvc;
|
|||
|
||||
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;
|
||||
|
||||
private List<Url> _footerMenu;
|
||||
private List<Url> _headerMenu;
|
||||
|
||||
public UserController(ApplicationUserManager userManager, ILogger<UserController> logger)
|
||||
public LoggedInUserController(ApplicationUserManager userManager, ILogger<LoggedInUserController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_userManager = userManager;
|
||||
|
@ -76,7 +79,15 @@ public class UserController : Controller
|
|||
ApplicationUser user = await _userManager.GetUserAsync(User);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
namespace CodeLiturgy.Views.Controllers;
|
||||
|
||||
namespace CodeLiturgy.Views.Controllers
|
||||
public class SitesController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Controller responsible for managing websites.
|
||||
/// </summary>
|
||||
[Route("api/sites")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
|
||||
public class SitesController : ControllerBase
|
||||
// GET
|
||||
public IActionResult Index()
|
||||
{
|
||||
private ApplicationUserManager _userManager;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
return View();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||
|
||||
namespace CodeLiturgy.Views.Controllers
|
||||
{
|
||||
public class SystemController : UserController
|
||||
public class SystemController : LoggedInUserController
|
||||
{
|
||||
public SystemController(ApplicationUserManager userManager, ILogger<SystemController> logger) : base(userManager, logger)
|
||||
{
|
||||
|
|
|
@ -9,7 +9,6 @@ namespace CodeLiturgy.Domain
|
|||
/// <summary>
|
||||
/// Application User Db Context
|
||||
/// </summary>
|
||||
[EfGenerator]
|
||||
public class ApplicationUserDbContext : IdentityDbContext<
|
||||
ApplicationUser,
|
||||
ApplicationRole,
|
||||
|
@ -21,23 +20,17 @@ namespace CodeLiturgy.Domain
|
|||
ApplicationUserToken>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[EfGetMany(typeof(ApplicationUserClaimUnique))]
|
||||
public sealed override DbSet<ApplicationUserClaim> UserClaims { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[EfGetMany(typeof(ApplicationUserRoleUnique))]
|
||||
public sealed override DbSet<ApplicationUserRole> UserRoles { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[EfGetMany(typeof(ApplicationRoleUnique))]
|
||||
public sealed override DbSet<ApplicationRole> Roles { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
[EfGetMany(typeof(ApplicationRoleClaimUnique))]
|
||||
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; }
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
@ -5,20 +5,12 @@ using CodeLiturgy.Domain.Model;
|
|||
|
||||
namespace CodeLiturgy.Domain
|
||||
{
|
||||
[EfGenerator]
|
||||
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; }
|
||||
|
||||
[EfGetOneBy(nameof(SiteEnvironment.Id), typeof(SiteEnvironmentUnique))]
|
||||
[EfGetOne(typeof(SiteEnvironmentUnique))]
|
||||
[EfGetMany(typeof(SiteEnvironmentUnique))]
|
||||
[EfAddMethods(typeof(SiteEnvironmentCreate), typeof(SiteEnvironmentUnique))]
|
||||
public DbSet<SiteEnvironment> Environments { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
@model dynamic
|
||||
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>title</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -22,6 +22,11 @@ internal class LayoutCache
|
|||
RootLocation,
|
||||
nameof(HomeController),
|
||||
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);
|
||||
|
||||
#endregion Route Tree
|
||||
|
@ -43,6 +48,7 @@ internal class LayoutCache
|
|||
{
|
||||
var menuToShow = new List<Url>();
|
||||
|
||||
// Add Root URL
|
||||
menuToShow.Add(Root.ToUrl());
|
||||
|
||||
if (!userAuthenticated)
|
||||
|
@ -50,6 +56,12 @@ internal class LayoutCache
|
|||
return menuToShow;
|
||||
}
|
||||
|
||||
var rootChildrenUrls = Root.Children.Select(x => x.ToUrl()).ToList();
|
||||
|
||||
menuToShow = menuToShow
|
||||
.Concat(rootChildrenUrls)
|
||||
.ToList();
|
||||
|
||||
if (dictionary[HeaderMenuId] is List<Url> headerMenu)
|
||||
{
|
||||
menuToShow = menuToShow
|
||||
|
|
|
@ -1,19 +1,46 @@
|
|||
namespace CodeLiturgy.Views.Utils
|
||||
{
|
||||
/// <summary>
|
||||
/// Url container.
|
||||
/// </summary>
|
||||
public class Url
|
||||
{
|
||||
public string Name;
|
||||
public string Location;
|
||||
/// <summary>
|
||||
/// 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)
|
||||
{
|
||||
Name = name;
|
||||
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)
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Children to Url List.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<Url> ChildrenToUrl()
|
||||
{
|
||||
return Children.Select(x => x.ToUrl()).ToList();
|
||||
|
|
|
@ -9,7 +9,6 @@ namespace CodeLiturgy.Views
|
|||
Environments,
|
||||
Root,
|
||||
Undefined
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
|
@ -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}));
|
||||
}
|
|
@ -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());
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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});
|
||||
}
|
|
@ -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());
|
||||
}
|
|
@ -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});
|
||||
|
||||
}
|
|
@ -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}));
|
||||
}
|
|
@ -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>
|
||||
|
|
@ -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>
|
||||
|
|
@ -1,35 +1,42 @@
|
|||
@using CodeLiturgy.Views.Utils
|
||||
@using CodeLiturgy.Data.Auth
|
||||
@using Duende.IdentityServer.Extensions
|
||||
@using Microsoft.Extensions.Hosting.Internal
|
||||
@{
|
||||
Layout = null;
|
||||
var userAuthenticated = User.IsAuthenticated();
|
||||
var user = ViewData.GetUserViewData();
|
||||
var rootUrl = SessionConstants.CookieDomain;
|
||||
var menu = LayoutCache.GetDefaultHeaderMenu(ViewData, User.IsAuthenticated());
|
||||
var isDevelopment = false;
|
||||
#if DEBUG
|
||||
isDevelopment = true;
|
||||
#endif
|
||||
}
|
||||
<div class="menu top">
|
||||
<div class="row no-wrap middle-align">
|
||||
<div class="col">
|
||||
<nav class="left-align">
|
||||
@if (menu is {Count: > 0 })
|
||||
{
|
||||
@foreach (var record in menu)
|
||||
{
|
||||
<div class="col">
|
||||
<nav class="left-align">
|
||||
<a href="@record.Location" class="white-text">
|
||||
@record.Name
|
||||
</a>
|
||||
}
|
||||
}
|
||||
</nav>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@*<div class="col">
|
||||
<div class="col">
|
||||
<nav class="right-align">
|
||||
<a href="#"
|
||||
target="_blank">
|
||||
<button class="events-button">See Full Events Calendar</button>
|
||||
@if (isDevelopment)
|
||||
{
|
||||
<a href="/api/swagger" target="_blank" class="white-text">
|
||||
Swagger API
|
||||
</a>
|
||||
}
|
||||
</nav>
|
||||
</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
Loading…
Reference in New Issue