Adding
This commit is contained in:
+118
@@ -0,0 +1,118 @@
|
||||
using System.Reflection;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
|
||||
public class Settings
|
||||
{
|
||||
public Dictionary<string, string> ActivityStateSet { get; set; }
|
||||
public Dictionary<string, string> ActivityTypeSet { get; set; }
|
||||
public List<Role> AppRoles { get; set; }
|
||||
public IReadOnlyCollection<ReportSettings> AuthorizedReports { get; set; }
|
||||
public List<BusinessLine> BusinessLines { get; set; }
|
||||
public Dictionary<string, string> DepartmentStateSet { get; set; }
|
||||
public Dictionary<string, string> OrganizationSet { get; set; }
|
||||
public List<PayoutProfile> PayoutProfiles { get; set; }
|
||||
public List<Permission> Permissions { get; set; }
|
||||
public List<ProductDetail> ProductDetails { get; }
|
||||
public Product[] ProductSet { get; set; }
|
||||
public List<Region> Regions { get; set; }
|
||||
public Dictionary<string, string> SystemTypeSet { get; set; }
|
||||
public Dictionary<string, string> UserTypeSet { get; set; }
|
||||
public IReadOnlyCollection<Department> Departments { get; set; }
|
||||
public IReadOnlyCollection<UserSummary> Employees { get; set; }
|
||||
|
||||
public DateTime NextBonusPeriod { get; set; }
|
||||
|
||||
public Settings()
|
||||
{
|
||||
ActivityStateSet = new Dictionary<string, string>();
|
||||
ActivityTypeSet = new Dictionary<string, string>();
|
||||
ProductSet = (Product[]) Enum.GetValues(typeof(Product));
|
||||
ProductDetails = ProductDetail.ProductDetails;
|
||||
SystemTypeSet = new Dictionary<string, string>();
|
||||
UserTypeSet = new Dictionary<string, string>();
|
||||
OrganizationSet = new Dictionary<string, string>();
|
||||
BusinessLines = new List<BusinessLine>();
|
||||
DepartmentStateSet = new Dictionary<string, string>();
|
||||
Permissions = new List<Permission>();
|
||||
Regions = Region.Regions;
|
||||
PayoutProfiles = PayoutProfile.ActivePayoutProfiles;
|
||||
|
||||
foreach (int key in Enum.GetValues(typeof(ActivityState)))
|
||||
{
|
||||
ActivityStateSet[key.ToString()] = Enum.GetName(typeof(ActivityState), key);
|
||||
}
|
||||
|
||||
foreach (int key in Enum.GetValues(typeof(ActivityType)))
|
||||
{
|
||||
ActivityTypeSet[key.ToString()] = Enum.GetName(typeof(ActivityType), key);
|
||||
}
|
||||
|
||||
foreach (int key in Enum.GetValues(typeof(SystemType)))
|
||||
{
|
||||
SystemTypeSet[key.ToString()] = Enum.GetName(typeof(SystemType), key);
|
||||
}
|
||||
|
||||
foreach (int key in Enum.GetValues(typeof(UserType)))
|
||||
{
|
||||
UserTypeSet[key.ToString()] = Enum.GetName(typeof(UserType), key);
|
||||
}
|
||||
|
||||
foreach (int key in Enum.GetValues(typeof(DepartmentState)))
|
||||
{
|
||||
DepartmentStateSet[key.ToString()] = Enum.GetName(typeof(DepartmentState), key);
|
||||
}
|
||||
|
||||
foreach (var field in typeof(Organization).GetFields(BindingFlags.Static | BindingFlags.Public))
|
||||
{
|
||||
if (field.FieldType != typeof(Organization))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var org = field.GetValue(field.Name) as Organization;
|
||||
if (org == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
OrganizationSet[org.OrgCode] = org.Name;
|
||||
}
|
||||
|
||||
foreach (var field in typeof(BusinessLine).GetFields(BindingFlags.Static | BindingFlags.Public))
|
||||
{
|
||||
if (field.FieldType != typeof(BusinessLine))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var bl = field.GetValue(field.Name) as BusinessLine;
|
||||
if (bl != null)
|
||||
{
|
||||
BusinessLines.Add(bl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AppRoles = Role.GetRolesList();
|
||||
|
||||
Permissions = EnumInstances<Permission>();
|
||||
}
|
||||
|
||||
private List<T> EnumInstances<T>() where T : class
|
||||
{
|
||||
var foundInstances = new List<T>();
|
||||
|
||||
foreach (var field in typeof(T).GetFields(BindingFlags.Static | BindingFlags.Public))
|
||||
{
|
||||
if (field.FieldType != typeof(T))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (field.GetValue(field.Name) is T instance)
|
||||
{
|
||||
foundInstances.Add(instance);
|
||||
}
|
||||
}
|
||||
return foundInstances;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user