/// <summary> /// Constructor. /// </summary> protected UnitOfWorkBase(IUnitOfWorkDefaultOptions defaultOptions) { DefaultOptions = defaultOptions; Id = Guid.NewGuid().ToString("N"); _filters = defaultOptions.Filters.ToList(); HozaruSession = NullHozaruSession.Instance; }
/// <summary> /// Gets current Tenant's Id. /// Throws <see cref="HozaruException"/> if <see cref="IHozaruSession.TenantId"/> is null. /// </summary> /// <param name="session">Session object.</param> /// <returns>Current Tenant's Id.</returns> /// <exception cref="HozaruException"></exception> public static int GetTenantId(this IHozaruSession session) { if (!session.TenantId.HasValue) { throw new HozaruException("Session.TenantId is null! Possible problems: No user logged in or current logged in user in a host user (TenantId is always null for host users)."); } return(session.TenantId.Value); }
/// <summary> /// Gets current User's Id. /// Throws <see cref="HozaruException"/> if <see cref="IHozaruSession.UserId"/> is null. /// </summary> /// <param name="session">Session object.</param> /// <returns>Current User's Id.</returns> public static long GetUserId(this IHozaruSession session) { if (!session.UserId.HasValue) { throw new HozaruException("Session.UserId is null! Probably, user is not logged in."); } return(session.UserId.Value); }
/// <summary> /// Constructor. /// </summary> public PermissionManager( IIocManager iocManager, IAuthorizationConfiguration authorizationConfiguration, FeatureDependencyContext featureDependencyContext ) { _iocManager = iocManager; _authorizationConfiguration = authorizationConfiguration; _featureDependencyContext = featureDependencyContext; HozaruSession = NullHozaruSession.Instance; }
public static bool ShouldSaveAudit(MethodInfo methodInfo, IAuditingConfiguration configuration, IHozaruSession hozaruSession, bool defaultValue = false) { if (configuration == null || !configuration.IsEnabled) { return(false); } if (!configuration.IsEnabledForAnonymousUsers && (hozaruSession == null || !hozaruSession.UserId.HasValue)) { return(false); } if (methodInfo == null) { return(false); } if (!methodInfo.IsPublic) { return(false); } if (methodInfo.IsDefined(typeof(AuditedAttribute))) { return(true); } if (methodInfo.IsDefined(typeof(DisableAuditingAttribute))) { return(false); } var classType = methodInfo.DeclaringType; if (classType != null) { if (classType.IsDefined(typeof(AuditedAttribute))) { return(true); } if (classType.IsDefined(typeof(DisableAuditingAttribute))) { return(false); } if (configuration.Selectors.Any(selector => selector.Predicate(classType))) { return(true); } } return(defaultValue); }