[Tizen] Add BuildTools 2.1.0-rc1-02804-05
[platform/upstream/coreclr.git] / Tools / dotnetcli / sdk / NuGetFallbackFolder / microsoft.visualstudio.web.codegenerators.mvc / 2.0.1 / Templates / RazorPageGenerator / CreatePageModel.cshtml
1 @inherits Microsoft.VisualStudio.Web.CodeGeneration.Templating.RazorTemplateBase
2 @using System.Collections.Generic
3 @using System.Linq
4 using System;
5 using System.Collections.Generic;
6 using System.Linq;
7 using System.Threading.Tasks;
8 using Microsoft.AspNetCore.Mvc;
9 using Microsoft.AspNetCore.Mvc.RazorPages;
10 using Microsoft.AspNetCore.Mvc.Rendering;
11 @{
12     var entitySetName = Model.ModelMetadata.EntitySetName;
13     var entitySetVar = Model.EntitySetVariable ??
14         (String.IsNullOrEmpty(entitySetName)
15             ? entitySetName
16             : (entitySetName.Substring(0, length: 1).ToLowerInvariant() + entitySetName.Substring(1)));
17
18     var relatedProperties = new Dictionary<string, dynamic>();
19     foreach (var nav in Model.ModelMetadata.Navigations)
20     {
21         relatedProperties.Add(nav.AssociationPropertyName, nav);
22     }
23
24     foreach (var namespaceName in Model.RequiredNamespaces)
25     {
26 @:using @namespaceName;
27     }
28 }
29
30 namespace @Model.NamespaceName
31 {
32     public class @Model.PageModelClassName : PageModel
33     {
34         private readonly @Model.ContextTypeName _context;
35
36         public @(Model.PageModelClassName)(@Model.ContextTypeName context)
37         {
38             _context = context;
39         }
40
41         public IActionResult OnGet()
42         {
43 @{
44     foreach (var property in relatedProperties.Values)
45     {
46         @:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList(_context.@property.EntitySetName, "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName");
47     }
48 }
49             return Page();
50         }
51
52         [BindProperty]
53         public @Model.ViewDataTypeShortName @Model.ViewDataTypeShortName { get; set; }
54
55         public async Task<IActionResult> OnPostAsync()
56         {
57             if (!ModelState.IsValid)
58             {
59                 return Page();
60             }
61
62             _context.@(Model.ModelTypeName).Add(@Model.ViewDataTypeShortName);
63             await _context.SaveChangesAsync();
64
65             return RedirectToPage("./Index");
66         }
67     }
68 }