using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Principal;
using LHDN.CRM.Models.ViewModels;

namespace LHDN.CRM.BC.Filters
{
    public class CustomPrincipal : WindowsPrincipal
    {
        public UserInfoViewModel User { get; protected set; }
        public CustomPrincipal(WindowsIdentity source, UserInfoViewModel baseUser) :
                            base(source)
        {
            User = baseUser;
        }

        public override bool IsInRole(string role)
        {
            return (base.IsInRole(role) ||
                    (
                        User != null &&
                        User.RolesObj != null &&
                        User.RolesObj.Count > 0 &&
                        User.RolesObj.Any(x => x.RoleCode.ToString() == role)
                    ));
        }
    }
}
