Subversion Repository Public Repository

ChrisCompleteCodeTrunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
@inherits Microsoft.VisualStudio.Web.CodeGeneration.Templating.RazorTemplateBase
@using Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore
@using System.Collections.Generic
@using System.Linq
@@model @GetEnumerableTypeExpression(Model.ViewDataTypeName)

@{
    if (Model.IsPartialView)
    {
    }
    else if (Model.IsLayoutPageSelected)
    {
@:@@{
    @:ViewData["Title"] = "@Model.ViewName";
        if (!string.IsNullOrEmpty(Model.LayoutPageFile))
        {
    @:Layout = "@Model.LayoutPageFile";
        }
@:}
@:
@:<h2>@Model.ViewName</h2>
@:
    }
    else
    {
@:@@{
    @:Layout = null;
@:}
@:
@:<!DOCTYPE html>
@:
@:<html>
@:<head>
    @:<meta name="viewport" content="width=device-width" />
    @:<title>@Model.ViewName</title>
@:</head>
@:<body>
        //    PushIndent("    ");
    }
@:<p>
    @:<a asp-action="Create">Create New</a>
@:</p>
@:<table class="table">
    @:<thead>
        @:<tr>
        Dictionary<string, IPropertyMetadata> propertyLookup = ((IModelMetadata)Model.ModelMetadata).Properties.ToDictionary(x => x.PropertyName, x => x);
        Dictionary<string, INavigationMetadata> navigationLookup = ((IModelMetadata)Model.ModelMetadata).Navigations.ToDictionary(x => x.AssociationPropertyName, x => x);

        foreach (var item in Model.ModelMetadata.ModelType.GetProperties())
        {
            if (propertyLookup.TryGetValue(item.Name, out IPropertyMetadata property)
                && property.Scaffold && !property.IsForeignKey && !property.IsPrimaryKey)
            {
            <th>
                @@Html.DisplayNameFor(model => model.@GetValueExpression(property))
            </th>
            }
            else if (navigationLookup.TryGetValue(item.Name, out INavigationMetadata navigation))
            {
            <th>
                @@Html.DisplayNameFor(model => model.@GetValueExpression(navigation))
            </th>
            }
        }
            @:<th></th>
        @:</tr>
    @:</thead>
    @:<tbody>
@:@@foreach (var item in Model) {
        @:<tr>
        foreach (var item in Model.ModelMetadata.ModelType.GetProperties())
        {
            if (propertyLookup.TryGetValue(item.Name, out IPropertyMetadata property)
                && property.Scaffold && !property.IsForeignKey && !property.IsPrimaryKey)
            {
            <td>
                @@Html.DisplayFor(modelItem => item.@GetValueExpression(property))
            </td>
            }
            else if (navigationLookup.TryGetValue(item.Name, out INavigationMetadata navigation))
            {
            <td>
                @@Html.DisplayFor(modelItem => item.@GetValueExpression(navigation).@navigation.DisplayPropertyName)
            </td>
            }
        }
        string pkName = GetPrimaryKeyName();
        if (pkName != null)
        {
            @:<td>
                @:<a asp-action="Edit" asp-route-id="@@item.@pkName">Edit</a> |
                @:<a asp-action="Details" asp-route-id="@@item.@pkName">Details</a> |
                @:<a asp-action="Delete" asp-route-id="@@item.@pkName">Delete</a>
            @:</td>
        }
        else
        {
            <td>
                @@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
                @@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
                @@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
            </td>
        }
        @:</tr>
@:}
    @:</tbody>

@:</table>
    if(!Model.IsPartialView && !Model.IsLayoutPageSelected)
    {
        //ClearIndent();
@:</body>
@:</html>
    }
}
@functions
{
    string GetPrimaryKeyName()
    {
        return (Model.ModelMetadata.PrimaryKeys != null && Model.ModelMetadata.PrimaryKeys.Length == 1)
        ? Model.ModelMetadata.PrimaryKeys[0].PropertyName
        : null;
    }

    string GetValueExpression(IPropertyMetadata property)
    {
        return property.PropertyName;
    }

    string GetValueExpression(INavigationMetadata navigation)
    {
        return navigation.AssociationPropertyName;
    }

    string GetEnumerableTypeExpression(string typeName)
    {
        return "IEnumerable<" + typeName + ">";
    }
}

Commits for ChrisCompleteCodeTrunk/ActionTireCo/packages/Microsoft.VisualStudio.Web.CodeGenerators.Mvc.2.1.0/Templates/ViewGenerator/List.cshtml

Diff revisions: vs.
Revision Author Commited Message
1 BBDSCHRIS picture BBDSCHRIS Wed 22 Aug, 2018 20:08:03 +0000