@inherits Microsoft.VisualStudio.Web.CodeGeneration.Templating.RazorTemplateBase
@using Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore
@using System.Collections.Generic
@using System.Linq
@@model @Model.ViewDataTypeName

@{
    if (Model.IsPartialView)
    {
    }
    else if (Model.IsLayoutPageSelected)
    {
@:@@{
    @:ViewData["Title"] = "@Model.ViewName";
        if (!string.IsNullOrEmpty(Model.LayoutPageFile))
        {
    @:Layout = "@Model.LayoutPageFile";
        }
@:}
@:
@:<h1>@Model.ViewName</h1>
@:
    }
    else
    {
@:@@{
    @:Layout = null;
@:}
@:
@:<!DOCTYPE html>
@:
@:<html>
@:<head>
    @:<meta name="viewport" content="width=device-width" />
    @:<title>@Model.ViewName</title>
@:</head>
@:<body>
@:
        //    PushIndent("    ");
    }
}
<h3>Are you sure you want to delete this?</h3>
<div>
    <h4>@Model.ViewDataTypeShortName</h4>
    <hr />
    <dl class="row">
@{
    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)
        {
        <dt class = "col-sm-2">
            @@Html.DisplayNameFor(model => model.@GetValueExpression(property))
        </dt>
        <dd class = "col-sm-10">
            @@Html.DisplayFor(model => model.@GetValueExpression(property))
        </dd>
        }
        else if (navigationLookup.TryGetValue(item.Name, out INavigationMetadata navigation))
        {
        <dt class = "col-sm-2">
            @@Html.DisplayNameFor(model => model.@GetValueExpression(navigation))
        </dt>
        <dd class = "col-sm-10">
            @@Html.DisplayFor(model => model.@GetValueExpression(navigation).@navigation.DisplayPropertyName)
        </dd class>
        }
    }
    @:</dl>
    @:
    @:<form asp-action="@Model.ViewName">
        foreach (var property in Model.ModelMetadata.Properties)
        {
            if(property.IsPrimaryKey){
        @:<input type="hidden" asp-for="@GetValueExpression(property)" />
            }
        }
        @:<input type="submit" value="Delete" class="k-button k-primary" /> |
        @:<a asp-action="Index" class="k-button">Back to List</a>
    @:</form>
@:</div>
    if (!Model.IsPartialView && !Model.IsLayoutPageSelected)
    {
        //ClearIndent();
@:</body>
@:</html>
    }
}
@functions
{
    string GetValueExpression(IPropertyMetadata property)
    {
        return property.PropertyName;
    }

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