我有一个域模型,用于确定用户是否有任何访问权限。
在每个Web请求中从数据库加载此类。
只有当数据库将此数据加载到域对象中时,才会访问属性上用于确定访问限制逻辑的setter。
我应该关注这个领域模型中的逻辑是否无法实现?
public class AccessInfo
{
private const int DefaultTempSearchDailyLimit = 25;
public AccessInfo()
{
Subscriptions = new List<Subscription>();
OrganisationalUnit = new OrganisationalUnit();
}
public OrganisationalUnit OrganisationalUnit { get; set; }
private int limit;
public int Limit
{
get { return CalculateLimit(); }
set { limit = value; }
}
public int Remaining
{
get
{
var remaining = Limit - Downloads;
return remaining < 0 ? 0 : remaining;
}
}
public List<Subscription> Subscriptions { get; set; }
public int Downloads { get; set; }
public bool HasEnoughAccess(int numberOfAccessNeeded)
{
return Remaining >= numberOfAccessNeeded;
}
private int CalculateLimit()
{
int userLimit;
if (OrganisationalUnit.IsOuReedBranch)
{
userLimit = OrganisationalUnit.FlexCandidateLimit;
return userLimit;
}
switch (OrganisationalUnit.OuType)
{
case (int)Enums.OuType.RecruitmentAgency:
var cvSearchSub = Subscriptions.SingleOrDefault(s => s.FeatureId == (int) FeatureFact.CVAccess);
var tempSearchSub = Subscriptions.SingleOrDefault(s => s.FeatureId == (int) FeatureFact.TempSearch);
userLimit = cvSearchSub != null && tempSearchSub == null ? DefaultTempSearchDailyLimit : tempSearchSub != null ? tempSearchSub.Data : 0;
break;
default:
userLimit = OrganisationalUnit.FlexCandidateLimit;
break;
}
return userLimit;
}
}