Файли
openidea/fixtures/aspnet-app/Controllers/ShowsController.cs
T
Glitched Polygons GmbH 75ec6c51a3 feat(csharp): Razor / cshtml / ASP.NET Core MVC support (#7256)
Razor (.cshtml/.razor) gets syntax highlighting, Roslyn's built-in Razor support with the HTML parts projected to the HTML language server (ordered open/close, a reserved projection URI, scoped capability registrations), and MVC navigation between controller actions and their views, including explicit View("...") names, subfolders and areas.

Closes #615

Co-authored-by: GlitchedPolygons <[email protected]>
2026-12-02 16:32:46 +08:00

44 рядки
1.5 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Ticketing.Models;
namespace Ticketing.Controllers;
public sealed class ShowsController(ILogger<ShowsController> logger) : Controller
{
public IActionResult Index(string? q)
{
// TODO: page the list once there are more than a handful of shows.
var pageSize = 20; // Intentional warning: assigned but never used (CS0219).
var shows = Show.All
.Where(s => string.IsNullOrWhiteSpace(q) || s.Title.Contains(q, StringComparison.OrdinalIgnoreCase))
.ToList();
ViewData["Query"] = q;
return View(shows);
}
public IActionResult Details(string id)
{
var show = Show.Find(id); // Set a breakpoint here (QA: debugger) and inspect `show`.
return show is null ? RedirectToAction("Index") : View(show);
}
[HttpGet]
public IActionResult Book(string id) =>
Show.Find(id) is { } show ? View(new BookingForm(show, new TicketOrder())) : NotFound();
[HttpPost, ValidateAntiForgeryToken]
public IActionResult Book(string id, [Bind(Prefix = "Order")] TicketOrder order)
{
if (Show.Find(id) is not { } show)
{
return NotFound();
}
if (!ModelState.IsValid)
{
return View(new BookingForm(show, order));
}
logger.LogInformation("{Name} booked {Quantity} seats for {Show}", order.Name, order.Quantity, show.Slug);
return View("Confirmation", new BookingConfirmation(show, order.Quantity));
}
}