Merge pull request #683 from sbwalker/master

resolve #526 remove pluralization from module creation templates
This commit is contained in:
Shaun Walker 2020-08-14 09:44:44 -07:00 committed by GitHub
commit 20c8f1528d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 346 additions and 358 deletions

View File

@ -16,7 +16,7 @@
</tr>
<tr>
<td>
<Label For="module" HelpText="Enter a name for this module. It should be in singular form (ie. Car) and not contain spaces or punctuation.">Module Name: </Label>
<Label For="module" HelpText="Enter a name for this module. It should not contain spaces or punctuation.">Module Name: </Label>
</td>
<td>
<input id="module" class="form-control" @bind="@_module" />

View File

@ -175,14 +175,14 @@ namespace Oqtane.Controllers
if (moduleDefinition.Template == "internal")
{
rootPath = Utilities.PathCombine(rootFolder.FullName,Path.DirectorySeparatorChar.ToString());
moduleDefinition.ModuleDefinitionName = moduleDefinition.Owner + "." + moduleDefinition.Name + "s, Oqtane.Client";
moduleDefinition.ServerManagerType = moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Manager." + moduleDefinition.Name + "Manager, Oqtane.Server";
moduleDefinition.ModuleDefinitionName = moduleDefinition.Owner + "." + moduleDefinition.Name + ", Oqtane.Client";
moduleDefinition.ServerManagerType = moduleDefinition.Owner + "." + moduleDefinition.Name + ".Manager." + moduleDefinition.Name + "Manager, Oqtane.Server";
}
else
{
rootPath = Utilities.PathCombine(rootFolder.Parent.FullName , moduleDefinition.Owner + "." + moduleDefinition.Name + "s",Path.DirectorySeparatorChar.ToString());
moduleDefinition.ModuleDefinitionName = moduleDefinition.Owner + "." + moduleDefinition.Name + "s, " + moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Client.Oqtane";
moduleDefinition.ServerManagerType = moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Manager." + moduleDefinition.Name + "Manager, " + moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Server.Oqtane";
rootPath = Utilities.PathCombine(rootFolder.Parent.FullName , moduleDefinition.Owner + "." + moduleDefinition.Name,Path.DirectorySeparatorChar.ToString());
moduleDefinition.ModuleDefinitionName = moduleDefinition.Owner + "." + moduleDefinition.Name + ", " + moduleDefinition.Owner + "." + moduleDefinition.Name + ".Client.Oqtane";
moduleDefinition.ServerManagerType = moduleDefinition.Owner + "." + moduleDefinition.Name + ".Manager." + moduleDefinition.Name + "Manager, " + moduleDefinition.Owner + "." + moduleDefinition.Name + ".Server.Oqtane";
}
ProcessTemplatesRecursively(new DirectoryInfo(templatePath), rootPath, rootFolder.Name, templatePath, moduleDefinition);
@ -196,8 +196,8 @@ namespace Oqtane.Controllers
{
// add embedded resources to project
List<string> resources = new List<string>();
resources.Add(Utilities.PathCombine("Modules", moduleDefinition.Owner + "." + moduleDefinition.Name + "s", "Scripts", moduleDefinition.Owner + "." + moduleDefinition.Name + "s.1.0.0.sql"));
resources.Add(Utilities.PathCombine("Modules", moduleDefinition.Owner + "." + moduleDefinition.Name + "s", "Scripts", moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Uninstall.sql"));
resources.Add(Utilities.PathCombine("Modules", moduleDefinition.Owner + "." + moduleDefinition.Name, "Scripts", moduleDefinition.Owner + "." + moduleDefinition.Name + ".1.0.0.sql"));
resources.Add(Utilities.PathCombine("Modules", moduleDefinition.Owner + "." + moduleDefinition.Name, "Scripts", moduleDefinition.Owner + "." + moduleDefinition.Name + ".Uninstall.sql"));
EmbedResourceFiles(Utilities.PathCombine(rootPath, "Oqtane.Server", "Oqtane.Server.csproj"), resources);
}

View File

@ -342,46 +342,48 @@ namespace Oqtane.Infrastructure
if (!string.IsNullOrEmpty(moduledefinition.ReleaseVersions) && !string.IsNullOrEmpty(moduledefinition.ServerManagerType))
{
Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
string[] versions = moduledefinition.ReleaseVersions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
using (var db = new InstallationContext(NormalizeConnectionString(_config.GetConnectionString(SettingKeys.ConnectionStringKey))))
if (moduletype != null)
{
foreach (var tenant in db.Tenant.ToList())
string[] versions = moduledefinition.ReleaseVersions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
using (var db = new InstallationContext(NormalizeConnectionString(_config.GetConnectionString(SettingKeys.ConnectionStringKey))))
{
int index = Array.FindIndex(versions, item => item == moduledefinition.Version);
if (tenant.Name == install.TenantName && install.TenantName != Constants.MasterTenant)
foreach (var tenant in db.Tenant.ToList())
{
index = -1;
}
if (index != (versions.Length - 1))
{
if (index == -1) index = 0;
for (int i = index; i < versions.Length; i++)
int index = Array.FindIndex(versions, item => item == moduledefinition.Version);
if (tenant.Name == install.TenantName && install.TenantName != Constants.MasterTenant)
{
try
index = -1;
}
if (index != (versions.Length - 1))
{
if (index == -1) index = 0;
for (int i = index; i < versions.Length; i++)
{
if (moduletype.GetInterface("IInstallable") != null)
try
{
var moduleobject = ActivatorUtilities.CreateInstance(scope.ServiceProvider, moduletype);
if (moduletype.GetInterface("IInstallable") != null)
{
var moduleobject = ActivatorUtilities.CreateInstance(scope.ServiceProvider, moduletype);
((IInstallable)moduleobject).Install(tenant, versions[i]);
}
else
{
sql.ExecuteScript(tenant, moduletype.Assembly, Utilities.GetTypeName(moduledefinition.ModuleDefinitionName) + "." + versions[i] + ".sql");
}
}
else
catch (Exception ex)
{
sql.ExecuteScript(tenant, moduletype.Assembly, Utilities.GetTypeName(moduledefinition.ModuleDefinitionName) + "." + versions[i] + ".sql");
result.Message = "An Error Occurred Installing " + moduledefinition.Name + " Version " + versions[i] + " - " + ex.Message.ToString();
}
}
catch (Exception ex)
{
result.Message = "An Error Occurred Installing " + moduledefinition.Name + " Version " + versions[i] + " - " + ex.Message.ToString();
}
}
}
}
if (string.IsNullOrEmpty(result.Message) && moduledefinition.Version != versions[versions.Length - 1])
{
moduledefinition.Version = versions[versions.Length - 1];
db.Entry(moduledefinition).State = EntityState.Modified;
db.SaveChanges();
if (string.IsNullOrEmpty(result.Message) && moduledefinition.Version != versions[versions.Length - 1])
{
moduledefinition.Version = versions[versions.Length - 1];
db.Entry(moduledefinition).State = EntityState.Modified;
db.SaveChanges();
}
}
}
}

View File

@ -1,8 +1,8 @@
@using Oqtane.Modules.Controls
@using [Owner].[Module]s.Services
@using [Owner].[Module]s.Models
@using [Owner].[Module].Services
@using [Owner].[Module].Models
@namespace [Owner].[Module]s
@namespace [Owner].[Module]
@inherits ModuleBase
@inject I[Module]Service [Module]Service
@inject NavigationManager NavigationManager
@ -31,6 +31,8 @@
public override string Actions => "Add,Edit";
public override string Title => "Manage [Module]";
public override List<Resource> Resources => new List<Resource>()
{
new Resource { ResourceType = ResourceType.Stylesheet, Url = ModulePath() + "Module.css" }

View File

@ -1,7 +1,7 @@
@using [Owner].[Module]s.Services
@using [Owner].[Module]s.Models
@using [Owner].[Module].Services
@using [Owner].[Module].Models
@namespace [Owner].[Module]s
@namespace [Owner].[Module]
@inherits ModuleBase
@inject I[Module]Service [Module]Service
@inject NavigationManager NavigationManager
@ -17,16 +17,16 @@ else
<br />
@if (@_[Module]s.Count != 0)
{
<Pager Items="@_[Module]s" Format="Grid">
<Pager Items="@_[Module]s">
<Header>
<div class="col"><strong>[Module]s</strong></div>
<th style="width: 1px;">&nbsp;</th>
<th style="width: 1px;">&nbsp;</th>
<th>Name</th>
</Header>
<Row>
<div class="col">
<ActionLink Action="Edit" Parameters="@($"id=" + context.[Module]Id.ToString())" />
<ActionDialog Header="Delete [Module]" Message="@("Are You Sure You Wish To Delete The " + context.Name + " [Module]?")" Action="Delete" Security="SecurityAccessLevel.Edit" Class="btn btn-danger" OnClick="@(async () => await Delete(context))" />
@context.Name
</div>
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.[Module]Id.ToString())" /></td>
<td><ActionDialog Header="Delete [Module]" Message="@("Are You Sure You Wish To Delete The " + context.Name + " [Module]?")" Action="Delete" Security="SecurityAccessLevel.Edit" Class="btn btn-danger" OnClick="@(async () => await Delete(context))" /></td>
<td>@context.Name</td>
</Row>
</Pager>
}
@ -41,7 +41,7 @@ else
<hr />
[Module] Module Created Successfully. Use Edit Mode To Add A [Module]. You Can Access The Files At The Following Locations:<br /><br />
[RootPath]Client\<br />
- [Owner].[Module]s.Client.csproj - client project<br />
- [Owner].[Module].Client.csproj - client project<br />
- _Imports.razor - global imports for module components<br />
- Edit.razor - component for adding or editing content<br />
- Index.razor - main component for your module **the content you are reading is in this file**<br />
@ -50,22 +50,22 @@ else
- Services\I[Module]Service.cs - interface for defining service API methods<br />
- Services\[Module]Service.cs - implements service API interface methods<br /><br />
[RootPath]Package\<br />
- [Owner].[Module]s.nuspec - nuget manifest for packaging module<br />
- [Owner].[Module]s.Package.csproj - packaging project<br />
- [Owner].[Module].nuspec - nuget manifest for packaging module<br />
- [Owner].[Module].Package.csproj - packaging project<br />
- debug.cmd - copies assemblies to Oqtane bin folder when in Debug mode<br />
- release.cmd - creates nuget package and deploys to Oqtane wwwroot/modules folder when in Release mode<br /><br />
[RootPath]Server\<br />
- [Owner].[Module]s.Server.csproj - server project<br />
- [Owner].[Module].Server.csproj - server project<br />
- Controllers\[Module]Controller.cs - API methods implemented using a REST pattern<br />
- Manager\[Module]Manager.cs - implements optional module interfaces for features such as import/export of content<br />
- Repository\I[Module]Repository.cs - interface for defining repository methods<br />
- Repository\[Module]Respository.cs - implements repository interface methods for data access using EF Core<br />
- Repository\[Module]Context.cs - provides a DB Context for data access<br />
- Scripts\[Owner].[Module]s.1.0.0.sql - database schema definition script<br />
- Scripts\[Owner].[Module]s.Uninstall.sql - database uninstall script<br />
- Scripts\[Owner].[Module].1.0.0.sql - database schema definition script<br />
- Scripts\[Owner].[Module].Uninstall.sql - database uninstall script<br />
- wwwroot\Module.css - module style sheet<br /><br />
[RootPath]Shared\<br />
- [Owner].[Module]s.csproj - shared project<br />
- [Owner].[Module].csproj - shared project<br />
- Models\[Module].cs - model definition<br /><br />
<!-- The content above is for informational purposes only and can be safely removed -->

View File

@ -1,7 +1,7 @@
using Oqtane.Models;
using Oqtane.Modules;
namespace [Owner].[Module]s
namespace [Owner].[Module]
{
public class ModuleInfo : IModule
{
@ -12,7 +12,7 @@ namespace [Owner].[Module]s
Version = "1.0.0",
ServerManagerType = "[ServerManagerType]",
ReleaseVersions = "1.0.0",
Dependencies = "[Owner].[Module]s.Shared.Oqtane"
Dependencies = "[Owner].[Module].Shared.Oqtane"
};
}
}

View File

@ -1,18 +1,18 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using [Owner].[Module]s.Models;
using [Owner].[Module].Models;
namespace [Owner].[Module]s.Services
namespace [Owner].[Module].Services
{
public interface I[Module]Service
{
Task<List<[Module]>> Get[Module]sAsync(int ModuleId);
Task<List<Models.[Module]>> Get[Module]sAsync(int ModuleId);
Task<[Module]> Get[Module]Async(int [Module]Id, int ModuleId);
Task<Models.[Module]> Get[Module]Async(int [Module]Id, int ModuleId);
Task<[Module]> Add[Module]Async([Module] [Module]);
Task<Models.[Module]> Add[Module]Async(Models.[Module] [Module]);
Task<[Module]> Update[Module]Async([Module] [Module]);
Task<Models.[Module]> Update[Module]Async(Models.[Module] [Module]);
Task Delete[Module]Async(int [Module]Id, int ModuleId);
}

View File

@ -5,9 +5,9 @@ using System.Threading.Tasks;
using Oqtane.Modules;
using Oqtane.Services;
using Oqtane.Shared;
using [Owner].[Module]s.Models;
using [Owner].[Module].Models;
namespace [Owner].[Module]s.Services
namespace [Owner].[Module].Services
{
public class [Module]Service : ServiceBase, I[Module]Service, IService
{
@ -20,42 +20,30 @@ namespace [Owner].[Module]s.Services
private string Apiurl => CreateApiUrl(_siteState.Alias, "[Module]");
public async Task<List<[Module]>> Get[Module]sAsync(int ModuleId)
public async Task<List<Models.[Module]>> Get[Module]sAsync(int ModuleId)
{
List<[Module]> [Module]s = await GetJsonAsync<List<[Module]>>(CreateAuthPolicyUrl($"{Apiurl}?moduleid={ModuleId}", ModuleId));
List<Models.[Module]> [Module]s = await GetJsonAsync<List<Models.[Module]>>(CreateAuthorizationPolicyUrl($"{Apiurl}?moduleid={ModuleId}", ModuleId));
return [Module]s.OrderBy(item => item.Name).ToList();
}
public async Task<[Module]> Get[Module]Async(int [Module]Id, int ModuleId)
public async Task<Models.[Module]> Get[Module]Async(int [Module]Id, int ModuleId)
{
return await GetJsonAsync<[Module]>(CreateAuthPolicyUrl($"{Apiurl}/{[Module]Id}", ModuleId));
return await GetJsonAsync<Models.[Module]>(CreateAuthorizationPolicyUrl($"{Apiurl}/{[Module]Id}", ModuleId));
}
public async Task<[Module]> Add[Module]Async([Module] [Module])
public async Task<Models.[Module]> Add[Module]Async(Models.[Module] [Module])
{
return await PostJsonAsync<[Module]>(CreateAuthPolicyUrl($"{Apiurl}", [Module].ModuleId), [Module]);
return await PostJsonAsync<Models.[Module]>(CreateAuthorizationPolicyUrl($"{Apiurl}", [Module].ModuleId), [Module]);
}
public async Task<[Module]> Update[Module]Async([Module] [Module])
public async Task<Models.[Module]> Update[Module]Async(Models.[Module] [Module])
{
return await PutJsonAsync<[Module]>(CreateAuthPolicyUrl($"{Apiurl}/{[Module].[Module]Id}", [Module].ModuleId), [Module]);
return await PutJsonAsync<Models.[Module]>(CreateAuthorizationPolicyUrl($"{Apiurl}/{[Module].[Module]Id}", [Module].ModuleId), [Module]);
}
public async Task Delete[Module]Async(int [Module]Id, int ModuleId)
{
await DeleteAsync(CreateAuthPolicyUrl($"{Apiurl}/{[Module]Id}", ModuleId));
}
private string CreateAuthPolicyUrl(string Url, int ModuleId)
{
if (Url.Contains("?"))
{
return Url + "&entityid=" + ModuleId.ToString();
}
else
{
return Url + "?entityid=" + ModuleId.ToString();
}
await DeleteAsync(CreateAuthorizationPolicyUrl($"{Apiurl}/{[Module]Id}", ModuleId));
}
}
}

View File

@ -1,4 +1,4 @@
@namespace [Owner].[Module]s
@namespace [Owner].[Module]
@inherits ModuleBase
@inject ISettingService SettingService

View File

@ -7,9 +7,9 @@
<Authors>[Owner]</Authors>
<Company>[Owner]</Company>
<Description>[Description]</Description>
<Product>[Owner].[Module]s</Product>
<Product>[Owner].[Module]</Product>
<Copyright>[Owner]</Copyright>
<AssemblyName>[Owner].[Module]s.Client.Oqtane</AssemblyName>
<AssemblyName>[Owner].[Module].Client.Oqtane</AssemblyName>
</PropertyGroup>
<ItemGroup>
@ -21,7 +21,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\[Owner].[Module]s.Shared.csproj" />
<ProjectReference Include="..\Shared\[Owner].[Module].Shared.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -6,9 +6,9 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Client\[Owner].[Module]s.Client.csproj" />
<ProjectReference Include="..\Server\[Owner].[Module]s.Server.csproj" />
<ProjectReference Include="..\Shared\[Owner].[Module]s.Shared.csproj" />
<ProjectReference Include="..\Client\[Owner].[Module].Client.csproj" />
<ProjectReference Include="..\Server\[Owner].[Module].Server.csproj" />
<ProjectReference Include="..\Shared\[Owner].[Module].Shared.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>[Owner].[Module]s</id>
<id>[Owner].[Module]</id>
<version>1.0.0</version>
<authors>[Owner]</authors>
<owners>[Owner]</owners>
<title>[Module]s</title>
<description>[Module]s</description>
<title>[Module]</title>
<description>[Module]</description>
<copyright>[Owner]</copyright>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
@ -20,12 +20,12 @@
</dependencies>
</metadata>
<files>
<file src="..\Client\bin\Release\netstandard2.1\[Owner].[Module]s.Client.Oqtane.dll" target="lib\netstandard2.1" />
<file src="..\Client\bin\Release\netstandard2.1\[Owner].[Module]s.Client.Oqtane.pdb" target="lib\netstandard2.1" />
<file src="..\Server\bin\Release\netcoreapp3.1\[Owner].[Module]s.Server.Oqtane.dll" target="lib\netcoreapp3.1" />
<file src="..\Server\bin\Release\netcoreapp3.1\[Owner].[Module]s.Server.Oqtane.pdb" target="lib\netcoreapp3.1" />
<file src="..\Shared\bin\Release\netstandard2.1\[Owner].[Module]s.Shared.Oqtane.dll" target="lib\netstandard2.1" />
<file src="..\Shared\bin\Release\netstandard2.1\[Owner].[Module]s.Shared.Oqtane.pdb" target="lib\netstandard2.1" />
<file src="..\Client\bin\Release\netstandard2.1\[Owner].[Module].Client.Oqtane.dll" target="lib\netstandard2.1" />
<file src="..\Client\bin\Release\netstandard2.1\[Owner].[Module].Client.Oqtane.pdb" target="lib\netstandard2.1" />
<file src="..\Server\bin\Release\netcoreapp3.1\[Owner].[Module].Server.Oqtane.dll" target="lib\netcoreapp3.1" />
<file src="..\Server\bin\Release\netcoreapp3.1\[Owner].[Module].Server.Oqtane.pdb" target="lib\netcoreapp3.1" />
<file src="..\Shared\bin\Release\netstandard2.1\[Owner].[Module].Shared.Oqtane.dll" target="lib\netstandard2.1" />
<file src="..\Shared\bin\Release\netstandard2.1\[Owner].[Module].Shared.Oqtane.pdb" target="lib\netstandard2.1" />
<file src="..\Server\wwwroot\**\*.*" target="wwwroot" />
</files>
</package>

View File

@ -1,7 +1,7 @@
XCOPY "..\Client\bin\Debug\netstandard2.1\[Owner].[Module]s.Client.Oqtane.dll" "..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\" /Y
XCOPY "..\Client\bin\Debug\netstandard2.1\[Owner].[Module]s.Client.Oqtane.pdb" "..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\" /Y
XCOPY "..\Server\bin\Debug\netcoreapp3.1\[Owner].[Module]s.Server.Oqtane.dll" "..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\" /Y
XCOPY "..\Server\bin\Debug\netcoreapp3.1\[Owner].[Module]s.Server.Oqtane.pdb" "..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\" /Y
XCOPY "..\Shared\bin\Debug\netstandard2.1\[Owner].[Module]s.Shared.Oqtane.dll" "..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\" /Y
XCOPY "..\Shared\bin\Debug\netstandard2.1\[Owner].[Module]s.Shared.Oqtane.pdb" "..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\" /Y
XCOPY "..\Server\wwwroot\Modules\[Owner].[Module]s\*" "..\..\[RootFolder]\Oqtane.Server\wwwroot\Modules\[Owner].[Module]s\" /Y /S /I
XCOPY "..\Client\bin\Debug\netstandard2.1\[Owner].[Module].Client.Oqtane.dll" "..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\" /Y
XCOPY "..\Client\bin\Debug\netstandard2.1\[Owner].[Module].Client.Oqtane.pdb" "..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\" /Y
XCOPY "..\Server\bin\Debug\netcoreapp3.1\[Owner].[Module].Server.Oqtane.dll" "..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\" /Y
XCOPY "..\Server\bin\Debug\netcoreapp3.1\[Owner].[Module].Server.Oqtane.pdb" "..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\" /Y
XCOPY "..\Shared\bin\Debug\netstandard2.1\[Owner].[Module].Shared.Oqtane.dll" "..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\" /Y
XCOPY "..\Shared\bin\Debug\netstandard2.1\[Owner].[Module].Shared.Oqtane.pdb" "..\..\[RootFolder]\Oqtane.Server\bin\Debug\netcoreapp3.1\" /Y
XCOPY "..\Server\wwwroot\Modules\[Owner].[Module]\*" "..\..\[RootFolder]\Oqtane.Server\wwwroot\Modules\[Owner].[Module]\" /Y /S /I

View File

@ -1,2 +1,2 @@
"..\..\[RootFolder]\oqtane.package\nuget.exe" pack [Owner].[Module]s.nuspec
"..\..\[RootFolder]\oqtane.package\nuget.exe" pack [Owner].[Module].nuspec
XCOPY "*.nupkg" "..\..\[RootFolder]\Oqtane.Server\wwwroot\Modules\" /Y

View File

@ -5,21 +5,21 @@ using Microsoft.AspNetCore.Http;
using Oqtane.Shared;
using Oqtane.Enums;
using Oqtane.Infrastructure;
using [Owner].[Module]s.Models;
using [Owner].[Module]s.Repository;
using [Owner].[Module].Models;
using [Owner].[Module].Repository;
namespace [Owner].[Module]s.Controllers
namespace [Owner].[Module].Controllers
{
[Route("{alias}/api/[controller]")]
public class [Module]Controller : Controller
{
private readonly I[Module]Repository _[Module]s;
private readonly I[Module]Repository _[Module]Repository;
private readonly ILogManager _logger;
protected int _entityId = -1;
public [Module]Controller(I[Module]Repository [Module]s, ILogManager logger, IHttpContextAccessor accessor)
public [Module]Controller(I[Module]Repository [Module]Repository, ILogManager logger, IHttpContextAccessor accessor)
{
_[Module]s = [Module]s;
_[Module]Repository = [Module]Repository;
_logger = logger;
if (accessor.HttpContext.Request.Query.ContainsKey("entityid"))
@ -31,17 +31,17 @@ namespace [Owner].[Module]s.Controllers
// GET: api/<controller>?moduleid=x
[HttpGet]
[Authorize(Policy = "ViewModule")]
public IEnumerable<[Module]> Get(string moduleid)
public IEnumerable<Models.[Module]> Get(string moduleid)
{
return _[Module]s.Get[Module]s(int.Parse(moduleid));
return _[Module]Repository.Get[Module]s(int.Parse(moduleid));
}
// GET api/<controller>/5
[HttpGet("{id}")]
[Authorize(Policy = "ViewModule")]
public [Module] Get(int id)
public Models.[Module] Get(int id)
{
[Module] [Module] = _[Module]s.Get[Module](id);
Models.[Module] [Module] = _[Module]Repository.Get[Module](id);
if ([Module] != null && [Module].ModuleId != _entityId)
{
[Module] = null;
@ -52,11 +52,11 @@ namespace [Owner].[Module]s.Controllers
// POST api/<controller>
[HttpPost]
[Authorize(Policy = "EditModule")]
public [Module] Post([FromBody] [Module] [Module])
public Models.[Module] Post([FromBody] Models.[Module] [Module])
{
if (ModelState.IsValid && [Module].ModuleId == _entityId)
{
[Module] = _[Module]s.Add[Module]([Module]);
[Module] = _[Module]Repository.Add[Module]([Module]);
_logger.Log(LogLevel.Information, this, LogFunction.Create, "[Module] Added {[Module]}", [Module]);
}
return [Module];
@ -65,11 +65,11 @@ namespace [Owner].[Module]s.Controllers
// PUT api/<controller>/5
[HttpPut("{id}")]
[Authorize(Policy = "EditModule")]
public [Module] Put(int id, [FromBody] [Module] [Module])
public Models.[Module] Put(int id, [FromBody] Models.[Module] [Module])
{
if (ModelState.IsValid && [Module].ModuleId == _entityId)
{
[Module] = _[Module]s.Update[Module]([Module]);
[Module] = _[Module]Repository.Update[Module]([Module]);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "[Module] Updated {[Module]}", [Module]);
}
return [Module];
@ -80,10 +80,10 @@ namespace [Owner].[Module]s.Controllers
[Authorize(Policy = "EditModule")]
public void Delete(int id)
{
[Module] [Module] = _[Module]s.Get[Module](id);
Models.[Module] [Module] = _[Module]Repository.Get[Module](id);
if ([Module] != null && [Module].ModuleId == _entityId)
{
_[Module]s.Delete[Module](id);
_[Module]Repository.Delete[Module](id);
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "[Module] Deleted {[Module]Id}", id);
}
}

View File

@ -5,36 +5,36 @@ using Oqtane.Modules;
using Oqtane.Models;
using Oqtane.Infrastructure;
using Oqtane.Repository;
using [Owner].[Module]s.Models;
using [Owner].[Module]s.Repository;
using [Owner].[Module].Models;
using [Owner].[Module].Repository;
namespace [Owner].[Module]s.Manager
namespace [Owner].[Module].Manager
{
public class [Module]Manager : IInstallable, IPortable
{
private I[Module]Repository _[Module]s;
private I[Module]Repository _[Module]Repository;
private ISqlRepository _sql;
public [Module]Manager(I[Module]Repository [Module]s, ISqlRepository sql)
public [Module]Manager(I[Module]Repository [Module]Repository, ISqlRepository sql)
{
_[Module]s = [Module]s;
_[Module]Repository = [Module]Repository;
_sql = sql;
}
public bool Install(Tenant tenant, string version)
{
return _sql.ExecuteScript(tenant, GetType().Assembly, "[Owner].[Module]s." + version + ".sql");
return _sql.ExecuteScript(tenant, GetType().Assembly, "[Owner].[Module]." + version + ".sql");
}
public bool Uninstall(Tenant tenant)
{
return _sql.ExecuteScript(tenant, GetType().Assembly, "[Owner].[Module]s.Uninstall.sql");
return _sql.ExecuteScript(tenant, GetType().Assembly, "[Owner].[Module].Uninstall.sql");
}
public string ExportModule(Module module)
{
string content = "";
List<[Module]> [Module]s = _[Module]s.Get[Module]s(module.ModuleId).ToList();
List<Models.[Module]> [Module]s = _[Module]Repository.Get[Module]s(module.ModuleId).ToList();
if ([Module]s != null)
{
content = JsonSerializer.Serialize([Module]s);
@ -44,19 +44,16 @@ namespace [Owner].[Module]s.Manager
public void ImportModule(Module module, string content, string version)
{
List<[Module]> [Module]s = null;
List<Models.[Module]> [Module]s = null;
if (!string.IsNullOrEmpty(content))
{
[Module]s = JsonSerializer.Deserialize<List<[Module]>>(content);
[Module]s = JsonSerializer.Deserialize<List<Models.[Module]>>(content);
}
if ([Module]s != null)
{
foreach([Module] [Module] in [Module]s)
foreach(var [Module] in [Module]s)
{
[Module] _[Module] = new [Module]();
_[Module].ModuleId = module.ModuleId;
_[Module].Name = [Module].Name;
_[Module]s.Add[Module](_[Module]);
_[Module]Repository.Add[Module](new Models.[Module] { ModuleId = module.ModuleId, Name = [Module].Name });
}
}
}

View File

@ -1,14 +1,14 @@
using System.Collections.Generic;
using [Owner].[Module]s.Models;
using [Owner].[Module].Models;
namespace [Owner].[Module]s.Repository
namespace [Owner].[Module].Repository
{
public interface I[Module]Repository
{
IEnumerable<[Module]> Get[Module]s(int ModuleId);
[Module] Get[Module](int [Module]Id);
[Module] Add[Module]([Module] [Module]);
[Module] Update[Module]([Module] [Module]);
IEnumerable<Models.[Module]> Get[Module]s(int ModuleId);
Models.[Module] Get[Module](int [Module]Id);
Models.[Module] Add[Module](Models.[Module] [Module]);
Models.[Module] Update[Module](Models.[Module] [Module]);
void Delete[Module](int [Module]Id);
}
}

View File

@ -2,13 +2,13 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Http;
using Oqtane.Modules;
using Oqtane.Repository;
using [Owner].[Module]s.Models;
using [Owner].[Module].Models;
namespace [Owner].[Module]s.Repository
namespace [Owner].[Module].Repository
{
public class [Module]Context : DBContextBase, IService
{
public virtual DbSet<[Module]> [Module] { get; set; }
public virtual DbSet<Models.[Module]> [Module] { get; set; }
public [Module]Context(ITenantResolver tenantResolver, IHttpContextAccessor accessor) : base(tenantResolver, accessor)
{

View File

@ -2,9 +2,9 @@ using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Collections.Generic;
using Oqtane.Modules;
using [Owner].[Module]s.Models;
using [Owner].[Module].Models;
namespace [Owner].[Module]s.Repository
namespace [Owner].[Module].Repository
{
public class [Module]Repository : I[Module]Repository, IService
{
@ -15,24 +15,24 @@ namespace [Owner].[Module]s.Repository
_db = context;
}
public IEnumerable<[Module]> Get[Module]s(int ModuleId)
public IEnumerable<Models.[Module]> Get[Module]s(int ModuleId)
{
return _db.[Module].Where(item => item.ModuleId == ModuleId);
}
public [Module] Get[Module](int [Module]Id)
public Models.[Module] Get[Module](int [Module]Id)
{
return _db.[Module].Find([Module]Id);
}
public [Module] Add[Module]([Module] [Module])
public Models.[Module] Add[Module](Models.[Module] [Module])
{
_db.[Module].Add([Module]);
_db.SaveChanges();
return [Module];
}
public [Module] Update[Module]([Module] [Module])
public Models.[Module] Update[Module](Models.[Module] [Module])
{
_db.Entry([Module]).State = EntityState.Modified;
_db.SaveChanges();
@ -41,7 +41,7 @@ namespace [Owner].[Module]s.Repository
public void Delete[Module](int [Module]Id)
{
[Module] [Module] = _db.[Module].Find([Module]Id);
Models.[Module] [Module] = _db.[Module].Find([Module]Id);
_db.[Module].Remove([Module]);
_db.SaveChanges();
}

View File

@ -5,17 +5,17 @@
<LangVersion>7.3</LangVersion>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<Version>1.0.0</Version>
<Product>[Owner].[Module]s</Product>
<Product>[Owner].[Module]</Product>
<Authors>[Owner]</Authors>
<Company>[Owner]</Company>
<Description>[Description]</Description>
<Copyright>[Owner]</Copyright>
<AssemblyName>[Owner].[Module]s.Server.Oqtane</AssemblyName>
<AssemblyName>[Owner].[Module].Server.Oqtane</AssemblyName>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Scripts\[Owner].[Module]s.1.0.0.sql" />
<EmbeddedResource Include="Scripts\[Owner].[Module]s.Uninstall.sql" />
<EmbeddedResource Include="Scripts\[Owner].[Module].1.0.0.sql" />
<EmbeddedResource Include="Scripts\[Owner].[Module].Uninstall.sql" />
</ItemGroup>
<ItemGroup>
@ -27,7 +27,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\[Owner].[Module]s.Shared.csproj" />
<ProjectReference Include="..\Shared\[Owner].[Module].Shared.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -2,7 +2,7 @@ using System;
using System.ComponentModel.DataAnnotations.Schema;
using Oqtane.Models;
namespace [Owner].[Module]s.Models
namespace [Owner].[Module].Models
{
[Table("[Owner][Module]")]
public class [Module] : IAuditable

View File

@ -4,12 +4,12 @@
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>7.3</LangVersion>
<Version>1.0.0</Version>
<Product>[Owner].[Module]s</Product>
<Product>[Owner].[Module]</Product>
<Authors>[Owner]</Authors>
<Company>[Owner]</Company>
<Description>[Description]</Description>
<Copyright>[Owner]</Copyright>
<AssemblyName>[Owner].[Module]s.Shared.Oqtane</AssemblyName>
<AssemblyName>[Owner].[Module].Shared.Oqtane</AssemblyName>
</PropertyGroup>
<ItemGroup>

View File

@ -3,13 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28621.142
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "[Owner].[Module]s.Client", "Client\[Owner].[Module]s.Client.csproj", "{AA8E58A1-CD09-4208-BF66-A8BB341FD669}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "[Owner].[Module].Client", "Client\[Owner].[Module].Client.csproj", "{AA8E58A1-CD09-4208-BF66-A8BB341FD669}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "[Owner].[Module]s.Server", "Server\[Owner].[Module]s.Server.csproj", "{04B05448-788F-433D-92C0-FED35122D45A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "[Owner].[Module].Server", "Server\[Owner].[Module].Server.csproj", "{04B05448-788F-433D-92C0-FED35122D45A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "[Owner].[Module]s.Shared", "Shared\[Owner].[Module]s.Shared.csproj", "{18D73F73-D7BE-4388-85BA-FBD9AC96FCA2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "[Owner].[Module].Shared", "Shared\[Owner].[Module].Shared.csproj", "{18D73F73-D7BE-4388-85BA-FBD9AC96FCA2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "[Owner].[Module]s.Package", "Package\[Owner].[Module]s.Package.csproj", "{C5CE512D-CBB7-4545-AF0F-9B6591A0C3A7}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "[Owner].[Module].Package", "Package\[Owner].[Module].Package.csproj", "{C5CE512D-CBB7-4545-AF0F-9B6591A0C3A7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -1,8 +1,8 @@
@using Oqtane.Modules.Controls
@using [Owner].[Module]s.Services
@using [Owner].[Module]s.Models
@using [Owner].[Module].Services
@using [Owner].[Module].Models
@namespace [Owner].[Module]s
@namespace [Owner].[Module]
@inherits ModuleBase
@inject I[Module]Service [Module]Service
@inject NavigationManager NavigationManager
@ -31,6 +31,8 @@
public override string Actions => "Add,Edit";
public override string Title => "Manage [Module]";
public override List<Resource> Resources => new List<Resource>()
{
new Resource { ResourceType = ResourceType.Stylesheet, Url = ModulePath() + "Module.css" }

View File

@ -1,7 +1,7 @@
@using [Owner].[Module]s.Services
@using [Owner].[Module]s.Models
@using [Owner].[Module].Services
@using [Owner].[Module].Models
@namespace [Owner].[Module]s
@namespace [Owner].[Module]
@inherits ModuleBase
@inject I[Module]Service [Module]Service
@inject NavigationManager NavigationManager
@ -17,16 +17,16 @@ else
<br />
@if (@_[Module]s.Count != 0)
{
<Pager Items="@_[Module]s" Format="Grid">
<Pager Items="@_[Module]s">
<Header>
<div class="col"><strong>[Module]s</strong></div>
<th style="width: 1px;">&nbsp;</th>
<th style="width: 1px;">&nbsp;</th>
<th>Name</th>
</Header>
<Row>
<div class="col">
<ActionLink Action="Edit" Parameters="@($"id=" + context.[Module]Id.ToString())" />
<ActionDialog Header="Delete [Module]" Message="@("Are You Sure You Wish To Delete The " + context.Name + " [Module]?")" Action="Delete" Security="SecurityAccessLevel.Edit" Class="btn btn-danger" OnClick="@(async () => await Delete(context))" />
@context.Name
</div>
<td><ActionLink Action="Edit" Parameters="@($"id=" + context.[Module]Id.ToString())" /></td>
<td><ActionDialog Header="Delete [Module]" Message="@("Are You Sure You Wish To Delete The " + context.Name + " [Module]?")" Action="Delete" Security="SecurityAccessLevel.Edit" Class="btn btn-danger" OnClick="@(async () => await Delete(context))" /></td>
<td>@context.Name</td>
</Row>
</Pager>
}

View File

@ -1,7 +1,7 @@
using Oqtane.Models;
using Oqtane.Modules;
namespace [Owner].[Module]s
namespace [Owner].[Module]
{
public class ModuleInfo : IModule
{

View File

@ -0,0 +1,19 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using [Owner].[Module].Models;
namespace [Owner].[Module].Services
{
public interface I[Module]Service
{
Task<List<Models.[Module]>> Get[Module]sAsync(int ModuleId);
Task<Models.[Module]> Get[Module]Async(int [Module]Id, int ModuleId);
Task<Models.[Module]> Add[Module]Async(Models.[Module] [Module]);
Task<Models.[Module]> Update[Module]Async(Models.[Module] [Module]);
Task Delete[Module]Async(int [Module]Id, int ModuleId);
}
}

View File

@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Oqtane.Modules;
using Oqtane.Services;
using Oqtane.Shared;
using [Owner].[Module].Models;
namespace [Owner].[Module].Services
{
public class [Module]Service : ServiceBase, I[Module]Service, IService
{
private readonly SiteState _siteState;
public [Module]Service(HttpClient http, SiteState siteState) : base(http)
{
_siteState = siteState;
}
private string Apiurl => CreateApiUrl(_siteState.Alias, "[Module]");
public async Task<List<Models.[Module]>> Get[Module]sAsync(int ModuleId)
{
List<Models.[Module]> [Module]s = await GetJsonAsync<List<Models.[Module]>>(CreateAuthorizationPolicyUrl($"{Apiurl}?moduleid={ModuleId}", ModuleId));
return [Module]s.OrderBy(item => item.Name).ToList();
}
public async Task<Models.[Module]> Get[Module]Async(int [Module]Id, int ModuleId)
{
return await GetJsonAsync<Models.[Module]>(CreateAuthorizationPolicyUrl($"{Apiurl}/{[Module]Id}", ModuleId));
}
public async Task<Models.[Module]> Add[Module]Async(Models.[Module] [Module])
{
return await PostJsonAsync<Models.[Module]>(CreateAuthorizationPolicyUrl($"{Apiurl}", [Module].ModuleId), [Module]);
}
public async Task<Models.[Module]> Update[Module]Async(Models.[Module] [Module])
{
return await PutJsonAsync<Models.[Module]>(CreateAuthorizationPolicyUrl($"{Apiurl}/{[Module].[Module]Id}", [Module].ModuleId), [Module]);
}
public async Task Delete[Module]Async(int [Module]Id, int ModuleId)
{
await DeleteAsync(CreateAuthorizationPolicyUrl($"{Apiurl}/{[Module]Id}", ModuleId));
}
}
}

View File

@ -1,4 +1,4 @@
@namespace [Owner].[Module]s
@namespace [Owner].[Module]
@inherits ModuleBase
@inject ISettingService SettingService

View File

@ -1,19 +0,0 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using [Owner].[Module]s.Models;
namespace [Owner].[Module]s.Services
{
public interface I[Module]Service
{
Task<List<[Module]>> Get[Module]sAsync(int ModuleId);
Task<[Module]> Get[Module]Async(int [Module]Id, int ModuleId);
Task<[Module]> Add[Module]Async([Module] [Module]);
Task<[Module]> Update[Module]Async([Module] [Module]);
Task Delete[Module]Async(int [Module]Id, int ModuleId);
}
}

View File

@ -1,61 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Oqtane.Modules;
using Oqtane.Services;
using Oqtane.Shared;
using [Owner].[Module]s.Models;
namespace [Owner].[Module]s.Services
{
public class [Module]Service : ServiceBase, I[Module]Service, IService
{
private readonly SiteState _siteState;
public [Module]Service(HttpClient http, SiteState siteState) : base(http)
{
_siteState = siteState;
}
private string Apiurl => CreateApiUrl(_siteState.Alias, "[Module]");
public async Task<List<[Module]>> Get[Module]sAsync(int ModuleId)
{
List<[Module]> [Module]s = await GetJsonAsync<List<[Module]>>(CreateAuthPolicyUrl($"{Apiurl}?moduleid={ModuleId}", ModuleId));
return [Module]s.OrderBy(item => item.Name).ToList();
}
public async Task<[Module]> Get[Module]Async(int [Module]Id, int ModuleId)
{
return await GetJsonAsync<[Module]>(CreateAuthPolicyUrl($"{Apiurl}/{[Module]Id}", ModuleId));
}
public async Task<[Module]> Add[Module]Async([Module] [Module])
{
return await PostJsonAsync<[Module]>(CreateAuthPolicyUrl($"{Apiurl}?entityid={[Module].ModuleId}", [Module].ModuleId), [Module]);
}
public async Task<[Module]> Update[Module]Async([Module] [Module])
{
return await PutJsonAsync<[Module]>(CreateAuthPolicyUrl($"{Apiurl}/{[Module].[Module]Id}", [Module].ModuleId), [Module]);
}
public async Task Delete[Module]Async(int [Module]Id, int ModuleId)
{
await DeleteAsync(CreateAuthPolicyUrl($"{Apiurl}/{[Module]Id}", ModuleId));
}
private string CreateAuthPolicyUrl(string Url, int ModuleId)
{
if (Url.Contains("?"))
{
return Url + "&entityid=" + ModuleId.ToString();
}
else
{
return Url + "?entityid=" + ModuleId.ToString();
}
}
}
}

View File

@ -5,21 +5,21 @@ using Microsoft.AspNetCore.Http;
using Oqtane.Shared;
using Oqtane.Enums;
using Oqtane.Infrastructure;
using [Owner].[Module]s.Models;
using [Owner].[Module]s.Repository;
using [Owner].[Module].Models;
using [Owner].[Module].Repository;
namespace [Owner].[Module]s.Controllers
namespace [Owner].[Module].Controllers
{
[Route("{alias}/api/[controller]")]
public class [Module]Controller : Controller
{
private readonly I[Module]Repository _[Module]s;
private readonly I[Module]Repository _[Module]Repository;
private readonly ILogManager _logger;
protected int _entityId = -1;
public [Module]Controller(I[Module]Repository [Module]s, ILogManager logger, IHttpContextAccessor accessor)
public [Module]Controller(I[Module]Repository [Module]Repository, ILogManager logger, IHttpContextAccessor accessor)
{
_[Module]s = [Module]s;
_[Module]Repository = [Module]Repository;
_logger = logger;
if (accessor.HttpContext.Request.Query.ContainsKey("entityid"))
@ -31,17 +31,17 @@ namespace [Owner].[Module]s.Controllers
// GET: api/<controller>?moduleid=x
[HttpGet]
[Authorize(Policy = "ViewModule")]
public IEnumerable<[Module]> Get(string moduleid)
public IEnumerable<Models.[Module]> Get(string moduleid)
{
return _[Module]s.Get[Module]s(int.Parse(moduleid));
return _[Module]Repository.Get[Module]s(int.Parse(moduleid));
}
// GET api/<controller>/5
[HttpGet("{id}")]
[Authorize(Policy = "ViewModule")]
public [Module] Get(int id)
public Models.[Module] Get(int id)
{
[Module] [Module] = _[Module]s.Get[Module](id);
Models.[Module] [Module] = _[Module]Repository.Get[Module](id);
if ([Module] != null && [Module].ModuleId != _entityId)
{
[Module] = null;
@ -52,11 +52,11 @@ namespace [Owner].[Module]s.Controllers
// POST api/<controller>
[HttpPost]
[Authorize(Policy = "EditModule")]
public [Module] Post([FromBody] [Module] [Module])
public Models.[Module] Post([FromBody] Models.[Module] [Module])
{
if (ModelState.IsValid && [Module].ModuleId == _entityId)
{
[Module] = _[Module]s.Add[Module]([Module]);
[Module] = _[Module]Repository.Add[Module]([Module]);
_logger.Log(LogLevel.Information, this, LogFunction.Create, "[Module] Added {[Module]}", [Module]);
}
return [Module];
@ -65,11 +65,11 @@ namespace [Owner].[Module]s.Controllers
// PUT api/<controller>/5
[HttpPut("{id}")]
[Authorize(Policy = "EditModule")]
public [Module] Put(int id, [FromBody] [Module] [Module])
public Models.[Module] Put(int id, [FromBody] Models.[Module] [Module])
{
if (ModelState.IsValid && [Module].ModuleId == _entityId)
{
[Module] = _[Module]s.Update[Module]([Module]);
[Module] = _[Module]Repository.Update[Module]([Module]);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "[Module] Updated {[Module]}", [Module]);
}
return [Module];
@ -80,10 +80,10 @@ namespace [Owner].[Module]s.Controllers
[Authorize(Policy = "EditModule")]
public void Delete(int id)
{
[Module] [Module] = _[Module]s.Get[Module](id);
Models.[Module] [Module] = _[Module]Repository.Get[Module](id);
if ([Module] != null && [Module].ModuleId == _entityId)
{
_[Module]s.Delete[Module](id);
_[Module]Repository.Delete[Module](id);
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "[Module] Deleted {[Module]Id}", id);
}
}

View File

@ -0,0 +1,61 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Oqtane.Modules;
using Oqtane.Models;
using Oqtane.Infrastructure;
using Oqtane.Repository;
using [Owner].[Module].Models;
using [Owner].[Module].Repository;
namespace [Owner].[Module].Manager
{
public class [Module]Manager : IInstallable, IPortable
{
private I[Module]Repository _[Module]Repository;
private ISqlRepository _sql;
public [Module]Manager(I[Module]Repository [Module]Repository, ISqlRepository sql)
{
_[Module]Repository = [Module]Repository;
_sql = sql;
}
public bool Install(Tenant tenant, string version)
{
return _sql.ExecuteScript(tenant, GetType().Assembly, "[Owner].[Module]." + version + ".sql");
}
public bool Uninstall(Tenant tenant)
{
return _sql.ExecuteScript(tenant, GetType().Assembly, "[Owner].[Module].Uninstall.sql");
}
public string ExportModule(Module module)
{
string content = "";
List<Models.[Module]> [Module]s = _[Module]Repository.Get[Module]s(module.ModuleId).ToList();
if ([Module]s != null)
{
content = JsonSerializer.Serialize([Module]s);
}
return content;
}
public void ImportModule(Module module, string content, string version)
{
List<Models.[Module]> [Module]s = null;
if (!string.IsNullOrEmpty(content))
{
[Module]s = JsonSerializer.Deserialize<List<Models.[Module]>>(content);
}
if ([Module]s != null)
{
foreach(var [Module] in [Module]s)
{
_[Module]Repository.Add[Module](new Models.[Module] { ModuleId = module.ModuleId, Name = [Module].Name });
}
}
}
}
}

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
using [Owner].[Module].Models;
namespace [Owner].[Module].Repository
{
public interface I[Module]Repository
{
IEnumerable<Models.[Module]> Get[Module]s(int ModuleId);
Models.[Module] Get[Module](int [Module]Id);
Models.[Module] Add[Module](Models.[Module] [Module]);
Models.[Module] Update[Module](Models.[Module] [Module]);
void Delete[Module](int [Module]Id);
}
}

View File

@ -2,13 +2,13 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Http;
using Oqtane.Modules;
using Oqtane.Repository;
using [Owner].[Module]s.Models;
using [Owner].[Module].Models;
namespace [Owner].[Module]s.Repository
namespace [Owner].[Module].Repository
{
public class [Module]Context : DBContextBase, IService
{
public virtual DbSet<[Module]> [Module] { get; set; }
public virtual DbSet<Models.[Module]> [Module] { get; set; }
public [Module]Context(ITenantResolver tenantResolver, IHttpContextAccessor accessor) : base(tenantResolver, accessor)
{

View File

@ -2,9 +2,9 @@ using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Collections.Generic;
using Oqtane.Modules;
using [Owner].[Module]s.Models;
using [Owner].[Module].Models;
namespace [Owner].[Module]s.Repository
namespace [Owner].[Module].Repository
{
public class [Module]Repository : I[Module]Repository, IService
{
@ -15,24 +15,24 @@ namespace [Owner].[Module]s.Repository
_db = context;
}
public IEnumerable<[Module]> Get[Module]s(int ModuleId)
public IEnumerable<Models.[Module]> Get[Module]s(int ModuleId)
{
return _db.[Module].Where(item => item.ModuleId == ModuleId);
}
public [Module] Get[Module](int [Module]Id)
public Models.[Module] Get[Module](int [Module]Id)
{
return _db.[Module].Find([Module]Id);
}
public [Module] Add[Module]([Module] [Module])
public Models.[Module] Add[Module](Models.[Module] [Module])
{
_db.[Module].Add([Module]);
_db.SaveChanges();
return [Module];
}
public [Module] Update[Module]([Module] [Module])
public Models.[Module] Update[Module](Models.[Module] [Module])
{
_db.Entry([Module]).State = EntityState.Modified;
_db.SaveChanges();
@ -41,7 +41,7 @@ namespace [Owner].[Module]s.Repository
public void Delete[Module](int [Module]Id)
{
[Module] [Module] = _db.[Module].Find([Module]Id);
Models.[Module] [Module] = _db.[Module].Find([Module]Id);
_db.[Module].Remove([Module]);
_db.SaveChanges();
}

View File

@ -1,52 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Oqtane.Modules;
using Oqtane.Models;
using Oqtane.Infrastructure;
using Oqtane.Repository;
using [Owner].[Module]s.Models;
using [Owner].[Module]s.Repository;
namespace [Owner].[Module]s.Manager
{
public class [Module]Manager : IPortable
{
private I[Module]Repository _[Module]s;
public [Module]Manager(I[Module]Repository [Module]s)
{
_[Module]s = [Module]s;
}
public string ExportModule(Module module)
{
string content = "";
List<[Module]> [Module]s = _[Module]s.Get[Module]s(module.ModuleId).ToList();
if ([Module]s != null)
{
content = JsonSerializer.Serialize([Module]s);
}
return content;
}
public void ImportModule(Module module, string content, string version)
{
List<[Module]> [Module]s = null;
if (!string.IsNullOrEmpty(content))
{
[Module]s = JsonSerializer.Deserialize<List<[Module]>>(content);
}
if ([Module]s != null)
{
foreach([Module] [Module] in [Module]s)
{
[Module] _[Module] = new [Module]();
_[Module].ModuleId = module.ModuleId;
_[Module].Name = [Module].Name;
_[Module]s.Add[Module](_[Module]);
}
}
}
}
}

View File

@ -1,14 +0,0 @@
using System.Collections.Generic;
using [Owner].[Module]s.Models;
namespace [Owner].[Module]s.Repository
{
public interface I[Module]Repository
{
IEnumerable<[Module]> Get[Module]s(int ModuleId);
[Module] Get[Module](int [Module]Id);
[Module] Add[Module]([Module] [Module]);
[Module] Update[Module]([Module] [Module]);
void Delete[Module](int [Module]Id);
}
}

View File

@ -2,7 +2,7 @@ using System;
using System.ComponentModel.DataAnnotations.Schema;
using Oqtane.Models;
namespace [Owner].[Module]s.Models
namespace [Owner].[Module].Models
{
[Table("[Owner][Module]")]
public class [Module] : IAuditable