Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move RazorPageGenerator SelectLists from GET handler to OnPageHandlerExecutionAsync #1005

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
@if (relatedProperties.Any())
{
using Microsoft.AspNetCore.Mvc.Filters;
}
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
@{
Expand Down Expand Up @@ -40,12 +44,6 @@ namespace @Model.NamespaceName

public IActionResult OnGet()
{
@{
foreach (var property in relatedProperties.Values)
{
@:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList([email protected], "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName");
}
}
return Page();
}

Expand All @@ -64,5 +62,20 @@ namespace @Model.NamespaceName

return RedirectToPage("./Index");
}
@if (relatedProperties.Any())
{

public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
@{
foreach (var property in relatedProperties.Values)
{
@:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList([email protected], "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName");
}
}

return base.OnPageHandlerExecutionAsync(context, next);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
@if (relatedProperties.Any())
{
using Microsoft.AspNetCore.Mvc.Filters;
}
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -61,12 +65,7 @@ namespace @Model.NamespaceName
{
return NotFound();
}
@{
foreach (var property in relatedProperties.Values)
{
@:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList([email protected], "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName");
}
}

return Page();
}

Expand Down Expand Up @@ -97,6 +96,21 @@ namespace @Model.NamespaceName

return RedirectToPage("./Index");
}
@if (relatedProperties.Any())
{

public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
@{
foreach (var property in relatedProperties.Values)
{
@:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList([email protected], "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName");
}
}

return base.OnPageHandlerExecutionAsync(context, next);
}
}

private bool @(Model.ModelTypeName)Exists(@primaryKeyShortTypeName id)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
@if (relatedProperties.Any())
{
using Microsoft.AspNetCore.Mvc.Filters;
}
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
@{
Expand Down Expand Up @@ -40,12 +44,6 @@ namespace @Model.NamespaceName

public IActionResult OnGet()
{
@{
foreach (var property in relatedProperties.Values)
{
@:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList([email protected], "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName");
}
}
return Page();
}

Expand All @@ -64,5 +62,20 @@ namespace @Model.NamespaceName

return RedirectToPage("./Index");
}
@if (relatedProperties.Any())
{

public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
@{
foreach (var property in relatedProperties.Values)
{
@:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList([email protected], "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName");
}
}

return base.OnPageHandlerExecutionAsync(context, next);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
@if (relatedProperties.Any())
{
using Microsoft.AspNetCore.Mvc.Filters;
}
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -61,12 +65,7 @@ namespace @Model.NamespaceName
{
return NotFound();
}
@{
foreach (var property in relatedProperties.Values)
{
@:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList([email protected], "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName");
}
}

return Page();
}

Expand Down Expand Up @@ -97,6 +96,21 @@ namespace @Model.NamespaceName

return RedirectToPage("./Index");
}
@if (relatedProperties.Any())
{

public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
@{
foreach (var property in relatedProperties.Values)
{
@:ViewData["@(property.ForeignKeyPropertyNames[0])"] = new SelectList([email protected], "@property.PrimaryKeyNames[0]", "@property.DisplayPropertyName");
}
}

return base.OnPageHandlerExecutionAsync(context, next);
}
}

private bool @(Model.ModelTypeName)Exists(@primaryKeyShortTypeName id)
{
Expand Down
9 changes: 8 additions & 1 deletion test/E2E_Test/Compiler/Resources/RazorPages/CarCreateCs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Library1.Models;
Expand All @@ -21,7 +22,6 @@ namespace TestProject

public IActionResult OnGet()
{
ViewData["ManufacturerID"] = new SelectList(_context.Set<Manufacturer>(), "ID", "ID");
return Page();
}

Expand All @@ -40,5 +40,12 @@ namespace TestProject

return RedirectToPage("./Index");
}

public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
ViewData["ManufacturerID"] = new SelectList(_context.Set<Manufacturer>(), "ID", "ID");

return base.OnPageHandlerExecutionAsync(context, next);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using DAL;
Expand All @@ -21,7 +22,6 @@ namespace TestProject

public IActionResult OnGet()
{
ViewData["ManufacturerID"] = new SelectList(_context.Set<Manufacturer>(), "ID", "ID");
return Page();
}

Expand All @@ -40,5 +40,12 @@ namespace TestProject

return RedirectToPage("./Index");
}

public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
ViewData["ManufacturerID"] = new SelectList(_context.Set<Manufacturer>(), "ID", "ID");

return base.OnPageHandlerExecutionAsync(context, next);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Library1.Models;
Expand All @@ -21,7 +22,6 @@ namespace TestProject

public IActionResult OnGet()
{
ViewData["ManufacturerID"] = new SelectList(_context.Set<Manufacturer>(), "ID", "ID");
return Page();
}

Expand All @@ -40,5 +40,12 @@ namespace TestProject

return RedirectToPage("./Index");
}

public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
ViewData["ManufacturerID"] = new SelectList(_context.Set<Manufacturer>(), "ID", "ID");

return base.OnPageHandlerExecutionAsync(context, next);
}
}
}
10 changes: 9 additions & 1 deletion test/E2E_Test/Compiler/Resources/RazorPages/Crud/EditCs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -37,7 +38,7 @@ namespace TestProject
{
return NotFound();
}
ViewData["ManufacturerID"] = new SelectList(_context.Set<Manufacturer>(), "ID", "ID");

return Page();
}

Expand Down Expand Up @@ -69,6 +70,13 @@ namespace TestProject
return RedirectToPage("./Index");
}

public override Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
ViewData["ManufacturerID"] = new SelectList(_context.Set<Manufacturer>(), "ID", "ID");

return base.OnPageHandlerExecutionAsync(context, next);
}

private bool CarExists(string id)
{
return _context.Car.Any(e => e.ID == id);
Expand Down