Skip to content

Commit

Permalink
Section 11 - Role based order display
Browse files Browse the repository at this point in the history
  • Loading branch information
bhrugen committed Sep 26, 2021
1 parent 3b563ac commit fca7a30
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion BulkyBookWeb/Areas/Admin/Controllers/OrderController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using BulkyBook.DataAccess.Repository.IRepository;
using BulkyBook.Models;
using BulkyBook.Utility;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;

namespace BulkyBookWeb.Areas.Admin.Controllers
{
[Area("Admin")]
[Authorize]
public class OrderController : Controller
{
private readonly IUnitOfWork _unitOfWork;
Expand All @@ -26,8 +29,16 @@ public IActionResult Index()
public IActionResult GetAll(string status)
{
IEnumerable<OrderHeader> orderHeaders;
orderHeaders = _unitOfWork.OrderHeader.GetAll(includeProperties: "ApplicationUser");

if (User.IsInRole(SD.Role_Admin) || User.IsInRole(SD.Role_Employee)) {
orderHeaders = _unitOfWork.OrderHeader.GetAll(includeProperties: "ApplicationUser");
}
else
{
var claimsIdentity = (ClaimsIdentity)User.Identity;
var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
orderHeaders = _unitOfWork.OrderHeader.GetAll(u=>u.ApplicationUserId==claim.Value,includeProperties: "ApplicationUser");
}

switch (status)
{
Expand Down

0 comments on commit fca7a30

Please sign in to comment.