This repository has been archived on 2023-10-28. You can view files and clone it, but cannot push or open issues or pull requests.
pwt-0x01-ng/Areas/Customer/Controllers/CustomerOrdersController.cs
surtur 4b42658671
All checks were successful
continuous-integration/drone/push Build is passing
feat: add Customer area
* controller
* views
* SessionExtensions class
2021-02-10 12:01:59 +01:00

49 lines
1.1 KiB
C#

using pwt_0x01_ng.Models;
using pwt_0x01_ng.Models.ApplicationServices;
using pwt_0x01_ng.Models.Database;
using pwt_0x01_ng.Models.Identity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace pwt_0x01_ng.Areas.Customer.Controllers
{
[Area("Customer")]
[Authorize(Roles = nameof(Roles.Customer))]
public class CustomerOrdersController : Controller
{
ISecurityApplicationService isas;
DBContext ctx;
public CustomerOrdersController(ISecurityApplicationService isas, DBContext ctx)
{
this.isas = isas;
this.ctx = ctx;
}
public async Task<IActionResult> Index()
{
if (User.Identity.IsAuthenticated)
{
User currentUser = await isas.gimme_current_user(User);
if (currentUser != null)
{
IList<Order> userOrders = await this.ctx.Order
.Where(or => or.User_id == currentUser.Id)
.Include(o => o.usr)
.Include(o => o.OrderItems)
.ThenInclude(oi => oi.Product)
.ToListAsync();
return View(userOrders);
}
}
return NotFound();
}
}
}