Initial commit
This commit is contained in:
49
.templates/AuditableEntity.cshtml
Normal file
49
.templates/AuditableEntity.cshtml
Normal file
@@ -0,0 +1,49 @@
|
||||
@inherits RazorTemplate<string>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Runtime.Serialization;
|
||||
using DotNetNuke.Common.Utilities;
|
||||
|
||||
namespace @(Settings.RootNameSpace).Data
|
||||
{
|
||||
[DataContract]
|
||||
public abstract class AuditableEntity
|
||||
{
|
||||
|
||||
public void FillAuditFields(IDataReader dr)
|
||||
{
|
||||
CreatedByUserID = Convert.ToInt32(Null.SetNull(dr["CreatedByUserID"], CreatedByUserID));
|
||||
CreatedOnDate = Convert.ToDateTime(Null.SetNull(dr["CreatedOnDate"], CreatedOnDate));
|
||||
LastModifiedByUserID = Convert.ToInt32(Null.SetNull(dr["LastModifiedByUserID"], LastModifiedByUserID));
|
||||
LastModifiedOnDate = Convert.ToDateTime(Null.SetNull(dr["LastModifiedOnDate"], LastModifiedOnDate));
|
||||
}
|
||||
|
||||
public void SetAddingUser(int userId)
|
||||
{
|
||||
CreatedByUserID = userId;
|
||||
CreatedOnDate = DateTime.Now;
|
||||
SetModifyingUser(userId);
|
||||
}
|
||||
|
||||
public void SetModifyingUser(int userId)
|
||||
{
|
||||
LastModifiedByUserID = userId;
|
||||
LastModifiedOnDate = DateTime.Now;
|
||||
}
|
||||
|
||||
#region Public Properties
|
||||
[DataMember]
|
||||
public int CreatedByUserID { get; set; }
|
||||
[DataMember]
|
||||
public DateTime CreatedOnDate { get; set; }
|
||||
[DataMember]
|
||||
public int LastModifiedByUserID { get; set; }
|
||||
[DataMember]
|
||||
public DateTime LastModifiedOnDate { get; set; }
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
35
.templates/BootstrapPopupEdit.cshtml
Normal file
35
.templates/BootstrapPopupEdit.cshtml
Normal file
@@ -0,0 +1,35 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
@{
|
||||
}
|
||||
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title" id="cmModalLabel">@@Html.GetLocalizedString("EditUser")</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 form-horizontal">
|
||||
@foreach (Column c in Model.Table.Columns)
|
||||
{
|
||||
<div class="form-group">
|
||||
<label for="Title" class="col-sm-2 control-label">@@Html.GetLocalizedString("@c.Name")</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control" id="@c.Name" value="@("@Model.")@c.Name">
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" id="cmdCancel" class="btn btn-default" data-dismiss="modal">@@Html.GetLocalizedString("cmdCancel")</a>
|
||||
<a href="#" id="cmdSubmit" class="btn btn-primary">@@Html.GetLocalizedString("cmdSubmit")</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
61
.templates/Controller.cshtml
Normal file
61
.templates/Controller.cshtml
Normal file
@@ -0,0 +1,61 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@{
|
||||
}
|
||||
using @(Settings.RootNameSpace).Models.@(Model.PluralName);
|
||||
using @(Settings.RootNameSpace).Repositories;
|
||||
|
||||
namespace @(Settings.RootNameSpace).Controllers
|
||||
{
|
||||
|
||||
public partial class @(Model.PluralName)Controller
|
||||
{
|
||||
|
||||
@if (@Model.Table.IsTableWithIdColumn())
|
||||
{
|
||||
@: public static @(Model.SingularName) Get@(Model.SingularName)(@Model.Table.PrimaryKeyParameterList())
|
||||
@: {
|
||||
@:
|
||||
@: @(Model.SingularName)Repository repo = new @(Model.SingularName)Repository();
|
||||
@: return repo.GetById(@Model.Table.PrimaryKeyParameters().Lowered());
|
||||
@:
|
||||
@: }
|
||||
@:
|
||||
@: public static int Add@(Model.SingularName)(ref @(Model.SingularName)Base @(Model.SingularName.Lowered())@(Model.HasAuditFields ? ", int userId" : ""))
|
||||
@: {
|
||||
if (Model.HasAuditFields)
|
||||
{
|
||||
@:
|
||||
@: @(Model.SingularName.Lowered()).SetAddingUser(userId);
|
||||
}
|
||||
@: @(Model.SingularName)BaseRepository repo = new @(Model.SingularName)BaseRepository();
|
||||
@: repo.Insert(@(Model.SingularName.Lowered()));
|
||||
@: return @(Model.SingularName.Lowered()).@Model.Table.PrimaryKeyParameters();
|
||||
@:
|
||||
@: }
|
||||
}
|
||||
|
||||
public static void Update@(Model.SingularName)(@(Model.SingularName)Base @(Model.SingularName.Lowered())@(Model.HasAuditFields ? ", int userId" : ""))
|
||||
{
|
||||
|
||||
@if (Model.HasAuditFields)
|
||||
{
|
||||
@: @(Model.SingularName.Lowered()).SetModifyingUser(userId);
|
||||
}
|
||||
@(Model.SingularName)BaseRepository repo = new @(Model.SingularName)BaseRepository();
|
||||
repo.Update(@(Model.SingularName.Lowered()));
|
||||
|
||||
}
|
||||
|
||||
public static void Delete@(Model.SingularName)(@(Model.SingularName)Base @(Model.SingularName.Lowered()))
|
||||
{
|
||||
|
||||
@(Model.SingularName)BaseRepository repo = new @(Model.SingularName)BaseRepository();
|
||||
repo.Delete(@(Model.SingularName.Lowered()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
82
.templates/Controller_Services.cshtml
Normal file
82
.templates/Controller_Services.cshtml
Normal file
@@ -0,0 +1,82 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@{
|
||||
}
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using DotNetNuke.Web.Api;
|
||||
using @(Settings.RootNameSpace).Repositories;
|
||||
|
||||
namespace @(Settings.RootNameSpace).Api
|
||||
{
|
||||
|
||||
public partial class @(Model.PluralName)Controller : @(Settings.ModuleName)ApiController
|
||||
{
|
||||
|
||||
[HttpGet()]
|
||||
[DnnModuleAuthorize(AccessLevel = DotNetNuke.Security.SecurityAccessLevel.View)]
|
||||
public HttpResponseMessage MyMethod(int id)
|
||||
{
|
||||
bool res = true;
|
||||
return Request.CreateResponse(HttpStatusCode.OK, res);
|
||||
}
|
||||
|
||||
@if (@Model.Table.IsTableWithIdColumn())
|
||||
{
|
||||
@: [HttpGet]
|
||||
@: [DnnModuleAuthorize(AccessLevel = DotNetNuke.Security.SecurityAccessLevel.View)]
|
||||
@: public HttpResponseMessage Get (@Model.Table.PrimaryKeyParameterList())
|
||||
@: {
|
||||
@:
|
||||
@: @(Model.SingularName)Repository repo = new @(Model.SingularName)Repository();
|
||||
@: return Request.CreateResponse(HttpStatusCode.OK, repo.GetById(@Model.Table.PrimaryKeyParameters().Lowered()));
|
||||
@:
|
||||
@: }
|
||||
@:
|
||||
@: [HttpPost]
|
||||
@: [DnnModuleAuthorize(AccessLevel = DotNetNuke.Security.SecurityAccessLevel.Edit)]
|
||||
@: public HttpResponseMessage Add (@(Model.SingularName)Base @(Model.SingularName.Lowered()))
|
||||
@: {
|
||||
if (Model.HasAuditFields)
|
||||
{
|
||||
@:
|
||||
@: @(Model.SingularName.Lowered()).SetAddingUser(userId);
|
||||
}
|
||||
@: @(Model.SingularName)BaseRepository repo = new @(Model.SingularName)BaseRepository();
|
||||
@: repo.Insert(@(Model.SingularName.Lowered()));
|
||||
@: return Request.CreateResponse(HttpStatusCode.OK, @(Model.SingularName.Lowered()));
|
||||
@:
|
||||
@: }
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[DnnModuleAuthorize(AccessLevel = DotNetNuke.Security.SecurityAccessLevel.Edit)]
|
||||
public HttpResponseMessage Update (@(Model.SingularName)Base @(Model.SingularName.Lowered()))
|
||||
{
|
||||
|
||||
@if (Model.HasAuditFields)
|
||||
{
|
||||
@: @(Model.SingularName.Lowered()).SetModifyingUser(userId);
|
||||
}
|
||||
@(Model.SingularName)BaseRepository repo = new @(Model.SingularName)BaseRepository();
|
||||
repo.Update(@(Model.SingularName.Lowered()));
|
||||
return Request.CreateResponse(HttpStatusCode.OK, @(Model.SingularName.Lowered()));
|
||||
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[DnnModuleAuthorize(AccessLevel = DotNetNuke.Security.SecurityAccessLevel.Edit)]
|
||||
public HttpResponseMessage Delete (@Model.Table.PrimaryKeyParameterList())
|
||||
{
|
||||
|
||||
@(Model.SingularName)BaseRepository repo = new @(Model.SingularName)BaseRepository();
|
||||
repo.Delete(@(Model.SingularName.Lowered()));
|
||||
return Request.CreateResponse(HttpStatusCode.OK, "");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
21
.templates/IHydratableField.cshtml
Normal file
21
.templates/IHydratableField.cshtml
Normal file
@@ -0,0 +1,21 @@
|
||||
@inherits RazorTemplate<Column>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
@switch (Model.DataType.SqlDataType.ToString())
|
||||
{
|
||||
case "DateTime":
|
||||
case "SmallDateTime":
|
||||
@: @Model.Name = (DateTime)(Null.SetNull(dr["@Model.Name"], @Model.Name));
|
||||
break;
|
||||
case "Time":
|
||||
@: if (dr["@Model.Name"] != DBNull.Value) { @Model.Name = (TimeSpan)dr["@Model.Name"]; }
|
||||
break;
|
||||
case "Guid":
|
||||
@: @Model.Name = (Guid)(Null.SetNull(dr["@Model.Name"], @Model.Name));
|
||||
break;
|
||||
default:
|
||||
@: @Model.Name = Convert.To@(Model.DataType.DataTypeToCsStruct())(Null.SetNull(dr["@Model.Name"], @Model.Name));
|
||||
break;
|
||||
}
|
||||
39
.templates/IPropertyAccessField.cshtml
Normal file
39
.templates/IPropertyAccessField.cshtml
Normal file
@@ -0,0 +1,39 @@
|
||||
@inherits RazorTemplate<Column>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
case "@Model.Name.ToLower()": // @Model.DataType.SqlDataType.ToString()
|
||||
@if (Model.Nullable)
|
||||
{
|
||||
@: if (@Model.Name == null)
|
||||
@: {
|
||||
@: return "";
|
||||
@: };
|
||||
}
|
||||
@switch (Model.DataType.SqlDataType.ToString())
|
||||
{
|
||||
case "Bit":
|
||||
@: return @(Model.Name).ToString();
|
||||
break;
|
||||
case "Char":
|
||||
case "Text":
|
||||
case "VarChar":
|
||||
case "VarCharMax":
|
||||
case "NChar":
|
||||
case "NText":
|
||||
case "NVarChar":
|
||||
case "NVarCharMax":
|
||||
@: return PropertyAccess.FormatString(@Model.Name, strFormat);
|
||||
break;
|
||||
default:
|
||||
if (Model.Nullable)
|
||||
{
|
||||
@: return ((@(Model.DataType.DataTypeToCs()))@(Model.Name)).ToString(strFormat, formatProvider);
|
||||
}
|
||||
else
|
||||
{
|
||||
@: return @(Model.Name).ToString(strFormat, formatProvider);
|
||||
}
|
||||
break;
|
||||
}
|
||||
56
.templates/Main.cshtml
Normal file
56
.templates/Main.cshtml
Normal file
@@ -0,0 +1,56 @@
|
||||
@inherits RazorTemplate<string>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
|
||||
@foreach (Bring2mind.CodeGen.Cli.Data.ObjectDefinition od in DnnDb.Objects.Values)
|
||||
{
|
||||
Engine.RenderTemplate("Controller.cshtml", "Controllers\\" + od.PluralName + "Controller.cs", od);
|
||||
Engine.RenderTemplate("Controller_Services.cshtml", "Api\\" + od.PluralName + "Controller.cs", od);
|
||||
if (od.IsLinkTableWithoutFields)
|
||||
{
|
||||
Engine.RenderTemplate("RepositoryLinkTable.cshtml", "Repositories\\" + od.SingularName + "Repository_Core.cs", od);
|
||||
}
|
||||
else if (od.IsLinkTableWithFields)
|
||||
{
|
||||
Engine.RenderTemplate("RepositoryLinkTablePlus.cshtml", "Repositories\\" + od.SingularName + "Repository_Core.cs", od);
|
||||
}
|
||||
else
|
||||
{
|
||||
Engine.RenderTemplate("Repository.cshtml", "Repositories\\" + od.SingularName + "Repository_Core.cs", od);
|
||||
}
|
||||
Engine.RenderTemplate("Repository_Empty.cshtml", "Repositories\\" + od.SingularName + "Repository.cs", od);
|
||||
if (od.HasTable)
|
||||
{
|
||||
Engine.RenderTemplate("BootstrapPopupEdit.cshtml", "Extra\\Bootstrap\\" + od.SingularName + "Popup.cs", od);
|
||||
Engine.RenderTemplate("MvcEdit.cshtml", "Extra\\Mvc\\" + od.SingularName + "Edit.cshtml", od);
|
||||
Engine.RenderTemplate("MvcBootstrapEdit.cshtml", "Extra\\MvcBootstrap\\" + od.SingularName + "Edit.cshtml", od);
|
||||
}
|
||||
if (od.TableAndView)
|
||||
{
|
||||
Engine.RenderTemplate("Model.cshtml", "Models\\" + od.PluralName + "\\" + od.SingularName + "_Declaration.cs", od);
|
||||
Engine.RenderTemplate("Model_Interfaces.cshtml", "Models\\" + od.PluralName + "\\" + od.SingularName + "_Interfaces.cs", od);
|
||||
Engine.RenderTemplate("ModelBase.cshtml", "Models\\" + od.PluralName + "\\" + od.SingularName + "Base.cs", od);
|
||||
Engine.RenderTemplate("ModelBase_Interfaces.cshtml", "Models\\" + od.PluralName + "\\" + od.SingularName + "Base_Interfaces.cs", od);
|
||||
}
|
||||
else if (od.TableOnly)
|
||||
{
|
||||
Engine.RenderTemplate("ModelBase.cshtml", "Models\\" + od.PluralName + "\\" + od.SingularName + "_Declaration.cs", od);
|
||||
Engine.RenderTemplate("ModelBase_Interfaces.cshtml", "Models\\" + od.PluralName + "\\" + od.SingularName + "_Interfaces.cs", od);
|
||||
Engine.RenderTemplate("Model_Empty.cshtml", "Models\\" + od.PluralName + "\\" + od.SingularName + ".cs", od);
|
||||
}
|
||||
else if (od.ViewOnly)
|
||||
{
|
||||
Engine.RenderTemplate("Model.cshtml", "Models\\" + od.PluralName + "\\" + od.SingularName + "_Declaration.cs", od);
|
||||
Engine.RenderTemplate("Model_Interfaces.cshtml", "Models\\" + od.PluralName + "\\" + od.SingularName + "_Interfaces.cs", od);
|
||||
Engine.RenderTemplate("Model_Empty.cshtml", "Models\\" + od.PluralName + "\\" + od.SingularName + ".cs", od);
|
||||
}
|
||||
Engine.RenderTemplate("TypeScriptIModel.cshtml", "ts\\Models\\I" + od.SingularName + ".ts", od);
|
||||
}
|
||||
|
||||
@{
|
||||
Engine.RenderTemplate("TypeScriptIModelIndex.cshtml", "ts\\Models\\index.js");
|
||||
Engine.RenderTemplate("RepositoryImpl.cshtml", "Data\\RepositoryImpl.cs");
|
||||
Engine.RenderTemplate("AuditableEntity.cshtml", "Data\\AuditableEntity.cs");
|
||||
Engine.RenderTemplate("Sprocs.cshtml", "Data\\Sprocs.cs", DnnDb.StoredProcedures);
|
||||
}
|
||||
89
.templates/Model.cshtml
Normal file
89
.templates/Model.cshtml
Normal file
@@ -0,0 +1,89 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
@{
|
||||
}
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using DotNetNuke.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace @(Settings.RootNameSpace).Models.@(Model.PluralName)
|
||||
{
|
||||
|
||||
[TableName("@Model.Prefix@Model.ModuleQualifier@Model.Name")]
|
||||
@if (Model.Table.IsTableWithIdColumn())
|
||||
{
|
||||
@: [PrimaryKey("@Model.Table.PrimaryKeyParameters()", AutoIncrement = true)]
|
||||
}
|
||||
[DataContract]
|
||||
@if (Model.Scope != "")
|
||||
{
|
||||
@: [Scope("@Model.Scope")]
|
||||
}
|
||||
public partial class @(Model.SingularName) @if (Model.TableAndView){@: : @(Model.SingularName)Base
|
||||
}
|
||||
{
|
||||
|
||||
#region .ctor
|
||||
public @(Model.SingularName)() @if (Model.TableAndView){@: : base()
|
||||
}
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
@foreach (Column c in Model.UniqueViewColumns)
|
||||
{
|
||||
@:@Raw(Engine.RunCompile("PropertyField.cshtml", c).TrimEnd('\r', '\n'))
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
@if (Model.TableAndView)
|
||||
{
|
||||
@: public @(Model.SingularName)Base Get@(Model.SingularName)Base()
|
||||
@: {
|
||||
@: @(Model.SingularName)Base res = new @(Model.SingularName)Base();
|
||||
foreach (Column c in Model.TableColumns)
|
||||
{
|
||||
@: res.@c.Name = @c.Name;
|
||||
}
|
||||
if (Model.HasAuditFields)
|
||||
{
|
||||
@: res.CreatedByUserID = CreatedByUserID;
|
||||
@: res.CreatedOnDate = CreatedOnDate;
|
||||
@: res.LastModifiedByUserID = LastModifiedByUserID;
|
||||
@: res.LastModifiedOnDate = LastModifiedOnDate;
|
||||
}
|
||||
@: return res;
|
||||
@: }
|
||||
}
|
||||
public @(Model.SingularName) Clone()
|
||||
{
|
||||
@(Model.SingularName) res = new @(Model.SingularName)();
|
||||
@foreach (Column c in Model.TableColumns)
|
||||
{
|
||||
@: res.@c.Name = @c.Name;
|
||||
}
|
||||
@if (Model.TableAndView)
|
||||
{
|
||||
foreach (Column c in Model.UniqueViewColumns)
|
||||
{
|
||||
@: res.@c.Name = @c.Name;
|
||||
}
|
||||
}
|
||||
@if (Model.HasAuditFields)
|
||||
{
|
||||
@: res.CreatedByUserID = CreatedByUserID;
|
||||
@: res.CreatedOnDate = CreatedOnDate;
|
||||
@: res.LastModifiedByUserID = LastModifiedByUserID;
|
||||
@: res.LastModifiedOnDate = LastModifiedOnDate;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
68
.templates/ModelBase.cshtml
Normal file
68
.templates/ModelBase.cshtml
Normal file
@@ -0,0 +1,68 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
@{
|
||||
dynamic vb = new System.Dynamic.ExpandoObject();
|
||||
vb.ObjectName = Model.SingularName;
|
||||
|
||||
string baseQualifier = "Base";
|
||||
if (Model.TableOnly)
|
||||
{
|
||||
baseQualifier = "";
|
||||
}
|
||||
|
||||
}
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using DotNetNuke.ComponentModel.DataAnnotations;
|
||||
using @(Settings.RootNameSpace).Data;
|
||||
|
||||
namespace @(Settings.RootNameSpace).Models.@(Model.PluralName)
|
||||
{
|
||||
[TableName("@Model.ModuleQualifier@Model.Name")]
|
||||
@if (Model.Table.IsTableWithIdColumn())
|
||||
{
|
||||
@: [PrimaryKey("@Model.Table.PrimaryKeyParameters()", AutoIncrement = true)]
|
||||
}
|
||||
[DataContract]
|
||||
@if (Model.Scope != "")
|
||||
{
|
||||
@: [Scope("@Model.Scope")]
|
||||
}
|
||||
public partial class @(Model.SingularName)@baseQualifier @if (Model.HasAuditFields){@: : AuditableEntity
|
||||
}
|
||||
{
|
||||
|
||||
#region .ctor
|
||||
public @(Model.SingularName)@(baseQualifier)()
|
||||
{
|
||||
@if (@Model.Table.IsTableWithIdColumn())
|
||||
{
|
||||
@: @Model.Table.PrimaryKeyParameters() = -1;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
@foreach (Column c in Model.TableColumns)
|
||||
{
|
||||
@:@Raw(Engine.RunCompile("PropertyField.cshtml", c))
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public void Read@(Model.SingularName)@(baseQualifier)(@(Model.SingularName)@baseQualifier @(Model.SingularName.Lowered()))
|
||||
{
|
||||
@foreach (Column c in Model.TableColumns)
|
||||
{
|
||||
@:@Raw(Engine.RunCompile("ReadBaseField.cshtml", c, vb))
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
81
.templates/ModelBase_Interfaces.cshtml
Normal file
81
.templates/ModelBase_Interfaces.cshtml
Normal file
@@ -0,0 +1,81 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
@{
|
||||
string baseQualifier = "Base";
|
||||
if (Model.TableOnly)
|
||||
{
|
||||
baseQualifier = "";
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
using DotNetNuke.Common.Utilities;
|
||||
using DotNetNuke.ComponentModel.DataAnnotations;
|
||||
using DotNetNuke.Entities.Modules;
|
||||
using DotNetNuke.Services.Tokens;
|
||||
|
||||
namespace @(Settings.RootNameSpace).Models.@(Model.PluralName)
|
||||
{
|
||||
public partial class @(Model.SingularName)@baseQualifier : IHydratable, IPropertyAccess
|
||||
{
|
||||
|
||||
#region IHydratable
|
||||
|
||||
public virtual void Fill(IDataReader dr)
|
||||
{
|
||||
@if (Model.HasAuditFields)
|
||||
{
|
||||
@: FillAuditFields(dr);
|
||||
}
|
||||
@foreach (Column c in Model.TableColumns)
|
||||
{
|
||||
@:@Raw(Engine.RunCompile("IHydratableField.cshtml", c).TrimEnd('\r', '\n'))
|
||||
}
|
||||
}
|
||||
|
||||
[IgnoreColumn()]
|
||||
public int KeyID
|
||||
{
|
||||
@if (@Model.Table.IsTableWithIdColumn())
|
||||
{
|
||||
@: get { return @Model.Table.PrimaryKeyParameters(); }
|
||||
@: set { @Model.Table.PrimaryKeyParameters() = value; }
|
||||
}
|
||||
else
|
||||
{
|
||||
@: get { return Null.NullInteger; }
|
||||
@: set { }
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IPropertyAccess
|
||||
public virtual string GetProperty(string strPropertyName, string strFormat, System.Globalization.CultureInfo formatProvider, DotNetNuke.Entities.Users.UserInfo accessingUser, DotNetNuke.Services.Tokens.Scope accessLevel, ref bool propertyNotFound)
|
||||
{
|
||||
switch (strPropertyName.ToLower())
|
||||
{
|
||||
@foreach (Column c in Model.TableColumns)
|
||||
{
|
||||
@:@Raw(Engine.RunCompile("IPropertyAccessField.cshtml", c).TrimEnd('\r', '\n'))
|
||||
}
|
||||
default:
|
||||
propertyNotFound = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return Null.NullString;
|
||||
}
|
||||
|
||||
[IgnoreColumn()]
|
||||
public CacheLevel Cacheability
|
||||
{
|
||||
get { return CacheLevel.fullyCacheable; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
52
.templates/ModelPublic.cshtml
Normal file
52
.templates/ModelPublic.cshtml
Normal file
@@ -0,0 +1,52 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace @(Settings.RootNameSpace).Models.@(Model.PluralName)
|
||||
{
|
||||
public class @(Model.SingularName)Public : @(Model.SingularName)
|
||||
{
|
||||
@foreach (Column c in Model.TableColumns)
|
||||
{
|
||||
@: [JsonIgnore]
|
||||
@: public new @c.DataType.DataTypeToCs()@(c.NullSuffix()) @c.Name { get; set; }
|
||||
}
|
||||
@foreach (Column c in Model.UniqueViewColumns)
|
||||
{
|
||||
@: [JsonIgnore]
|
||||
@: public new @c.DataType.DataTypeToCs()@(c.NullSuffix()) @c.Name { get; set; }
|
||||
}
|
||||
@if (Model.HasAuditFields)
|
||||
{
|
||||
@: [JsonIgnore]
|
||||
@: public new int CreatedByUserID { get; set; }
|
||||
@: [JsonIgnore]
|
||||
@: public new DateTime CreatedOnDate { get; set; }
|
||||
@: [JsonIgnore]
|
||||
@: public new int LastModifiedByUserID { get; set; }
|
||||
@: [JsonIgnore]
|
||||
@: public new DateTime LastModifiedOnDate { get; set; }
|
||||
@: [JsonIgnore]
|
||||
@: public new string CreatedByUser { get; set; }
|
||||
@: [JsonIgnore]
|
||||
@: public new string LastModifiedByUser { get; set; }
|
||||
}
|
||||
|
||||
public @(Model.SingularName)Public(@(Model.SingularName) input)
|
||||
{
|
||||
@foreach (Column c in Model.TableColumns)
|
||||
{
|
||||
@: @c.Name = input.@c.Name;
|
||||
}
|
||||
@foreach (Column c in Model.UniqueViewColumns)
|
||||
{
|
||||
@: @c.Name = input.@c.Name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
.templates/Model_Empty.cshtml
Normal file
12
.templates/Model_Empty.cshtml
Normal file
@@ -0,0 +1,12 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@{
|
||||
}
|
||||
namespace @(Settings.RootNameSpace).Models.@(Model.PluralName)
|
||||
{
|
||||
public partial class @(Model.SingularName)
|
||||
{
|
||||
}
|
||||
}
|
||||
60
.templates/Model_Interfaces.cshtml
Normal file
60
.templates/Model_Interfaces.cshtml
Normal file
@@ -0,0 +1,60 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
@{
|
||||
}
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
using DotNetNuke.Common.Utilities;
|
||||
using DotNetNuke.Services.Tokens;
|
||||
|
||||
namespace @(Settings.RootNameSpace).Models.@(Model.PluralName)
|
||||
{
|
||||
|
||||
[Serializable(), XmlRoot("@(Model.SingularName)")]
|
||||
public partial class @(Model.SingularName)
|
||||
{
|
||||
|
||||
#region IHydratable
|
||||
public @(Model.TableAndView ? "override" : "") void Fill(IDataReader dr)
|
||||
{
|
||||
@if (Model.TableAndView)
|
||||
{
|
||||
@: base.Fill(dr);
|
||||
}
|
||||
@foreach (Column c in Model.UniqueViewColumns)
|
||||
{
|
||||
@:@Raw(Engine.RunCompile("IHydratableField.cshtml", c).TrimEnd('\r', '\n'))
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IPropertyAccess
|
||||
public @(Model.TableAndView ? "override" : "") string GetProperty(string strPropertyName, string strFormat, System.Globalization.CultureInfo formatProvider, DotNetNuke.Entities.Users.UserInfo accessingUser, DotNetNuke.Services.Tokens.Scope accessLevel, ref bool propertyNotFound)
|
||||
{
|
||||
switch (strPropertyName.ToLower()) {
|
||||
@foreach (Column c in Model.UniqueViewColumns)
|
||||
{
|
||||
@:@Raw(Engine.RunCompile("IPropertyAccessField.cshtml", c).TrimEnd('\r', '\n'))
|
||||
}
|
||||
default:
|
||||
@if (Model.TableAndView)
|
||||
{
|
||||
@: return base.GetProperty(strPropertyName, strFormat, formatProvider, accessingUser, accessLevel, ref propertyNotFound);
|
||||
}
|
||||
else
|
||||
{
|
||||
@: propertyNotFound = true;
|
||||
@: return "";
|
||||
@: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
55
.templates/MvcBootstrapEdit.cshtml
Normal file
55
.templates/MvcBootstrapEdit.cshtml
Normal file
@@ -0,0 +1,55 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
@{
|
||||
}
|
||||
@@inherits WebPage<@(Model.SingularName)>
|
||||
@@using Connect.DNN.Modules.Conference.Common;
|
||||
@@using Connect.Conference.Core.Models.Conferences;
|
||||
@@using DotNetNuke.Web.Mvc.Helpers;
|
||||
|
||||
<div class="form-horizontal">
|
||||
@foreach (Column c in Model.Table.Columns)
|
||||
{
|
||||
var req = c.Nullable ? "" : ", required = \"true\"";
|
||||
var tp = "";
|
||||
switch (c.DataType.SqlDataType) {
|
||||
case SqlDataType.BigInt:
|
||||
case SqlDataType.Int:
|
||||
case SqlDataType.TinyInt:
|
||||
case SqlDataType.SmallInt:
|
||||
case SqlDataType.Real:
|
||||
case SqlDataType.Numeric:
|
||||
case SqlDataType.Float:
|
||||
tp = ", type = \"number\"";
|
||||
break;
|
||||
case SqlDataType.Date:
|
||||
tp = ", type = \"date\"";
|
||||
break;
|
||||
case SqlDataType.DateTime:
|
||||
case SqlDataType.SmallDateTime:
|
||||
tp = ", type = \"datetime\"";
|
||||
break;
|
||||
}
|
||||
if (c.DataType.SqlDataType == SqlDataType.Bit) {
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
@@Html.CheckBoxFor(m => m.@c.Name) @@Dnn.LocalizeString("@c.Name")
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
} else {
|
||||
<div class="form-group">
|
||||
<label for="@c.Name" class="col-sm-2 control-label">@@Dnn.LocalizeString("@c.Name")</label>
|
||||
<div class="col-sm-10">
|
||||
@@Html.TextBoxFor(m => m.@c.Name, new { @@class = "form-control", placeholder = Dnn.LocalizeString("@c.Name")@req@tp })
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
23
.templates/MvcEdit.cshtml
Normal file
23
.templates/MvcEdit.cshtml
Normal file
@@ -0,0 +1,23 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
@{
|
||||
}
|
||||
@@inherits WebPage<@(Model.SingularName)>
|
||||
@@using Connect.DNN.Modules.Conference.Common;
|
||||
@@using Connect.Conference.Core.Models.Conferences;
|
||||
@@using DotNetNuke.Web.Mvc.Helpers;
|
||||
|
||||
<fieldset>
|
||||
@foreach (Column c in Model.Table.Columns)
|
||||
{
|
||||
<div class="dnnFormItem">
|
||||
<div class="dnnLabel" style="position: relative;">
|
||||
<label>@@Dnn.LocalizeString("@c.Name")</label>
|
||||
</div>
|
||||
@@Html.TextBoxFor(m => m.@c.Name, new { placeholder = Dnn.LocalizeString("@c.Name") })
|
||||
</div>
|
||||
}
|
||||
</fieldset>
|
||||
7
.templates/PropertyField.cshtml
Normal file
7
.templates/PropertyField.cshtml
Normal file
@@ -0,0 +1,7 @@
|
||||
@inherits RazorTemplate<Column>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
[DataMember]
|
||||
public @Model.DataType.DataTypeToCs()@(Model.NullSuffix()) @Model.Name { get; set; }
|
||||
35
.templates/ReadBaseField.cshtml
Normal file
35
.templates/ReadBaseField.cshtml
Normal file
@@ -0,0 +1,35 @@
|
||||
@inherits RazorTemplate<Column>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
@switch (Model.DataType.SqlDataType.ToString())
|
||||
{
|
||||
case "Int":
|
||||
case "TinyInt":
|
||||
case "SmallInt":
|
||||
@: if (@(((string)ViewBag.ObjectName).Lowered()).@Model.Name > -1)
|
||||
@: @Model.Name = @(((string)ViewBag.ObjectName).Lowered()).@Model.Name;
|
||||
break;
|
||||
case "Real":
|
||||
case "Numeric":
|
||||
case "Float":
|
||||
case "Decimal":
|
||||
case "Money":
|
||||
case "SmallMoney":
|
||||
case "Date":
|
||||
case "DateTime":
|
||||
case "Time":
|
||||
case "SmallDateTime":
|
||||
case "Bit":
|
||||
if (Model.Nullable)
|
||||
{
|
||||
@: if (@(((string)ViewBag.ObjectName).Lowered()).@Model.Name != null)
|
||||
}
|
||||
@: @Model.Name = @(((string)ViewBag.ObjectName).Lowered()).@Model.Name;
|
||||
break;
|
||||
default:
|
||||
@: if (!String.IsNullOrEmpty(@(((string)ViewBag.ObjectName).Lowered()).@Model.Name))
|
||||
@: @Model.Name = @(((string)ViewBag.ObjectName).Lowered()).@Model.Name;
|
||||
break;
|
||||
}
|
||||
142
.templates/Repository.cshtml
Normal file
142
.templates/Repository.cshtml
Normal file
@@ -0,0 +1,142 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DotNetNuke.Common;
|
||||
using DotNetNuke.Data;
|
||||
using DotNetNuke.Framework;
|
||||
using @(Settings.RootNameSpace).Models.@(Model.PluralName);
|
||||
|
||||
namespace @(Settings.RootNameSpace).Repositories
|
||||
{
|
||||
|
||||
public partial class @(Model.SingularName)Repository : ServiceLocator<I@(Model.SingularName)Repository, @(Model.SingularName)Repository>, I@(Model.SingularName)Repository
|
||||
{
|
||||
protected override Func<I@(Model.SingularName)Repository> GetFactory()
|
||||
{
|
||||
return () => new @(Model.SingularName)Repository();
|
||||
}
|
||||
public IEnumerable<@(Model.SingularName)> Get@(Model.PluralName)(@(Model.GetScopeDeclaration(true, true, false, false)))
|
||||
{
|
||||
using (var context = DataContext.Instance())
|
||||
{
|
||||
var rep = context.GetRepository<@(Model.SingularName)>();
|
||||
return rep.Get(@(Model.GetScopeDeclaration(true, false, false, false)));
|
||||
}
|
||||
}
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
if (fo.Key != Model.Scope)
|
||||
{
|
||||
@: public IEnumerable<@(Model.SingularName)> Get@(Model.PluralName)By@(fo.Value.SingularName)(@(Model.Table.Parameter(fo.Key, true, true, "")))
|
||||
@: {
|
||||
@: using (var context = DataContext.Instance())
|
||||
@: {
|
||||
@: return context.ExecuteQuery<@(Model.SingularName)>(System.Data.CommandType.Text,
|
||||
@: "SELECT * FROM {databaseOwner}{objectQualifier}@Model.Prefix@Model.ModuleQualifier@Model.Name WHERE @(Model.Table.Parameter(fo.Key, false, false, ""))=@@0",
|
||||
@: @(Model.Table.Parameter(fo.Key, false, true, "")));
|
||||
@: }
|
||||
@: }
|
||||
}
|
||||
}
|
||||
@if (Model.HasTable)
|
||||
{
|
||||
if (!Model.HasNoPrimaryKey)
|
||||
{
|
||||
@: public @(Model.SingularName) Get@(Model.SingularName)(@(Model.GetScopeDeclaration(true, true, false, true))@Model.Table.PrimaryKeyParameterList())
|
||||
@: {
|
||||
@: using (var context = DataContext.Instance())
|
||||
@: {
|
||||
@: var rep = context.GetRepository<@(Model.SingularName)>();
|
||||
@: return rep.GetById(@Model.Table.PrimaryKeyParameters().Lowered()@(Model.GetScopeDeclaration(true, false, true, false)));
|
||||
@: }
|
||||
@: }
|
||||
}
|
||||
@: public @(Model.TableObjectName) Add@(Model.SingularName)(@(Model.TableObjectName) @(Model.SingularNameLowered)@(Model.HasAuditFields ? ", int userId" : ""))
|
||||
@: {
|
||||
@: Requires.NotNull(@(Model.SingularNameLowered));
|
||||
if (Model.Scope != "")
|
||||
{
|
||||
@: Requires.PropertyNotNegative(@(Model.SingularNameLowered), "@(Model.GetScopeDeclaration(false, false, false, false))");
|
||||
}
|
||||
if (Model.HasAuditFields)
|
||||
{
|
||||
@: @(Model.SingularNameLowered).CreatedByUserID = userId;
|
||||
@: @(Model.SingularNameLowered).CreatedOnDate = DateTime.Now;
|
||||
@: @(Model.SingularNameLowered).LastModifiedByUserID = userId;
|
||||
@: @(Model.SingularNameLowered).LastModifiedOnDate = DateTime.Now;
|
||||
}
|
||||
@: using (var context = DataContext.Instance())
|
||||
@: {
|
||||
@: var rep = context.GetRepository<@(Model.TableObjectName)>();
|
||||
@: rep.Insert(@(Model.SingularNameLowered));
|
||||
@: }
|
||||
@: return @(Model.SingularNameLowered);
|
||||
@: }
|
||||
@: public void Delete@(Model.SingularName)(@(Model.TableObjectName) @(Model.SingularNameLowered))
|
||||
@: {
|
||||
@: Requires.NotNull(@(Model.SingularNameLowered));
|
||||
@: Requires.PropertyNotNegative(@(Model.SingularNameLowered), "@(Model.SingularName)Id");
|
||||
@: using (var context = DataContext.Instance())
|
||||
@: {
|
||||
@: var rep = context.GetRepository<@(Model.TableObjectName)>();
|
||||
@: rep.Delete(@(Model.SingularNameLowered));
|
||||
@: }
|
||||
@: }
|
||||
if (!Model.HasNoPrimaryKey)
|
||||
{
|
||||
@: public void Delete@(Model.SingularName)(@(Model.GetScopeDeclaration(true, true, false, true))@Model.Table.PrimaryKeyParameterList())
|
||||
@: {
|
||||
@: using (var context = DataContext.Instance())
|
||||
@: {
|
||||
@: var rep = context.GetRepository<@(Model.TableObjectName)>();
|
||||
@: rep.Delete("@(Model.GetParameterList(true, true, ObjectDefinition.ParameterListType.SqlWhereClause))", @(Model.GetParameterList(true, true, ObjectDefinition.ParameterListType.Plain)));
|
||||
@: }
|
||||
@: }
|
||||
}
|
||||
@: public void Update@(Model.SingularName)(@(Model.TableObjectName) @(Model.SingularNameLowered)@(Model.HasAuditFields ? ", int userId" : ""))
|
||||
@: {
|
||||
@: Requires.NotNull(@(Model.SingularNameLowered));
|
||||
@: Requires.PropertyNotNegative(@(Model.SingularNameLowered), "@(Model.SingularName)Id");
|
||||
if (Model.HasAuditFields)
|
||||
{
|
||||
@: @(Model.SingularNameLowered).LastModifiedByUserID = userId;
|
||||
@: @(Model.SingularNameLowered).LastModifiedOnDate = DateTime.Now;
|
||||
}
|
||||
@: using (var context = DataContext.Instance())
|
||||
@: {
|
||||
@: var rep = context.GetRepository<@(Model.TableObjectName)>();
|
||||
@: rep.Update(@(Model.SingularNameLowered));
|
||||
@: }
|
||||
@: }
|
||||
}
|
||||
}
|
||||
public partial interface I@(Model.SingularName)Repository
|
||||
{
|
||||
IEnumerable<@(Model.SingularName)> Get@(Model.PluralName)(@(Model.GetScopeDeclaration(true, true, false, false)));
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
if (fo.Key != Model.Scope)
|
||||
{
|
||||
@: IEnumerable<@(Model.SingularName)> Get@(Model.PluralName)By@(fo.Value.SingularName)(@(Model.Table.Parameter(fo.Key, true, true, "")));
|
||||
}
|
||||
}
|
||||
@if (Model.HasTable)
|
||||
{
|
||||
if (!Model.HasNoPrimaryKey)
|
||||
{
|
||||
@: @(Model.SingularName) Get@(Model.SingularName)(@(Model.GetScopeDeclaration(true, true, false, true))@Model.Table.PrimaryKeyParameterList());
|
||||
}
|
||||
@: @(Model.TableObjectName) Add@(Model.SingularName)(@(Model.TableObjectName) @(Model.SingularNameLowered)@(Model.HasAuditFields ? ", int userId" : ""));
|
||||
@: void Delete@(Model.SingularName)(@(Model.TableObjectName) @(Model.SingularNameLowered));
|
||||
if (!Model.HasNoPrimaryKey)
|
||||
{
|
||||
@: void Delete@(Model.SingularName)(@(Model.GetScopeDeclaration(true, true, false, true))@Model.Table.PrimaryKeyParameterList());
|
||||
}
|
||||
@: void Update@(Model.SingularName)(@(Model.TableObjectName) @(Model.SingularNameLowered)@(Model.HasAuditFields ? ", int userId" : ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
135
.templates/RepositoryImpl.cshtml
Normal file
135
.templates/RepositoryImpl.cshtml
Normal file
@@ -0,0 +1,135 @@
|
||||
@inherits RazorTemplate<string>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
using System.Collections.Generic;
|
||||
using DotNetNuke.Collections;
|
||||
using DotNetNuke.Data;
|
||||
|
||||
namespace @(Settings.RootNameSpace).Data
|
||||
{
|
||||
public abstract class RepositoryImpl<T> : IRepository<T> where T : class
|
||||
{
|
||||
|
||||
public virtual void Delete(T item)
|
||||
{
|
||||
using (IDataContext db = DataContext.Instance()) {
|
||||
IRepository<T> repo = db.GetRepository<T>();
|
||||
repo.Delete(item);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Delete(string sqlCondition, params object[] args)
|
||||
{
|
||||
using (IDataContext db = DataContext.Instance()) {
|
||||
IRepository<T> repo = db.GetRepository<T>();
|
||||
repo.Delete(sqlCondition, args);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual IEnumerable<T> Find(string sqlCondition, params object[] args)
|
||||
{
|
||||
IEnumerable<T> list = null;
|
||||
using (IDataContext db = DataContext.Instance()) {
|
||||
IRepository<T> repo = db.GetRepository<T>();
|
||||
list = repo.Find(sqlCondition, args);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public virtual IPagedList<T> Find(int pageIndex, int pageSize, string sqlCondition, params object[] args)
|
||||
{
|
||||
IPagedList<T> list = null;
|
||||
using (IDataContext db = DataContext.Instance()) {
|
||||
IRepository<T> repo = db.GetRepository<T>();
|
||||
list = repo.Find(pageIndex, pageSize, sqlCondition, args);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public virtual IEnumerable<T> Get()
|
||||
{
|
||||
IEnumerable<T> list = null;
|
||||
using (IDataContext db = DataContext.Instance()) {
|
||||
IRepository<T> repo = db.GetRepository<T>();
|
||||
list = repo.Get();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public virtual IEnumerable<T> Get<TScopeType>(TScopeType scopeValue)
|
||||
{
|
||||
IEnumerable<T> list = null;
|
||||
using (IDataContext db = DataContext.Instance()) {
|
||||
IRepository<T> repo = db.GetRepository<T>();
|
||||
list = repo.Get<TScopeType>(scopeValue);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public virtual T GetById<TProperty>(TProperty id)
|
||||
{
|
||||
T item = null;
|
||||
using (IDataContext db = DataContext.Instance()) {
|
||||
IRepository<T> repo = db.GetRepository<T>();
|
||||
item = repo.GetById<TProperty>(id);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public virtual T GetById<TProperty, TScopeType>(TProperty id, TScopeType scopeValue)
|
||||
{
|
||||
T item = null;
|
||||
using (IDataContext db = DataContext.Instance()) {
|
||||
IRepository<T> repo = db.GetRepository<T>();
|
||||
item = repo.GetById<TProperty, TScopeType>(id, scopeValue);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public virtual IPagedList<T> GetPage(int pageIndex, int pageSize)
|
||||
{
|
||||
IPagedList<T> list = null;
|
||||
using (IDataContext db = DataContext.Instance()) {
|
||||
IRepository<T> repo = db.GetRepository<T>();
|
||||
list = repo.GetPage(pageIndex, pageSize);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public virtual IPagedList<T> GetPage<TScopeType>(TScopeType scopeValue, int pageIndex, int pageSize)
|
||||
{
|
||||
IPagedList<T> list = null;
|
||||
using (IDataContext db = DataContext.Instance()) {
|
||||
IRepository<T> repo = db.GetRepository<T>();
|
||||
list = repo.GetPage<TScopeType>(scopeValue, pageIndex, pageSize);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public virtual void Insert(T item)
|
||||
{
|
||||
using (IDataContext db = DataContext.Instance()) {
|
||||
IRepository<T> repo = db.GetRepository<T>();
|
||||
repo.Insert(item);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Update(T item)
|
||||
{
|
||||
using (IDataContext db = DataContext.Instance()) {
|
||||
IRepository<T> repo = db.GetRepository<T>();
|
||||
repo.Update(item);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Update(string sqlCondition, params object[] args)
|
||||
{
|
||||
using (IDataContext db = DataContext.Instance()) {
|
||||
IRepository<T> repo = db.GetRepository<T>();
|
||||
repo.Update(sqlCondition, args);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
111
.templates/RepositoryLinkTable.cshtml
Normal file
111
.templates/RepositoryLinkTable.cshtml
Normal file
@@ -0,0 +1,111 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DotNetNuke.Collections;
|
||||
using DotNetNuke.Common;
|
||||
using DotNetNuke.Data;
|
||||
using DotNetNuke.Framework;
|
||||
using @(Settings.RootNameSpace).Data;
|
||||
using @(Settings.RootNameSpace).Models.@(Model.PluralName);
|
||||
|
||||
namespace @(Settings.RootNameSpace).Repositories
|
||||
{
|
||||
|
||||
public partial class @(Model.SingularName)Repository : ServiceLocator<I@(Model.SingularName)Repository, @(Model.SingularName)Repository>, I@(Model.SingularName)Repository
|
||||
{
|
||||
protected override Func<I@(Model.SingularName)Repository> GetFactory()
|
||||
{
|
||||
return () => new @(Model.SingularName)Repository();
|
||||
}
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
if (fo.Key != Model.Scope)
|
||||
{
|
||||
@: public IEnumerable<@(Model.SingularName)> Get@(Model.PluralName)By@(fo.Value.SingularName)(@(Model.Table.Parameter(fo.Key, true, true, "")))
|
||||
@: {
|
||||
@: using (var context = DataContext.Instance())
|
||||
@: {
|
||||
@: return context.ExecuteQuery<@(Model.SingularName)>(System.Data.CommandType.Text,
|
||||
@: "SELECT * FROM {databaseOwner}{objectQualifier}@Model.Prefix@Model.ModuleQualifier@Model.Name WHERE @(Model.Table.Parameter(fo.Key, false, false, ""))=@@0",
|
||||
@: @(Model.Table.Parameter(fo.Key, false, true, "")));
|
||||
@: }
|
||||
@: }
|
||||
}
|
||||
}
|
||||
public void Set@(Model.SingularName)(@Model.Table.ParameterList(Globals.ColumnGroup.PrimaryKey, true, true))
|
||||
{
|
||||
using (var context = DataContext.Instance())
|
||||
{
|
||||
context.Execute(System.Data.CommandType.Text,
|
||||
"IF NOT EXISTS (SELECT * FROM {databaseOwner}{objectQualifier}@(Model.ModuleQualifier)@(Model.Name) " +
|
||||
"WHERE @Model.Table.SqlParameterList(Globals.ColumnGroup.PrimaryKey, true, 0, " AND ")) " +
|
||||
"INSERT INTO {databaseOwner}{objectQualifier}@(Model.ModuleQualifier)@(Model.Name) (@Model.Table.ParameterList(Globals.ColumnGroup.PrimaryKey, false, false, "", ", ")) " +
|
||||
"SELECT @@0, @@1", @Model.Table.ParameterList(Globals.ColumnGroup.PrimaryKey, false, true));
|
||||
}
|
||||
}
|
||||
public void Set@(Model.PluralName)(@(Model.Table.FirstPrimaryKeyParameter().ColumnParameter()), List<int> @(Model.PluralName.Lowered()))
|
||||
{
|
||||
|
||||
using (var context = DataContext.Instance())
|
||||
{
|
||||
context.Execute(System.Data.CommandType.Text,
|
||||
"DELETE FROM {databaseOwner}{objectQualifier}@(Model.ModuleQualifier)@(Model.Name) WHERE @(Model.Table.FirstPrimaryKeyParameter().Name)=@@0", @(Model.Table.FirstPrimaryKeyParameter().Name.Lowered()));
|
||||
context.Execute(System.Data.CommandType.Text,
|
||||
"INSERT INTO {databaseOwner}{objectQualifier}@(Model.ModuleQualifier)@(Model.Name) (@Model.Table.ParameterList(Globals.ColumnGroup.PrimaryKey, false, false, "", ", ")) " +
|
||||
"SELECT @@0, s.RecordID " +
|
||||
"FROM {databaseOwner}{objectQualifier}SplitDelimitedIDs(@@1, ',') s", @(Model.Table.FirstPrimaryKeyParameter().Name.Lowered()), string.Join(",", @(Model.PluralName.Lowered())));
|
||||
}
|
||||
}
|
||||
public void Delete@(Model.SingularName)(@(Model.Table.ParameterList(Globals.ColumnGroup.PrimaryKey, true, true)))
|
||||
{
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
if (fo.Key != Model.Scope)
|
||||
{
|
||||
@: Requires.NotNull(@(Model.Table.Parameter(fo.Key, false, true, "")));
|
||||
}
|
||||
}
|
||||
using (var context = DataContext.Instance())
|
||||
{
|
||||
context.Execute(System.Data.CommandType.Text,
|
||||
"DELETE FROM {databaseOwner}{objectQualifier}@Model.ModuleQualifier@Model.Name WHERE @(Model.Table.SqlParameterList(Globals.ColumnGroup.PrimaryKey, true, 0, " AND "))",
|
||||
@(Model.Table.ParameterList(Globals.ColumnGroup.PrimaryKey, false, true, "", ",")));
|
||||
}
|
||||
}
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
@: public void Delete@(Model.PluralName)By@(fo.Value.SingularName)(@(Model.Table.Parameter(fo.Key, true, true, "")))
|
||||
@: {
|
||||
@: Requires.NotNull(@(Model.Table.Parameter(fo.Key, false, true, "")));
|
||||
@: using (var context = DataContext.Instance())
|
||||
@: {
|
||||
@: var rep = context.GetRepository<@(Model.TableObjectName)>();
|
||||
@: rep.Delete("WHERE @(Model.Table.Parameter(fo.Key, false, false, ""))=@@0", @(Model.Table.Parameter(fo.Key, false, true, "")));
|
||||
@: }
|
||||
@: }
|
||||
}
|
||||
}
|
||||
|
||||
public partial interface I@(Model.SingularName)Repository
|
||||
{
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
if (fo.Key != Model.Scope)
|
||||
{
|
||||
@: IEnumerable<@(Model.SingularName)> Get@(Model.PluralName)By@(fo.Value.SingularName)(@(Model.Table.Parameter(fo.Key, true, true, "")));
|
||||
}
|
||||
}
|
||||
void Set@(Model.SingularName)(@Model.Table.PrimaryKeyParameterList());
|
||||
void Set@(Model.PluralName)(@(Model.Table.FirstPrimaryKeyParameter().ColumnParameter()), List<int> @(Model.PluralName.Lowered()));
|
||||
void Delete@(Model.SingularName)(@(Model.Table.ParameterList(Globals.ColumnGroup.PrimaryKey, true, true)));
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
@: void Delete@(Model.PluralName)By@(fo.Value.SingularName)(@(Model.Table.Parameter(fo.Key, true, true, "")));
|
||||
}
|
||||
}
|
||||
}
|
||||
152
.templates/RepositoryLinkTablePlus.cshtml
Normal file
152
.templates/RepositoryLinkTablePlus.cshtml
Normal file
@@ -0,0 +1,152 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DotNetNuke.Common;
|
||||
using DotNetNuke.Data;
|
||||
using DotNetNuke.Framework;
|
||||
using @(Settings.RootNameSpace).Models.@(Model.PluralName);
|
||||
|
||||
namespace @(Settings.RootNameSpace).Repositories
|
||||
{
|
||||
|
||||
public partial class @(Model.SingularName)Repository : ServiceLocator<I@(Model.SingularName)Repository, @(Model.SingularName)Repository>, I@(Model.SingularName)Repository
|
||||
{
|
||||
protected override Func<I@(Model.SingularName)Repository> GetFactory()
|
||||
{
|
||||
return () => new @(Model.SingularName)Repository();
|
||||
}
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
if (fo.Key != Model.Scope)
|
||||
{
|
||||
@: public IEnumerable<@(Model.SingularName)> Get@(Model.PluralName)By@(fo.Value.SingularName)(@(Model.Table.Parameter(fo.Key, true, true, "")))
|
||||
@: {
|
||||
@: using (var context = DataContext.Instance())
|
||||
@: {
|
||||
@: return context.ExecuteQuery<@(Model.SingularName)>(System.Data.CommandType.Text,
|
||||
@: "SELECT * FROM {databaseOwner}{objectQualifier}@Model.Prefix@Model.ModuleQualifier@Model.Name WHERE @(Model.Table.Parameter(fo.Key, false, false, ""))=@@0",
|
||||
@: @(Model.Table.Parameter(fo.Key, false, true, "")));
|
||||
@: }
|
||||
@: }
|
||||
}
|
||||
}
|
||||
public @(Model.SingularName) Get@(Model.SingularName)(@Model.Table.PrimaryKeyParameterList())
|
||||
{
|
||||
using (var context = DataContext.Instance())
|
||||
{
|
||||
return context.ExecuteSingleOrDefault<@(Model.SingularName)>(System.Data.CommandType.Text,
|
||||
"SELECT * FROM {databaseOwner}{objectQualifier}@Model.Prefix@Model.ModuleQualifier@Model.Name WHERE @(Model.Table.SqlParameterList(Globals.ColumnGroup.PrimaryKey, true, 0, " AND "))",
|
||||
@(Model.Table.ParameterList(Globals.ColumnGroup.PrimaryKey, false, true, "", ",")));
|
||||
}
|
||||
}
|
||||
public void Add@(Model.SingularName)(@(Model.TableObjectName) @(Model.SingularNameLowered)@(Model.HasAuditFields ? ", int userId" : ""))
|
||||
{
|
||||
Requires.NotNull(@(Model.SingularNameLowered));
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
if (fo.Key != Model.Scope)
|
||||
{
|
||||
@: Requires.NotNull(@(Model.SingularNameLowered).@(Model.Table.Parameter(fo.Key, false, false, "")));
|
||||
}
|
||||
}
|
||||
@if (Model.HasAuditFields)
|
||||
{
|
||||
@: @(Model.SingularNameLowered).CreatedByUserID = userId;
|
||||
@: @(Model.SingularNameLowered).CreatedOnDate = DateTime.Now;
|
||||
@: @(Model.SingularNameLowered).LastModifiedByUserID = userId;
|
||||
@: @(Model.SingularNameLowered).LastModifiedOnDate = DateTime.Now;
|
||||
}
|
||||
using (var context = DataContext.Instance())
|
||||
{
|
||||
context.Execute(System.Data.CommandType.Text,
|
||||
"IF NOT EXISTS (SELECT * FROM {databaseOwner}{objectQualifier}@(Model.ModuleQualifier)@(Model.Name) " +
|
||||
"WHERE @Model.Table.SqlParameterList(Globals.ColumnGroup.PrimaryKey, true, 0, " AND ")) " +
|
||||
"INSERT INTO {databaseOwner}{objectQualifier}@(Model.ModuleQualifier)@(Model.Name) (@Model.Table.ParameterList(Globals.ColumnGroup.All, false, false, "", ", ")) " +
|
||||
"SELECT @(Globals.GetSqlParameterNumbers(Model.Table.Columns.Count, 0, ", "))", @(Model.Table.ParameterList(Globals.ColumnGroup.All, false, false, Model.SingularNameLowered + ".", ", ")));
|
||||
}
|
||||
}
|
||||
public void Delete@(Model.SingularName)(@(Model.TableObjectName) @(Model.SingularNameLowered))
|
||||
{
|
||||
Delete@(Model.SingularName)(@(Model.Table.ParameterList(Globals.ColumnGroup.PrimaryKey, false, false, Model.SingularNameLowered + ".", ", ")));
|
||||
}
|
||||
public void Delete@(Model.SingularName)(@(Model.Table.ParameterList(Globals.ColumnGroup.PrimaryKey, true, true)))
|
||||
{
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
if (fo.Key != Model.Scope)
|
||||
{
|
||||
@: Requires.NotNull(@(Model.Table.Parameter(fo.Key, false, true, "")));
|
||||
}
|
||||
}
|
||||
using (var context = DataContext.Instance())
|
||||
{
|
||||
context.Execute(System.Data.CommandType.Text,
|
||||
"DELETE FROM {databaseOwner}{objectQualifier}@Model.ModuleQualifier@Model.Name WHERE @(Model.Table.SqlParameterList(Globals.ColumnGroup.PrimaryKey, true, 0, " AND "))",
|
||||
@(Model.Table.ParameterList(Globals.ColumnGroup.PrimaryKey, false, true, "", ",")));
|
||||
}
|
||||
}
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
if (fo.Key != Model.Scope)
|
||||
{
|
||||
@: public void Delete@(Model.PluralName)By@(fo.Value.SingularName)(@(Model.Table.Parameter(fo.Key, true, true, "")))
|
||||
@: {
|
||||
@: using (var context = DataContext.Instance())
|
||||
@: {
|
||||
@: context.Execute(System.Data.CommandType.Text,
|
||||
@: "DELETE FROM {databaseOwner}{objectQualifier}@Model.ModuleQualifier@Model.Name WHERE @(Model.Table.Parameter(fo.Key, false, false, ""))=@@0",
|
||||
@: @(Model.Table.Parameter(fo.Key, false, true, "")));
|
||||
@: }
|
||||
@: }
|
||||
}
|
||||
}
|
||||
public void Update@(Model.SingularName)(@(Model.TableObjectName) @(Model.SingularNameLowered)@(Model.HasAuditFields ? ", int userId" : ""))
|
||||
{
|
||||
Requires.NotNull(@(Model.SingularNameLowered));
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
if (fo.Key != Model.Scope)
|
||||
{
|
||||
@: Requires.NotNull(@(Model.SingularNameLowered).@(Model.Table.Parameter(fo.Key, false, false, "")));
|
||||
}
|
||||
}
|
||||
@if (Model.HasAuditFields)
|
||||
{
|
||||
@: @(Model.SingularNameLowered).LastModifiedByUserID = userId;
|
||||
@: @(Model.SingularNameLowered).LastModifiedOnDate = DateTime.Now;
|
||||
}
|
||||
using (var context = DataContext.Instance())
|
||||
{
|
||||
var rep = context.GetRepository<@(Model.TableObjectName)>();
|
||||
rep.Update("SET @(Model.Table.SqlParameterList(Globals.ColumnGroup.NonePrimaryKey, true, 0, ", ")) WHERE @(Model.Table.SqlParameterList(Globals.ColumnGroup.PrimaryKey, true, Model.Table.GetColumns(Globals.ColumnGroup.NonePrimaryKey).Count, " AND "))",
|
||||
@(Model.Table.ParameterList(Globals.ColumnGroup.NonePrimaryKey, false, false, Model.SingularNameLowered + ".", ",")), @(Model.Table.ParameterList(Globals.ColumnGroup.PrimaryKey, false, false, Model.SingularNameLowered + ".", ",")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial interface I@(Model.SingularName)Repository
|
||||
{
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
if (fo.Key != Model.Scope)
|
||||
{
|
||||
@: IEnumerable<@(Model.SingularName)> Get@(Model.PluralName)By@(fo.Value.SingularName)(@(Model.Table.Parameter(fo.Key, true, true, "")));
|
||||
}
|
||||
}
|
||||
@(Model.SingularName) Get@(Model.SingularName)(@Model.Table.PrimaryKeyParameterList());
|
||||
void Add@(Model.SingularName)(@(Model.TableObjectName) @(Model.SingularNameLowered)@(Model.HasAuditFields ? ", int userId" : ""));
|
||||
void Delete@(Model.SingularName)(@(Model.TableObjectName) @(Model.SingularNameLowered));
|
||||
void Delete@(Model.SingularName)(@(Model.Table.ParameterList(Globals.ColumnGroup.PrimaryKey, true, true)));
|
||||
@foreach (KeyValuePair<String, ObjectDefinition> fo in Model.ForeignKeyObjects)
|
||||
{
|
||||
if (fo.Key != Model.Scope)
|
||||
{
|
||||
@: void Delete@(Model.PluralName)By@(fo.Value.SingularName)(@(Model.Table.Parameter(fo.Key, true, true, "")));
|
||||
}
|
||||
}
|
||||
void Update@(Model.SingularName)(@(Model.TableObjectName) @(Model.SingularNameLowered)@(Model.HasAuditFields ? ", int userId" : ""));
|
||||
}
|
||||
}
|
||||
21
.templates/Repository_Empty.cshtml
Normal file
21
.templates/Repository_Empty.cshtml
Normal file
@@ -0,0 +1,21 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DotNetNuke.Common;
|
||||
using DotNetNuke.Data;
|
||||
using DotNetNuke.Framework;
|
||||
using @(Settings.RootNameSpace).Models.@(Model.PluralName);
|
||||
|
||||
namespace @(Settings.RootNameSpace).Repositories
|
||||
{
|
||||
public partial class @(Model.SingularName)Repository : ServiceLocator<I@(Model.SingularName)Repository, @(Model.SingularName)Repository>, I@(Model.SingularName)Repository
|
||||
{
|
||||
}
|
||||
public partial interface I@(Model.SingularName)Repository
|
||||
{
|
||||
}
|
||||
}
|
||||
51
.templates/Sprocs.cshtml
Normal file
51
.templates/Sprocs.cshtml
Normal file
@@ -0,0 +1,51 @@
|
||||
@inherits RazorTemplate<Dictionary<String, SprocDefinition>>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
@{}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DotNetNuke.Data;
|
||||
|
||||
namespace @(Settings.RootNameSpace).Data
|
||||
{
|
||||
public class Sprocs
|
||||
{
|
||||
@foreach (SprocDefinition sp in Model.Values)
|
||||
{
|
||||
var objName = "object";
|
||||
if (sp.ReturnObject != "")
|
||||
{
|
||||
objName = sp.ReturnObject;
|
||||
}
|
||||
@: // @Raw(System.Text.RegularExpressions.Regex.Replace(sp.Sproc.TextBody, "(\n|\r\n?)", "\r\n // "));
|
||||
if (sp.ReturnsData)
|
||||
{
|
||||
@: public static IEnumerable<@objName> @(sp.Name)(@sp.Sproc.ParameterList(true, true, "", ", "))
|
||||
}
|
||||
else
|
||||
{
|
||||
@: public static void @(sp.Name)(@sp.Sproc.ParameterList(true, true, "", ", "))
|
||||
}
|
||||
@: {
|
||||
@: using (var context = DataContext.Instance())
|
||||
@: {
|
||||
if (sp.ReturnsData)
|
||||
{
|
||||
@: return context.ExecuteQuery<@objName>(System.Data.CommandType.StoredProcedure,
|
||||
}
|
||||
else
|
||||
{
|
||||
@: context.Execute(System.Data.CommandType.StoredProcedure,
|
||||
}
|
||||
var pl = sp.Sproc.ParameterList(false, true, "", ", ");
|
||||
var comma = string.IsNullOrEmpty(pl) ? "" : ",";
|
||||
@: "@sp.Sproc.Name"@comma
|
||||
@: @pl);
|
||||
@: }
|
||||
@: }
|
||||
@:
|
||||
}
|
||||
}
|
||||
}
|
||||
89
.templates/TypeScriptIModel.cshtml
Normal file
89
.templates/TypeScriptIModel.cshtml
Normal file
@@ -0,0 +1,89 @@
|
||||
@inherits RazorTemplate<ObjectDefinition>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
export interface I@(Model.SingularName) {
|
||||
@foreach (Column c in Model.TableColumns)
|
||||
{
|
||||
@: @(c.Name)@(c.NullSuffix()): @(c.DataType.DataTypeToJs());
|
||||
}
|
||||
@if (Model.HasAuditFields)
|
||||
{
|
||||
@: CreatedByUserID: number;
|
||||
@: CreatedOnDate: Date;
|
||||
@: LastModifiedByUserID: number;
|
||||
@: LastModifiedOnDate: Date;
|
||||
}
|
||||
@foreach (Column c in Model.UniqueViewColumns)
|
||||
{
|
||||
@: @(c.Name)@(c.NullSuffix()): @(c.DataType.DataTypeToJs());
|
||||
}
|
||||
}
|
||||
|
||||
export class @(Model.SingularName) implements I@(Model.SingularName) {
|
||||
@foreach (Column c in Model.TableColumns)
|
||||
{
|
||||
@: @(c.Name)@(c.NullSuffix()): @(c.DataType.DataTypeToJs());
|
||||
}
|
||||
@if (Model.HasAuditFields)
|
||||
{
|
||||
@: CreatedByUserID: number;
|
||||
@: CreatedOnDate: Date;
|
||||
@: LastModifiedByUserID: number;
|
||||
@: LastModifiedOnDate: Date;
|
||||
}
|
||||
@foreach (Column c in Model.UniqueViewColumns)
|
||||
{
|
||||
@: @(c.Name)@(c.NullSuffix()): @(c.DataType.DataTypeToJs());
|
||||
}
|
||||
constructor() {
|
||||
@foreach (Column c in Model.TableColumns)
|
||||
{
|
||||
if (!c.Nullable) {
|
||||
switch (c.DataType.DataTypeToJs())
|
||||
{
|
||||
case "number":
|
||||
@: this.@(c.Name) = -1;
|
||||
break;
|
||||
case "string":
|
||||
@: this.@(c.Name) = "";
|
||||
break;
|
||||
case "boolean":
|
||||
@: this.@(c.Name) = false;
|
||||
break;
|
||||
case "Date":
|
||||
@: this.@(c.Name) = new Date();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@if (Model.HasAuditFields)
|
||||
{
|
||||
@: this.CreatedByUserID = -1;
|
||||
@: this.CreatedOnDate = new Date();
|
||||
@: this.LastModifiedByUserID = -1;
|
||||
@: this.LastModifiedOnDate = new Date();
|
||||
}
|
||||
@foreach (Column c in Model.UniqueViewColumns)
|
||||
{
|
||||
if (!c.Nullable) {
|
||||
switch (c.DataType.DataTypeToJs())
|
||||
{
|
||||
case "number":
|
||||
@: this.@(c.Name) = -1;
|
||||
break;
|
||||
case "string":
|
||||
@: this.@(c.Name) = "";
|
||||
break;
|
||||
case "boolean":
|
||||
@: this.@(c.Name) = false;
|
||||
break;
|
||||
case "Date":
|
||||
@: this.@(c.Name) = new Date();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
.templates/TypeScriptIModelIndex.cshtml
Normal file
11
.templates/TypeScriptIModelIndex.cshtml
Normal file
@@ -0,0 +1,11 @@
|
||||
@inherits RazorTemplate<string>
|
||||
@using Bring2mind.CodeGen.Cli.Common
|
||||
@using Bring2mind.CodeGen.Cli.Data
|
||||
@using Bring2mind.CodeGen.Cli.Razor
|
||||
@using Microsoft.SqlServer.Management.Smo
|
||||
@using System.Linq
|
||||
|
||||
@foreach (ObjectDefinition od in DnnDb.Objects.Values.OrderBy(od => od.SingularName))
|
||||
{
|
||||
@:export * from './I@(od.SingularName)';
|
||||
}
|
||||
Reference in New Issue
Block a user