Files
eShopOnWeb/src/Web/Controllers/OrderController.cs
Viswanatha Swamy 1598d0bbe1 Swamy/remove unused usings and reorganize usings (#489)
* Removed and Reordered the using statements

* Removed and Reordered the usings inside Web Project

* Removed and Reordered the usings inside PublicApi project

* Removed Unused usings and reorganized usings inside Infrastructure project
2020-12-03 08:05:28 -05:00

44 lines
1.2 KiB
C#

using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopWeb.Web.Features.MyOrders;
using Microsoft.eShopWeb.Web.Features.OrderDetails;
using System.Threading.Tasks;
namespace Microsoft.eShopWeb.Web.Controllers
{
[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()
{
var viewModel = await _mediator.Send(new GetMyOrders(User.Identity.Name));
return View(viewModel);
}
[HttpGet("{orderId}")]
public async Task<IActionResult> Detail(int orderId)
{
var viewModel = await _mediator.Send(new GetOrderDetails(User.Identity.Name, orderId));
if (viewModel == null)
{
return BadRequest("No such order found for this user.");
}
return View(viewModel);
}
}
}