Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created November 24, 2025 22:00
Show Gist options
  • Select an option

  • Save dcomartin/630a07fd8457237c6ae66441b2bd8200 to your computer and use it in GitHub Desktop.

Select an option

Save dcomartin/630a07fd8457237c6ae66441b2bd8200 to your computer and use it in GitHub Desktop.
[ApiExplorerSettings(IgnoreApi = true)]
[Authorize] // Controllers that mainly require Authorization still use Controller/View; other pages use Pages
[Route("[controller]/[action]")]
public class OrderController : Controller
{
private readonly IMediator _mediator;
public OrderController(IMediator mediator)
{
_mediator = mediator;
}
[HttpGet]
public async Task<IActionResult> MyOrders([FromServices] CatalogContext dbContext)
{
Guard.Against.Null(User.Identity?.Name, nameof(User.Identity.Name));
var orders = await dbContext.Orders
.Include(x => x.OrderItems)
.Where(x => x.BuyerId == User.Identity.Name)
.ToArrayAsync();
var viewModel = orders.Select(o => new OrderViewModel
{
OrderDate = o.OrderDate,
OrderNumber = o.Id,
ShippingAddress = o.ShipToAddress,
Total = o.Total()
});
return View(viewModel);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment