Skip to content

Commit

Permalink
Adding scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
park9140 committed Jul 30, 2011
1 parent 6567bac commit 74a72a2
Show file tree
Hide file tree
Showing 225 changed files with 255,434 additions and 14,382 deletions.
3 changes: 3 additions & 0 deletions GARDIS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.0\lib\NET35
EndGlobalSection
EndGlobal
Binary file modified GARDIS.suo
Binary file not shown.
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");
}
}
}
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 #>>(); } }
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.
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

0 comments on commit 74a72a2

Please sign in to comment.