-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
225 changed files
with
255,434 additions
and
14,382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
159 changes: 159 additions & 0 deletions
159
GARDIS/CodeTemplates/Scaffolders/MvcScaffolding.Controller/ControllerWithContext.cs.t4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
<#@ template language="C#" HostSpecific="True" inherits="DynamicTransform" #> | ||
<#@ Output Extension="cs" #> | ||
<#@ assembly name="System.Data.Entity" #> | ||
<#@ import namespace="System.Collections" #> | ||
<#@ import namespace="System.Collections.Generic" #> | ||
<#@ import namespace="System.Linq" #> | ||
<#@ import namespace="System.Text.RegularExpressions" #> | ||
<#@ import namespace="EnvDTE" #> | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Data.Entity; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.Mvc; | ||
<# if(!string.IsNullOrEmpty(Model.ModelTypeNamespace)) { #> | ||
using <#= Model.ModelTypeNamespace #>; | ||
<# } #> | ||
<# if(Model.DbContextNamespace != Model.ModelTypeNamespace) { #> | ||
using <#= Model.DbContextNamespace #>; | ||
<# } #> | ||
|
||
namespace <#= Model.ControllerNamespace #> | ||
{ | ||
<# | ||
var modelType = (CodeType)Model.ModelType; | ||
var modelName = modelType.Name; | ||
var modelNamePlural = Model.ModelTypePluralized; | ||
var modelVariable = modelName.ToLower(); | ||
var relatedEntities = ((IEnumerable)Model.RelatedEntities).OfType<RelatedEntityInfo>(); | ||
var primaryKeyProperty = modelType.VisibleMembers().OfType<CodeProperty>().Single(x => x.Name == Model.PrimaryKey); | ||
var routingName = Regex.Replace(Model.ControllerName, "Controller$", "", RegexOptions.IgnoreCase); | ||
var isObjectContext = ((CodeType)Model.DbContextType).IsAssignableTo<System.Data.Objects.ObjectContext>(); | ||
#> | ||
public class <#= Model.ControllerName #> : Controller | ||
{ | ||
private <#= ((CodeType)Model.DbContextType).Name #> context = new <#= ((CodeType)Model.DbContextType).Name #>(); | ||
|
||
// | ||
// GET: /<#= routingName #>/ | ||
|
||
public ViewResult Index() | ||
{ | ||
<# | ||
var propertiesToInclude = relatedEntities.Select(relation => relation.LazyLoadingProperty).Where(x => x != null); | ||
var includeExpressions = isObjectContext | ||
? String.Join("", propertiesToInclude.Select(x => String.Format(".Include(\"{0}\")", x.Name))) | ||
: String.Join("", propertiesToInclude.Select(x => String.Format(".Include({0} => {0}.{1})", modelVariable, x.Name))); | ||
#> | ||
return View(context.<#= modelNamePlural #><#= includeExpressions #>.ToList()); | ||
} | ||
|
||
// | ||
// GET: /<#= routingName #>/Details/5 | ||
|
||
public ViewResult Details(<#= primaryKeyProperty.Type.AsString #> id) | ||
{ | ||
<#= modelName #> <#= modelVariable #> = context.<#= modelNamePlural #>.Single(x => x.<#= primaryKeyProperty.Name #> == id); | ||
return View(<#= modelVariable #>); | ||
} | ||
|
||
// | ||
// GET: /<#= routingName #>/Create | ||
|
||
public ActionResult Create() | ||
{ | ||
<# foreach(var relatedEntity in relatedEntities.Where(x => x.RelationType == RelationType.Parent)) { #> | ||
ViewBag.Possible<#= relatedEntity.RelationNamePlural #> = context.<#= relatedEntity.RelatedEntityTypeNamePlural #>; | ||
<# } #> | ||
return View(); | ||
} | ||
|
||
// | ||
// POST: /<#= routingName #>/Create | ||
|
||
[HttpPost] | ||
public ActionResult Create(<#= modelName #> <#= modelVariable #>) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
<# if(primaryKeyProperty.Type.AsString == "System.Guid") { #> | ||
<#= modelVariable #>.<#= primaryKeyProperty.Name #> = Guid.NewGuid(); | ||
<# } #> | ||
<# if(isObjectContext) { #> | ||
context.<#= modelNamePlural #>.AddObject(<#= modelVariable #>); | ||
<# } else { #> | ||
context.<#= modelNamePlural #>.Add(<#= modelVariable #>); | ||
<# } #> | ||
context.SaveChanges(); | ||
return RedirectToAction("Index"); | ||
} | ||
|
||
<# foreach(var relatedEntity in relatedEntities.Where(x => x.RelationType == RelationType.Parent)) { #> | ||
ViewBag.Possible<#= relatedEntity.RelationNamePlural #> = context.<#= relatedEntity.RelatedEntityTypeNamePlural #>; | ||
<# } #> | ||
return View(<#= modelVariable #>); | ||
} | ||
|
||
// | ||
// GET: /<#= routingName #>/Edit/5 | ||
|
||
public ActionResult Edit(<#= primaryKeyProperty.Type.AsString #> id) | ||
{ | ||
<#= modelName #> <#= modelVariable #> = context.<#= modelNamePlural #>.Single(x => x.<#= primaryKeyProperty.Name #> == id); | ||
<# foreach(var relatedEntity in relatedEntities.Where(x => x.RelationType == RelationType.Parent)) { #> | ||
ViewBag.Possible<#= relatedEntity.RelationNamePlural #> = context.<#= relatedEntity.RelatedEntityTypeNamePlural #>; | ||
<# } #> | ||
return View(<#= modelVariable #>); | ||
} | ||
|
||
// | ||
// POST: /<#= routingName #>/Edit/5 | ||
|
||
[HttpPost] | ||
public ActionResult Edit(<#= modelName #> <#= modelVariable #>) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
<# if(isObjectContext) { #> | ||
context.<#= modelNamePlural #>.Attach(<#= modelVariable #>); | ||
context.ObjectStateManager.ChangeObjectState(<#= modelVariable #>, EntityState.Modified); | ||
<# } else { #> | ||
context.Entry(<#= modelVariable #>).State = EntityState.Modified; | ||
<# } #> | ||
context.SaveChanges(); | ||
return RedirectToAction("Index"); | ||
} | ||
<# foreach(var relatedEntity in relatedEntities.Where(x => x.RelationType == RelationType.Parent)) { #> | ||
ViewBag.Possible<#= relatedEntity.RelationNamePlural #> = context.<#= relatedEntity.RelatedEntityTypeNamePlural #>; | ||
<# } #> | ||
return View(<#= modelVariable #>); | ||
} | ||
|
||
// | ||
// GET: /<#= routingName #>/Delete/5 | ||
|
||
public ActionResult Delete(<#= primaryKeyProperty.Type.AsString #> id) | ||
{ | ||
<#= modelName #> <#= modelVariable #> = context.<#= modelNamePlural #>.Single(x => x.<#= primaryKeyProperty.Name #> == id); | ||
return View(<#= modelVariable #>); | ||
} | ||
|
||
// | ||
// POST: /<#= routingName #>/Delete/5 | ||
|
||
[HttpPost, ActionName("Delete")] | ||
public ActionResult DeleteConfirmed(<#= primaryKeyProperty.Type.AsString #> id) | ||
{ | ||
<#= modelName #> <#= modelVariable #> = context.<#= modelNamePlural #>.Single(x => x.<#= primaryKeyProperty.Name #> == id); | ||
<# if(isObjectContext) { #> | ||
context.<#= modelNamePlural #>.DeleteObject(<#= modelVariable #>); | ||
<# } else { #> | ||
context.<#= modelNamePlural #>.Remove(<#= modelVariable #>); | ||
<# } #> | ||
context.SaveChanges(); | ||
return RedirectToAction("Index"); | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
GARDIS/CodeTemplates/Scaffolders/T4Scaffolding.EFDbContext/DbContextEntityMember.cs.t4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<#@ Template Language="C#" HostSpecific="True" Inherits="DynamicTransform" #> | ||
public DataBase<<#= ((EnvDTE.CodeType)Model.EntityType).FullName #>> <#= Model.EntityTypeNamePluralized #> { get { return new DataBase<<#= ((EnvDTE.CodeType)Model.EntityType).FullName #>>(); } } |
103 changes: 103 additions & 0 deletions
103
GARDIS/CodeTemplates/Scaffolders/T4Scaffolding.EFRepository/Repository.cs.t4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<#@ template language="C#" HostSpecific="True" inherits="DynamicTransform" #> | ||
<#@ assembly name="System.Data.Entity" #> | ||
<#@ import namespace="System.Linq" #> | ||
<#@ import namespace="EnvDTE" #> | ||
<#@ Output Extension="cs" #> | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Data.Entity; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Web; | ||
<# foreach(var ns in new[] { Model.ModelTypeNamespace, Model.DbContextNamespace }.Where(x => !string.IsNullOrEmpty(x) && (x != Model.RepositoryNamespace)).Distinct()) { #> | ||
using <#= ns #>; | ||
<# } #> | ||
|
||
namespace <#= Model.RepositoryNamespace #> | ||
{ | ||
<# | ||
var modelType = (CodeType)Model.ModelType; | ||
var modelName = modelType.Name; | ||
var modelNamePlural = Model.ModelTypePluralized; | ||
var contextName = ((CodeType)Model.DbContextType).Name; | ||
var primaryKeyProperty = modelType.VisibleMembers().OfType<CodeProperty>().Single(x => x.Name == Model.PrimaryKey); | ||
var isObjectContext = ((CodeType)Model.DbContextType).IsAssignableTo<System.Data.Objects.ObjectContext>(); | ||
#> | ||
public class <#= modelName #>Repository : I<#= modelName #>Repository | ||
{ | ||
<#= contextName #> context = new <#= contextName #>(); | ||
|
||
public IQueryable<<#= modelName #>> All | ||
{ | ||
get { return context.<#= modelNamePlural #>; } | ||
} | ||
|
||
public IQueryable<<#= modelName #>> AllIncluding(params Expression<Func<<#= modelName #>, object>>[] includeProperties) | ||
{ | ||
IQueryable<<#= modelName #>> query = context.<#= modelNamePlural #>; | ||
foreach (var includeProperty in includeProperties) { | ||
query = query.Include(includeProperty); | ||
} | ||
return query; | ||
} | ||
|
||
public <#= modelName #> Find(<#= primaryKeyProperty.Type.AsString #> id) | ||
{ | ||
<# if(isObjectContext) { #> | ||
return context.<#= modelNamePlural #>.Single(x => x.<#= Model.PrimaryKey #> == id); | ||
<# } else { #> | ||
return context.<#= modelNamePlural #>.Find(id); | ||
<# } #> | ||
} | ||
|
||
public void InsertOrUpdate(<#= modelName #> <#= modelName.ToLower() #>) | ||
{ | ||
if (<#= modelName.ToLower() #>.<#= Model.PrimaryKey #> == default(<#= primaryKeyProperty.Type.AsString #>)) { | ||
// New entity | ||
<# if(primaryKeyProperty.Type.AsString == "System.Guid") { #> | ||
<#= modelName.ToLower() #>.<#= primaryKeyProperty.Name #> = Guid.NewGuid(); | ||
<# } #> | ||
<# if(isObjectContext) { #> | ||
context.<#= modelNamePlural #>.AddObject(<#= modelName.ToLower() #>); | ||
<# } else { #> | ||
context.<#= modelNamePlural #>.Add(<#= modelName.ToLower() #>); | ||
<# } #> | ||
} else { | ||
// Existing entity | ||
<# if(isObjectContext) { #> | ||
context.<#= modelNamePlural #>.Attach(<#= modelName.ToLower() #>); | ||
context.ObjectStateManager.ChangeObjectState(<#= modelName.ToLower() #>, EntityState.Modified); | ||
<# } else { #> | ||
context.Entry(<#= modelName.ToLower() #>).State = EntityState.Modified; | ||
<# } #> | ||
} | ||
} | ||
|
||
public void Delete(<#= primaryKeyProperty.Type.AsString #> id) | ||
{ | ||
<# if(isObjectContext) { #> | ||
var <#= modelName.ToLower() #> = context.<#= modelNamePlural #>.Single(x => x.<#= Model.PrimaryKey #> == id); | ||
context.<#= modelNamePlural #>.DeleteObject(<#= modelName.ToLower() #>); | ||
<# } else { #> | ||
var <#= modelName.ToLower() #> = context.<#= modelNamePlural #>.Find(id); | ||
context.<#= modelNamePlural #>.Remove(<#= modelName.ToLower() #>); | ||
<# } #> | ||
} | ||
|
||
public void Save() | ||
{ | ||
context.SaveChanges(); | ||
} | ||
} | ||
|
||
public interface I<#= modelName #>Repository | ||
{ | ||
IQueryable<<#= modelName #>> All { get; } | ||
IQueryable<<#= modelName #>> AllIncluding(params Expression<Func<<#= modelName #>, object>>[] includeProperties); | ||
<#= modelName #> Find(<#= primaryKeyProperty.Type.AsString #> id); | ||
void InsertOrUpdate(<#= modelName #> <#= modelName.ToLower() #>); | ||
void Delete(<#= primaryKeyProperty.Type.AsString #> id); | ||
void Save(); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+143 Bytes
GARDIS/Content/themes/base/images/ui-bg_highlight-soft_75_cccccc_1x100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.