-
-
Save dcomartin/630a07fd8457237c6ae66441b2bd8200 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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