Adding
This commit is contained in:
+760
@@ -0,0 +1,760 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
|
||||
public class ApplicationDbContext : DbContext, IApplicationDbContext
|
||||
{
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IDateTime _dateTime;
|
||||
|
||||
public ApplicationDbContext(
|
||||
DbContextOptions options,
|
||||
ICurrentUserService currentUserService,
|
||||
IDateTime dateTime
|
||||
) : base(options)
|
||||
{
|
||||
_currentUserService = currentUserService;
|
||||
_dateTime = dateTime;
|
||||
}
|
||||
|
||||
public DbSet<Goal> Goals { get; set; }
|
||||
public DbSet<GoalChange> GoalChanges { get; set; }
|
||||
public DbSet<Activity> Activities { get; set; }
|
||||
public DbSet<ActivityDetail> ActivityDetails { get; set; }
|
||||
public DbSet<ActivityStateChange> ActivityStateChanges { get; set; }
|
||||
public DbSet<ActivityDetailUpdate> ActivityDetailUpdates { get; set; }
|
||||
public DbSet<Department> Departments { get; set; }
|
||||
public DbSet<AppUser> AppUsers { get; set; }
|
||||
public DbSet<UserDepartment> DepartmentAssignments { get; set; }
|
||||
public DbSet<Commission> Commissions { get; set; }
|
||||
public DbSet<ProcessorHistoryRecord> ProcessorRunHistory { get; set; }
|
||||
public DbSet<UserPermission> UserPermissions { get; set; }
|
||||
public DbSet<PayoutLineItem> PayoutLineItems { get; set; }
|
||||
public DbSet<UserAssignment> UserAssignments { get; set; }
|
||||
public DbSet<RoleMapping> RoleMappings { get; set; }
|
||||
public DbSet<ActivityTransferAction> ActivityTransferActions { get; set; }
|
||||
public DbSet<DeadActivity> DeadActivities { get; set; }
|
||||
public DbSet<DepartmentLineItem> DepartmentLineItems { get; set; }
|
||||
public DbSet<UserDepartmentHistory> UserDepartmentHistories { get; set; }
|
||||
public DbSet<UserPermissionHistory> UserPermissionHistories { get; set; }
|
||||
|
||||
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
var currentUser = _currentUserService.GetCurrentUser();
|
||||
var currentAppUser = ChangeTracker.Context.Set<AppUser>().FirstOrDefault(x => x.AdEmail == currentUser.Email);
|
||||
var currentUserGuid = currentAppUser?.Id ?? Guid.Empty;
|
||||
|
||||
foreach (var entry in ChangeTracker.Entries<AuditCreate>())
|
||||
{
|
||||
if (entry.State == EntityState.Added)
|
||||
{
|
||||
entry.Entity.CreatedByType = currentUser.UserType();
|
||||
entry.Entity.CreatedBy = currentUser.UserName();
|
||||
entry.Entity.CreatedByAppUserId = currentUserGuid;
|
||||
entry.Entity.Created = _dateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var entry in ChangeTracker.Entries<Auditable>())
|
||||
{
|
||||
if (entry.State == EntityState.Modified || entry.State == EntityState.Added)
|
||||
{
|
||||
entry.Entity.LastUpdatedByType = currentUser.UserType();
|
||||
entry.Entity.LastUpdatedBy = currentUser.UserName();
|
||||
entry.Entity.LastUpdatedByAppUserId = currentUserGuid;
|
||||
entry.Entity.LastUpdated = _dateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
return base.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.Entity<ActivityPayoutLineItem>()
|
||||
.ToTable("ActivityPayouts")
|
||||
.HasKey(apli => new { apli.ActivityId, apli.PayoutLineItemId });
|
||||
|
||||
builder.Entity<ActivityPayoutLineItem>()
|
||||
.HasOne(bg => bg.Activity)
|
||||
.WithMany(b => b.ActivityPayouts)
|
||||
.HasForeignKey(bg => bg.ActivityId);
|
||||
|
||||
builder.Entity<ActivityPayoutLineItem>()
|
||||
.HasOne(bg => bg.PayoutLineItem)
|
||||
.WithMany(g => g.ActivityPayouts)
|
||||
.HasForeignKey(bg => bg.PayoutLineItemId);
|
||||
|
||||
builder.Entity<Activity>().ToTable("Activity");
|
||||
builder.Entity<Activity>().HasKey(p => p.Id);
|
||||
builder.Entity<Activity>()
|
||||
.Property(e => e.Product)
|
||||
.IsRequired()
|
||||
.HasConversion(x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, Product.Unknown));
|
||||
builder.Entity<Activity>()
|
||||
.Property(e => e.Type)
|
||||
.IsRequired()
|
||||
.HasConversion(x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, ActivityType.Unknown));
|
||||
builder.Entity<Activity>()
|
||||
.Property(e => e.SourceSystem)
|
||||
.IsRequired()
|
||||
.HasConversion(x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, SystemType.Unknown));
|
||||
builder.Entity<Activity>().Property(e => e.SourceId).IsRequired();
|
||||
builder.Entity<Activity>().Property(e => e.SourceCreated).IsRequired();
|
||||
builder.Entity<Activity>()
|
||||
.HasOne(e => e.Detail)
|
||||
.WithOne(b => b.Activity)
|
||||
.HasForeignKey<ActivityDetail>(b => b.ActivityRef)
|
||||
.IsRequired();
|
||||
builder.Entity<Activity>()
|
||||
.HasMany(e => e.MetaData)
|
||||
.WithOne(b => b.Activity)
|
||||
.HasForeignKey(b => b.ActivityRef);
|
||||
builder.Entity<Activity>().Property(e => e.DepartmentId).IsRequired();
|
||||
builder.Entity<Activity>().Property(e => e.EmployeeId).IsRequired();
|
||||
builder.Entity<Activity>().Property(e => e.EmployeeEmail);
|
||||
builder.Entity<Activity>().Property(e => e.MatchingActivityId).HasDefaultValue(0);
|
||||
builder.Entity<Activity>().Property(e => e.MatchingDpAccessoryActivityId).HasDefaultValue(0);
|
||||
builder.Entity<Activity>().Property(e => e.MatchingGapInsuranceActivityId).HasDefaultValue(0);
|
||||
builder.Entity<Activity>().Property(e => e.Accepted).IsRequired();
|
||||
builder.Entity<Activity>()
|
||||
.Property(e => e.State)
|
||||
.IsRequired()
|
||||
.HasConversion(x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, ActivityState.Unknown));
|
||||
builder.Entity<Activity>().HasIndex(e => e.Accepted);
|
||||
builder.Entity<Activity>().HasIndex(e => new { e.Accepted, e.Id });
|
||||
|
||||
builder.Entity<ActivityDetail>().ToTable("ActivityDetail");
|
||||
builder.Entity<ActivityDetail>().HasKey(p => p.Id);
|
||||
builder.Entity<ActivityDetail>().HasIndex(p => new { p.ActivityRef, p.Id });
|
||||
builder.Entity<ActivityDetail>().Property(p => p.SubAccountNumber).HasDefaultValue("");
|
||||
|
||||
builder.Entity<ActivityMetaData>().ToTable("ActivityMetaData");
|
||||
builder.Entity<ActivityMetaData>().HasKey(p => p.Id);
|
||||
builder.Entity<ActivityMetaData>().Property(p => p.MetaData);
|
||||
builder.Entity<ActivityMetaData>()
|
||||
.Property(p => p.MetaDataType)
|
||||
.IsRequired()
|
||||
.HasConversion(x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, MetaDataType.Unknown));
|
||||
builder.Entity<ActivityMetaData>().HasIndex(p => new { p.ActivityRef, p.Id });
|
||||
|
||||
builder.Entity<Goal>().ToTable("Goals");
|
||||
builder.Entity<Goal>().HasKey(p => p.Id);
|
||||
builder.Entity<Goal>()
|
||||
.Property(e => e.Product)
|
||||
.IsRequired()
|
||||
.HasConversion(x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, Product.Unknown));
|
||||
builder.Entity<Goal>().Property(e => e.StartDate).IsRequired();
|
||||
builder.Entity<Goal>().Property(e => e.EndDate).IsRequired();
|
||||
builder.Entity<Goal>().Property(e => e.EmployeeId);
|
||||
builder.Entity<Goal>().Property(e => e.DepartmentId);
|
||||
builder.Entity<Goal>().Property(e => e.Value).IsRequired();
|
||||
builder.Entity<Goal>().HasIndex(e => new { e.DepartmentId, e.StartDate, e.EndDate });
|
||||
builder.Entity<Goal>().HasIndex(e => new { e.DepartmentId, e.StartDate, e.EndDate, e.Id });
|
||||
|
||||
builder.Entity<GoalChange>().ToTable("GoalChanges");
|
||||
builder.Entity<GoalChange>().HasKey(p => p.Id);
|
||||
builder.Entity<GoalChange>()
|
||||
.Property(e => e.Product)
|
||||
.IsRequired()
|
||||
.HasConversion(x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, Product.Unknown));
|
||||
builder.Entity<GoalChange>().Property(e => e.StartDate).IsRequired();
|
||||
builder.Entity<GoalChange>().Property(e => e.EndDate).IsRequired();
|
||||
builder.Entity<GoalChange>().Property(e => e.Value).IsRequired();
|
||||
|
||||
builder.Entity<Department>().ToTable("Departments");
|
||||
builder.Entity<Department>().HasKey(p => p.Id);
|
||||
builder.Entity<Department>().HasIndex(e => e.DepartmentName).IsUnique();
|
||||
builder.Entity<Department>().Property(e => e.BusinessLineCode).IsRequired();
|
||||
builder.Entity<Department>().Property(e => e.RegionCode);
|
||||
builder.Entity<Department>().Property(e => e.DayforceDepartmentName).IsRequired();
|
||||
builder.Entity<Department>().Property(e => e.DayForceGlCode).IsRequired();
|
||||
builder.Entity<Department>().Property(e => e.DnaOrgNbr).IsRequired();
|
||||
builder.Entity<Department>()
|
||||
.Property(e => e.State)
|
||||
.IsRequired()
|
||||
.HasConversion(x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, DepartmentState.Unknown));
|
||||
|
||||
builder.Entity<AppUser>().ToTable("AppUser");
|
||||
builder.Entity<AppUser>().HasKey(e => e.Id);
|
||||
builder.Entity<AppUser>().Property(e => e.HomeDepartment).IsRequired();
|
||||
builder.Entity<AppUser>().Property(e => e.FullName).IsRequired();
|
||||
builder.Entity<AppUser>().Property(e => e.ManagerKey);
|
||||
builder.Entity<AppUser>().Property(e => e.Terminated);
|
||||
builder.Entity<AppUser>()
|
||||
.Property(e => e.Role)
|
||||
.HasConversion(
|
||||
x => x.Name,
|
||||
x => Role.DetermineRoleOrDefault(x)
|
||||
)
|
||||
.IsRequired();
|
||||
builder.Entity<AppUser>().Property(e => e.BaseRole).IsRequired();
|
||||
builder.Entity<AppUser>().HasMany(e => e.AdditionalPermissions).WithOne(e => e.AppUser);
|
||||
|
||||
builder.Entity<UserPermission>().ToTable("UserPermissions");
|
||||
builder.Entity<UserPermission>().HasKey(e => e.Id);
|
||||
builder.Entity<UserPermission>()
|
||||
.HasOne(e => e.AppUser)
|
||||
.WithMany(e => e.AdditionalPermissions)
|
||||
.IsRequired();
|
||||
builder.Entity<UserPermission>()
|
||||
.Property(e => e.Permission)
|
||||
.IsRequired()
|
||||
.HasConversion(
|
||||
x => x.Code,
|
||||
x => Permission.GetAllPermissions(false).FirstOrDefault(perm => perm.Code.Equals(x)) ?? Permission.Unknown);
|
||||
|
||||
builder.Entity<UserDepartment>().ToTable("DeptAssignments");
|
||||
builder.Entity<UserDepartment>().HasKey(p => p.Id);
|
||||
builder.Entity<UserDepartment>().Property(e => e.StartDate).IsRequired();
|
||||
builder.Entity<UserDepartment>().Property(e => e.EndDate);
|
||||
builder.Entity<UserDepartment>().Property(e => e.Note);
|
||||
builder.Entity<UserDepartment>().Property(e => e.SlidingPayout).HasColumnType("DECIMAL(5,2)").IsRequired().HasDefaultValue(0);
|
||||
builder.Entity<UserDepartment>().Property(e => e.IsHome).IsRequired();
|
||||
builder.Entity<UserDepartment>()
|
||||
.HasOne(p => p.Employee)
|
||||
.WithMany(b => b.Departments)
|
||||
.IsRequired();
|
||||
builder.Entity<UserDepartment>()
|
||||
.HasOne(p => p.Department)
|
||||
.WithMany(b => b.Assignments)
|
||||
.IsRequired();
|
||||
builder.Entity<UserDepartment>()
|
||||
.Property(e => e.Role)
|
||||
.HasConversion(
|
||||
x => x.Name,
|
||||
x => Role.DetermineRoleOrDefault(x)
|
||||
)
|
||||
.IsRequired();
|
||||
|
||||
builder.Entity<ActivityStateChange>().ToTable("ActivityStateChanges");
|
||||
builder.Entity<ActivityStateChange>().HasKey(p => p.Id);
|
||||
builder.Entity<ActivityStateChange>()
|
||||
.HasOne<Activity>()
|
||||
.WithMany()
|
||||
.HasForeignKey(p => p.ActivityId)
|
||||
.IsRequired();
|
||||
builder.Entity<ActivityStateChange>()
|
||||
.Property(e => e.State)
|
||||
.IsRequired()
|
||||
.HasConversion(
|
||||
x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, ActivityState.Unknown))
|
||||
.IsRequired();
|
||||
builder.Entity<ActivityStateChange>().Property(e => e.AcceptedDate);
|
||||
builder.Entity<ActivityStateChange>().Property(e => e.Note);
|
||||
|
||||
builder.Entity<ActivityDetailUpdate>().ToTable("ActivityDetailUpdates");
|
||||
builder.Entity<ActivityDetailUpdate>().HasKey(p => p.Id);
|
||||
builder.Entity<ActivityDetailUpdate>().HasOne<ActivityDetail>().WithMany().HasForeignKey(p => p.ActivityDetailId).IsRequired();
|
||||
builder.Entity<ActivityDetailUpdate>().Property(e => e.Note);
|
||||
|
||||
builder.Entity<Commission>().ToTable("Commissions");
|
||||
builder.Entity<Commission>().HasKey(p => p.Id);
|
||||
builder.Entity<Commission>()
|
||||
.Property(p => p.Product)
|
||||
.IsRequired()
|
||||
.HasConversion(
|
||||
x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, Product.Unknown)
|
||||
)
|
||||
.IsRequired();
|
||||
builder.Entity<Commission>().Property(p => p.RatePerProduct).IsRequired();
|
||||
builder.Entity<Commission>()
|
||||
.Property(p => p.Role)
|
||||
.IsRequired()
|
||||
.HasConversion(
|
||||
x => x.Name,
|
||||
x => Role.DetermineRoleOrDefault(x)
|
||||
)
|
||||
.IsRequired();
|
||||
builder.Entity<Commission>().HasIndex(p => p.Role);
|
||||
|
||||
builder.Entity<ProcessorHistoryRecord>().ToTable("ProcessorRunHistory");
|
||||
builder.Entity<ProcessorHistoryRecord>().HasKey(p => p.Process);
|
||||
builder.Entity<ProcessorHistoryRecord>()
|
||||
.Property(e => e.Process)
|
||||
.HasConversion(
|
||||
x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, Process.Unknown))
|
||||
.IsRequired();
|
||||
builder.Entity<ProcessorHistoryRecord>().Property(e => e.LastSuccessfulRunTime);
|
||||
builder.Entity<ProcessorHistoryRecord>().Property(e => e.LastProcessedRecordId);
|
||||
builder.Entity<ProcessorHistoryRecord>().Property(e => e.LastProcessedRecordTimestamp);
|
||||
|
||||
builder.Entity<PayoutLineItem>().ToTable("PayoutLineItems");
|
||||
builder.Entity<PayoutLineItem>().HasKey(p => p.Id);
|
||||
builder.Entity<PayoutLineItem>()
|
||||
.Property(p => p.Product)
|
||||
.IsRequired()
|
||||
.HasConversion(
|
||||
x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, Product.Unknown));
|
||||
builder.Entity<PayoutLineItem>()
|
||||
.Property(p => p.Role)
|
||||
.IsRequired()
|
||||
.HasConversion(
|
||||
x => x.Name,
|
||||
x => Role.DetermineRoleOrDefault(x)
|
||||
);
|
||||
builder.Entity<PayoutLineItem>().Property(p => p.EmployeeId).IsRequired();
|
||||
builder.Entity<PayoutLineItem>().Property(p => p.DepartmentId).IsRequired();
|
||||
builder.Entity<PayoutLineItem>().Property(p => p.ActivityPeriod).IsRequired();
|
||||
builder.Entity<PayoutLineItem>().Property(p => p.ActivityTotal).HasColumnType("DECIMAL(12,2)").IsRequired();
|
||||
builder.Entity<PayoutLineItem>().Property(p => p.PayoutTotal).HasColumnType("DECIMAL(12,2)").IsRequired();
|
||||
builder.Entity<PayoutLineItem>().Property(p => p.SlidingPayout).HasColumnType("DECIMAL(5,2)").IsRequired();
|
||||
|
||||
builder.Entity<UserAssignment>().ToTable("UserAssignments").HasKey(p => p.Id);
|
||||
builder.Entity<UserAssignment>()
|
||||
.Property(p => p.Type)
|
||||
.IsRequired()
|
||||
.HasConversion(
|
||||
x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, AssignmentType.Unknown));
|
||||
builder.Entity<UserAssignment>().Property(p => p.Key).IsRequired();
|
||||
builder.Entity<UserAssignment>().HasOne(p => p.AppUser).WithMany(p => p.Assignments).IsRequired();
|
||||
|
||||
builder.Entity<ActivityTransferAction>().ToTable("ActivityTransferActions").HasKey(p => p.Id);
|
||||
builder.Entity<ActivityTransferAction>()
|
||||
.Property(p => p.ActivityStateBeforeTransfer)
|
||||
.IsRequired()
|
||||
.HasConversion(
|
||||
x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, ActivityState.Unknown)
|
||||
);
|
||||
builder.Entity<ActivityTransferAction>().Property(p => p.RequestedActivityId).IsRequired();
|
||||
builder.Entity<ActivityTransferAction>()
|
||||
.Property(p => p.State)
|
||||
.IsRequired()
|
||||
.HasConversion(
|
||||
x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, ActivityTransferState.Unknown)
|
||||
);
|
||||
builder.Entity<ActivityTransferAction>().Property(p => p.NewActivityId);
|
||||
builder.Entity<ActivityTransferAction>().Property(p => p.NewActivityDepartmentId).IsRequired();
|
||||
builder.Entity<ActivityTransferAction>().Property(p => p.NewActivityEmployeeId).IsRequired();
|
||||
builder.Entity<ActivityTransferAction>().Property(p => p.RequestedDepartmentApproved);
|
||||
builder.Entity<ActivityTransferAction>().Property(p => p.RequestedDepartmentApprover);
|
||||
builder.Entity<ActivityTransferAction>().Property(p => p.NewDepartmentApproved);
|
||||
builder.Entity<ActivityTransferAction>().Property(p => p.NewDepartmentApprover);
|
||||
|
||||
builder.Entity<DeadActivity>().ToTable("DeadActivity");
|
||||
builder.Entity<DeadActivity>().HasKey(p => p.Id);
|
||||
builder.Entity<DeadActivity>()
|
||||
.Property(e => e.Product)
|
||||
.HasConversion(x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, Product.Unknown));
|
||||
builder.Entity<DeadActivity>()
|
||||
.Property(e => e.Reason)
|
||||
.HasConversion(x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, DeadActivityReason.Unknown))
|
||||
.IsRequired();
|
||||
builder.Entity<DeadActivity>().Property(e => e.ReasonNote);
|
||||
builder.Entity<DeadActivity>()
|
||||
.Property(e => e.Type)
|
||||
.HasConversion(x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, ActivityType.Unknown));
|
||||
builder.Entity<DeadActivity>()
|
||||
.Property(e => e.SourceSystem)
|
||||
.HasConversion(x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, SystemType.Unknown));
|
||||
builder.Entity<DeadActivity>().Property(e => e.SourceId);
|
||||
builder.Entity<DeadActivity>().Property(e => e.SourceCreated);
|
||||
builder.Entity<DeadActivity>()
|
||||
.HasOne(e => e.DeadDetail)
|
||||
.WithOne(b => b.DeadActivity)
|
||||
.HasForeignKey<DeadActivityDetail>(b => b.DeadActivityRef);
|
||||
builder.Entity<DeadActivity>().Property(e => e.DepartmentId);
|
||||
builder.Entity<DeadActivity>().Property(e => e.EmployeeId);
|
||||
builder.Entity<DeadActivity>().Property(e => e.EmployeeEmail);
|
||||
builder.Entity<DeadActivity>().Property(e => e.Accepted);
|
||||
builder.Entity<DeadActivity>()
|
||||
.Property(e => e.State)
|
||||
.HasConversion(x => x.ToString(),
|
||||
x => ConvertEnumOrDefault(x, ActivityState.Unknown));
|
||||
|
||||
builder.Entity<DeadActivityDetail>().ToTable("DeadActivityDetail");
|
||||
builder.Entity<DeadActivityDetail>().HasKey(p => p.Id);
|
||||
|
||||
builder.Entity<DepartmentLineItem>().ToTable("DepartmentLineItems");
|
||||
builder.Entity<DepartmentLineItem>().HasKey(p => p.Id);
|
||||
builder.Entity<DepartmentLineItem>().Property(p => p.PayoutTotal).HasColumnType("DECIMAL(12,2)").IsRequired();
|
||||
builder.Entity<DepartmentLineItem>().Property(p => p.PayoutPercentage).HasColumnType("DECIMAL(5,2)").IsRequired();
|
||||
|
||||
builder.Entity<UserDepartmentHistory>().ToTable("UserDepartmentHistory");
|
||||
builder.Entity<UserDepartmentHistory>().HasKey(p => p.Id);
|
||||
|
||||
builder.Entity<UserPermissionHistory>().ToTable("UserPermissionHistory");
|
||||
builder.Entity<UserPermissionHistory>().HasKey(p => p.Id);
|
||||
|
||||
builder.Entity<RoleMapping>().ToTable("RoleMappings");
|
||||
builder.Entity<RoleMapping>().HasKey(r => r.Id);
|
||||
builder.Entity<RoleMapping>().Property(r => r.Id);
|
||||
builder.Entity<RoleMapping>()
|
||||
.Property(r => r.ApplicationRole)
|
||||
.HasConversion(
|
||||
x => x.Name,
|
||||
x => Role.DetermineRoleOrDefault(x)
|
||||
)
|
||||
.IsRequired();
|
||||
builder.Entity<RoleMapping>().Property(r => r.BusinessRole);
|
||||
}
|
||||
|
||||
private static T ConvertEnumOrDefault<T>(string value, T defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (T)Enum.Parse(typeof(T), value);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SeedRoleMappingData()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (RoleMappings.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RoleMappings.AddRange(new List<RoleMapping>
|
||||
{
|
||||
new() { ApplicationRole = Role.Teller, BusinessRole = "ACH REPRESENTATIVE" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "ACH SUPERVISOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "ADMIN ASSISTANT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "ADMIN ASST BUS LEND" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "APPLICATION SUP SPEC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "APPLICATIONS SUPPORT MANAGER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "ASSOCIATE COUNSEL - COMPLIANCE" },
|
||||
new() { ApplicationRole = Role.ABM, BusinessRole = "ASST BRANCH MANAGER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "ASST MGR IND LENDING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "AVP / MANAGER, CARD OPERATIONS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "AVP LOAN SERVICING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "AVP FACILITIES & PURCHASING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "AVP, BUSINESS LENDING OPERATIONS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "AVP, CARD PRODUCT MGMT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "AVP, COLLECTIONS" },
|
||||
new() { ApplicationRole = Role.Manager, BusinessRole = "AVP, DIGITAL & ONLINE SERVICING" },
|
||||
new() { ApplicationRole = Role.Manager, BusinessRole = "AVP, MEMBER SERVICE" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "AVP/ACCOUNTING" },
|
||||
new() { ApplicationRole = Role.BM, BusinessRole = "AVP/BRANCH MANAGER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "AVP/BUSINESS LENDING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "AVP/FACILITIES" },
|
||||
new() { ApplicationRole = Role.Manager, BusinessRole = "AVP/MANAGER OPS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "AVP/MANAGER, CARD OPERATIONS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "AVP/MARKETING" },
|
||||
new() { ApplicationRole = Role.Manager, BusinessRole = "AVP/MGR CONS LEN MSC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "AVP/MTG OPERATIONS" },
|
||||
new() { ApplicationRole = Role.Manager, BusinessRole = "AVP/MTG SALES" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "BENEFITS ANALYST" },
|
||||
new() { ApplicationRole = Role.BM, BusinessRole = "BRANCH MANAGER" },
|
||||
new() { ApplicationRole = Role.BM, BusinessRole = "BRANCH MANAGER - CORE PROJECT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "BRANCH ONBOARDING COORDINATOR" },
|
||||
new() { ApplicationRole = Role.BOM, BusinessRole = "BRANCH OP MANAGER" },
|
||||
new() { ApplicationRole = Role.BusinessLineManager, BusinessRole = "BRANCH SUPPORT SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "BSA ASSOCIATE" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "BSA LEAD" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "BSA MANAGER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "BUS CREDIT ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "BUS LN DOC & CLOSING SPEC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "BUS LN SERVICING SPEC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "BUSINESS ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "BUSINESS INTELLIGENCE ENGINEER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CARD PROJECT ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CASH MANAGEMENT SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CFO" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CHIEF INFORMATION & RISK OFFICER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CHIEF PEOPLE OFFICER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CIO" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CL PROC MANAGER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CL PROC SUPERVISOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CLERK" },
|
||||
new() { ApplicationRole = Role.LIC, BusinessRole = "CLIENT SRVC ASST-LIC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CLO" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CLV SUPERVISOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COLL SPEC-BANKRUPTCY" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COLL SPEC-CRED BUREA" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COLL SPEC-FRAUD" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COLL SPEC-LOSS MIT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COLL SPEC-PROBATE" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COLL SPEC-RECOVERY" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COLL SPEC-REO FORE" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COLL SPEC-REPOS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COLL SPEC-SKIP TRACE" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COLLECT BUS ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COLLECTION CLERK" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COLLECTIONS MANAGEMENT SYSTEM ADMINISTRATOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COLLECTOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COMMS SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COMPENSATION MANAGER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COMPLIANCE ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COMPLIANCE MANAGER - FAIR LENDING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COMPLIANCE MGR-ADVISORY" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COMPLIANCE OFFICER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COMPLIANCE SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "COMPLIANCE TRAINER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CONS LN PROC AUD CLE" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CONS LN PROCESSOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CONS LN COORDINATOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CONS LN VAULT CLERK" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CREDIT CARD MEMBER SERVICE REP" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CREDIT OPERATIONS COORDINATOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "CXO" },
|
||||
new() { ApplicationRole = Role.Developer, BusinessRole = "DATA ARCHITECT" },
|
||||
new() { ApplicationRole = Role.Developer, BusinessRole = "DATA ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "DEALER RELATION MGR" },
|
||||
new() { ApplicationRole = Role.Developer, BusinessRole = "DEV OPS ENGINEER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "DESKTOP & FIELD SUPPORT SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "DIGITAL PROGRAM MANAGER" },
|
||||
new() { ApplicationRole = Role.MSR, BusinessRole = "DIGITAL REPRESENTATIVE" },
|
||||
new() { ApplicationRole = Role.MSR, BusinessRole = "DIGITAL REPRESENTATIVE (BILINGUAL)" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "DIR FIN PLAN & ANALY" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "DIR MGMNT REPORTING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "DIR SECURITY/FRAUD" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "DIRECTOR COMMUNITY RELATIONS & EVENTS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "DIRECTOR INV & TREAS" },
|
||||
new() { ApplicationRole = Role.Manager, BusinessRole = "DIRECTOR MEMBER RELATIONSHIPS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "ENHANCED DUE DILIGEN" },
|
||||
new() { ApplicationRole = Role.Developer, BusinessRole = "ENTERPRISE ARCHITECT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "ENTERPRISE RISK MGMT ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "ENTERPRISE RISK MGR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "EVP" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "EXECUTIVE ASSISTANT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "FACILITIES CLERK" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "FACILITIES SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "FINANCIAL ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "FINANCIAL OPERATIONS ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "FRAUD PREV ASSOCIATE - DEBIT CARDS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "FRAUD PREVENTION SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "GRAPHIC DESIGNER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "HR ADVISOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "HR BUSINESS PARTNER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "HR CONSULTANT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "HR COORDINATOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "IND LN/LS CLERK" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "IND LN/LS OFFICER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "IND LN/LS OFFICER N TRNG" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "IND LN/LS OFFICER PM" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "IND LN/LS PROC SUPV" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "IND LN/LS OFFICER N PM" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "IND LOAN PROC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "IND LOAN UNDERWRITER PM" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "INF SECURITY ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "INF SECURITY OFFICER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "INFRAST & OPER MGR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "INFRASTRUCTURE SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "INFRASTRUCTURE SUPPORT SPECIALIST - SHAREPOINT & O365" },
|
||||
new() { ApplicationRole = Role.Mortgage, BusinessRole = "INTERNET MLO" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "INTERNAL COMM & ENGMNT SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "INV/SECURITY" },
|
||||
new() { ApplicationRole = Role.OpsHelpDesk, BusinessRole = "IRA ADMINISTRATOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "IT DELIVERY MANAGER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "IT HELPDESK OPS SUP" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "IT HELPDESK/OPS I" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "IT HELPDESK/OPS II" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "ITEM PROCESSING CLK" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "LEAD COLLECT CLERK" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "LEAD IT DESK FIELD" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "LEAD PROCESS CLERK" },
|
||||
new() { ApplicationRole = Role.Teller, BusinessRole = "LEAD TELLER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "LEGAL ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MAIL PROCESSING CLERK" },
|
||||
new() { ApplicationRole = Role.ManagementTrainee, BusinessRole = "MANAGEMENT TRAINEE" },
|
||||
new() { ApplicationRole = Role.Manager, BusinessRole = "MANAGER MSC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MANAGER, HUMAN RESOURCES" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MANAGER, INTERNAL AUDIT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MANAGER MTG SERVICING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MANAGER, TALENT ACQUISITION" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MARKETING ASSISTANT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MARKETING COORDINATOR, CONTENT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MARKETING COORDINATOR, CREATIVE" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MARKETING TRAFFIC & PROD MGR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MEMBER EXPERIENCE ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MEMBER EXP ANALYST" },
|
||||
new() { ApplicationRole = Role.MSCTeamLead, BusinessRole = "MEMBER SERVICE ONBOARDING COORDINATOR" },
|
||||
new() { ApplicationRole = Role.MSR, BusinessRole = "MEMBER SERVICE REP" },
|
||||
new() { ApplicationRole = Role.MSR, BusinessRole = "MEMBER SERVICE REP (BILINGUAL)" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MGR BUS LEND CR OPS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MGR CONSUMER LOAN UNDERWRITING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MGR INDIRECT LOAN UNDERWRITING" },
|
||||
new() { ApplicationRole = Role.Manager, BusinessRole = "MGR MEMBER SVS CTR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MORTGAGE CLOSING SUPERVISOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MORTGAGE DISCLOSURE DESK REPRESENTATIVE" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MORTGAGE QUALITY ASSURANCE SPECIALST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MRKTNG BUS ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MTG CLOSING CLERK" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MTG CLOSING COORDTR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MTG LN SERV SUPV" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MTG LN SV SPECIALIST" },
|
||||
new() { ApplicationRole = Role.Mortgage, BusinessRole = "MTG LOAN ORIGINATOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MTG LOAN PROCESSOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MTG LOAN UNDERWRITER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MTG PROCESSING CLERK" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MTG PROCESSING SUP" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MTG SERVICING REP" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "MTG UNDERWRITING SUP" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "NET SUPP SPECIALIST" },
|
||||
new() { ApplicationRole = Role.MSR, BusinessRole = "ONLINE EXPERIENCE SPECIALIST" },
|
||||
new() { ApplicationRole = Role.MSR, BusinessRole = "ONLINE EXPERIENCE SPECIALIST (BILINGUAL)" },
|
||||
new() { ApplicationRole = Role.OpsHelpDesk, BusinessRole = "OP HELP DESK REP" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "OPERATIONS MANAGER" },
|
||||
new() { ApplicationRole = Role.Admin, BusinessRole = "OPERATIONS QUALITY CONTROL ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "OPERATIONS SUPP MGR" },
|
||||
new() { ApplicationRole = Role.OpsHelpDesk, BusinessRole = "OPERATIONS SUPP SPEC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "ORG CHANGE/DEV LD" },
|
||||
new() { ApplicationRole = Role.MSR, BusinessRole = "OUTBOUND MEMBER RELATION SPCL" },
|
||||
new() { ApplicationRole = Role.MSR, BusinessRole = "OUTBOUND MEMBER RELATION SPCL (BILINGUAL)" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "PAYROLL & HRIS ADMINISTRATOR" },
|
||||
new() { ApplicationRole = Role.PFO, BusinessRole = "PERS FIN OFFICER" },
|
||||
new() { ApplicationRole = Role.PFO, BusinessRole = "PERS FIN OFFICER - MSC" },
|
||||
new() { ApplicationRole = Role.PFO, BusinessRole = "PERS FIN OFFICER - MSC (BILINGUAL)" },
|
||||
new() { ApplicationRole = Role.PFO, BusinessRole = "PFO IN TRAINING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "PHYSICAL SECURITY MANAGER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "PORT MGR BUS LENDING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "PRESIDENT/CEO" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "PROCESS ENGINEER MANAGER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "PRODUCT MANAGER, DIGITAL BANKING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "PRODUCT MANAGER, RETAIL DEPOSITS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "PROJECT MANAGER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "PURCH SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "PURCHASING ASSISTANT" },
|
||||
new() { ApplicationRole = Role.MSCTeamLead, BusinessRole = "QUALITY ASSUR SPCLST" },
|
||||
new() { ApplicationRole = Role.MSCTeamLead, BusinessRole = "QUALITY ASSURANCE SPECIALIST - MSC" },
|
||||
new() { ApplicationRole = Role.Developer, BusinessRole = "QUALITY ASSURANCE ANALYST" },
|
||||
new() { ApplicationRole = Role.Teller, BusinessRole = "RECEPTIONIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "RECRUITER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SECURITY SERVICES" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SOC MEDIA SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SOFT ENG/DATA" },
|
||||
new() { ApplicationRole = Role.Developer, BusinessRole = "SOFTWARE ENG" },
|
||||
new() { ApplicationRole = Role.Developer, BusinessRole = "SOFTWARE ENGINEERING MANAGER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR ADMIN ASSISTANT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR BSA ASSOC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR BUS CRED ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR. BUSINESS ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR BUS LN DOC & CLOSING SPEC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR COMPENSATION ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR COMPLIANCE ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR CONS LN PROCESSOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR CONS LN UNDERWRITER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR DATABASE ADMINISTRATOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR ENHANCED DUE DILIGENCE ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR FIN ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR IND LN PROC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR IND LN/LS OFFICER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR IND LN/LS OFFICER PM" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR IND LOAN UNDERWRITER PM" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR IND LOAN UNDERWRITER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR INFRAS SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR INTERNAL AUDITOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR INV/SECURITY" },
|
||||
new() { ApplicationRole = Role.LIC, BusinessRole = "SR INVESTMENT REP" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR LEADERSHIP DEV ADVISOR" },
|
||||
new() { ApplicationRole = Role.MSR, BusinessRole = "SR MEMBER SERV REP" },
|
||||
new() { ApplicationRole = Role.MSR, BusinessRole = "SR MEMBER SERV REP (BILINGUAL)" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR MTG LOAN PROCESSOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR MORTGAGE CLOSING COORDINATOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR MORTGAGE SERVICES SYSTEMS ADMINISTRATOR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR MTG LOAN UNDERWRITER" },
|
||||
new() { ApplicationRole = Role.PFO, BusinessRole = "SR ORG CHANGE & COMMUNICATIONS ADVISOR" },
|
||||
new() { ApplicationRole = Role.PFO, BusinessRole = "SR PERS FIN OFFICER" },
|
||||
new() { ApplicationRole = Role.PFO, BusinessRole = "SR PERS FIN OFFICER - MSC" },
|
||||
new() { ApplicationRole = Role.Developer, BusinessRole = "SR SOFTWARE ENG" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR STAFF ACCOUNTANT" },
|
||||
new() { ApplicationRole = Role.Teller, BusinessRole = "SR TELLER II (FLOATER)" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR BUSINESS ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SR THIRD PARTY MANAGEMENT ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "STAFF ACCOUNTANT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "STAFF COUNSEL" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "STAFF INT AUDITOR" },
|
||||
new() { ApplicationRole = Role.Manager, BusinessRole = "SUPERVISOR, MORTGAGE LENDING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SUPVR COLLECTIONS" },
|
||||
new() { ApplicationRole = Role.BusinessLineManager, BusinessRole = "SVP BR STRATEGY & DE" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SVP BUSINESS LENDING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SVP DIGITAL STRATEGY" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SVP HR TRNG COMMUNIC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "SVP LEGAL, RISK & COMPLIANCE" },
|
||||
new() { ApplicationRole = Role.Manager, BusinessRole = "SVP MORTGAGE SERVICES" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "TALENT ACQUISITION SPECIALIST" },
|
||||
new() { ApplicationRole = Role.MSCTeamLead, BusinessRole = "TEAM LDR - MSC LOANS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "TEAM LDR-CLP" },
|
||||
new() { ApplicationRole = Role.MSCTeamLead, BusinessRole = "TEAM LDR-CONS LN-MSC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "TEAM LDR-IND LNDG" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "TEAM LDR-IND LNDG PM" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "TEAM LDR-INDIRECT LOAN PM" },
|
||||
new() { ApplicationRole = Role.MSCTeamLead, BusinessRole = "TEAM LDR-MSC" },
|
||||
new() { ApplicationRole = Role.MSCTeamLead, BusinessRole = "TEAM LDR-MSC (BILINGUAL)" },
|
||||
new() { ApplicationRole = Role.LIC, BusinessRole = "TEAM LEAD - CLIENT SERVICES ASSISTANTS" },
|
||||
new() { ApplicationRole = Role.Mortgage, BusinessRole = "TEAM LEAD - MTG SERVICING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "TEAM LEAD-COLLECTION" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "TEAM LEADER - CARD SERVICES" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "TECHNICAL WRITER" },
|
||||
new() { ApplicationRole = Role.Teller, BusinessRole = "TELLER I" },
|
||||
new() { ApplicationRole = Role.Teller, BusinessRole = "TELLER I (CO-OP)" },
|
||||
new() { ApplicationRole = Role.Teller, BusinessRole = "TELLER I (FLOATER)" },
|
||||
new() { ApplicationRole = Role.Teller, BusinessRole = "TELLER II" },
|
||||
new() { ApplicationRole = Role.Teller, BusinessRole = "TELLER II (FLOATER)" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "THIRD PARTY MANAGEMENT ANALYST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "TITLE CLERK" },
|
||||
new() { ApplicationRole = Role.MSCTeamLead, BusinessRole = "TM LDR DIGITAL BANK" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "TRAINER-MSC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "TRAINER-PROF DEV/CHNG" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "TRNG ONBD SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "TRNG OPER SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UniversalSpecialistPFO, BusinessRole = "UNIVERSAL SPECIALIST" },
|
||||
new() { ApplicationRole = Role.UniversalSpecialistTeller, BusinessRole = "UNIVERSAL SPECIALIST (FLOATER)" },
|
||||
new() { ApplicationRole = Role.RegionalManager, BusinessRole = "VP BR SALES & SRVC" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP BUSINESS LENDING TEAM LEAD" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP CARD SERVICES" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP COLLECTIONS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP COMM DEVELOPMENT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP CONSUMER LENDING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP CONTROLLER" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP HUMAN RESOURCES" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP IND LENDING" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP INTERNAL AUDIT" },
|
||||
new() { ApplicationRole = Role.LIC, BusinessRole = "VP LANDMARK INV CTR" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP MARKETING" },
|
||||
new() { ApplicationRole = Role.BusinessLineManager, BusinessRole = "VP MEMBER SERVICE CENTER" },
|
||||
new() { ApplicationRole = Role.Mortgage, BusinessRole = "VP MORTGAGE" },
|
||||
new() { ApplicationRole = Role.Manager, BusinessRole = "VP MORTGAGE SALES" },
|
||||
new() { ApplicationRole = Role.Admin, BusinessRole = "VP OPERATIONS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP ORGANIZATIONAL CHANGE MANAGEMENT & COMMUNICATIONS" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP PROJ MGMNT" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP SOFTWARE ENG & DA" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "VP TRAINING & DEV" },
|
||||
new() { ApplicationRole = Role.UNKNOWN_ROLE, BusinessRole = "WEBSITE CONTENT SPECIALIST" }
|
||||
});
|
||||
|
||||
await SaveChangesAsync();
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
+772
@@ -0,0 +1,772 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Results;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Serilog;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
|
||||
public class ApplicationDbIntegrityService : IApplicationDbIntegrityService
|
||||
{
|
||||
private readonly ApplicationDbContext _applicationDbContext;
|
||||
private const string DataIntegrityFailureMessage = "AppUserId maintenance was required, the system was unable to carry out all of this maintenance in an automated fashion and this must be looked into immediately";
|
||||
private const string DataIntegrityPartialSuccessMessage = "AppUserId maintenance was required, it was carried out in an automated fashion but this should not have been required and needs to be looked into";
|
||||
private const string DataIntegritySuccessMessage = "Data integrity audit finished successfully, no maintenance was required";
|
||||
|
||||
public ApplicationDbIntegrityService(ApplicationDbContext applicationDbContext)
|
||||
{
|
||||
_applicationDbContext = applicationDbContext;
|
||||
}
|
||||
|
||||
public async Task<bool> AppUserIdIntegrityMaintenanceSucceeded(CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnsureAuditCreateAndUpdateAppUserIds();
|
||||
|
||||
Log.Information("ApplicationDbIntegrity: RunDataIntegrityAudit method Started");
|
||||
|
||||
var allMaintenanceResults = new List<DataIntegrityAuditResult>
|
||||
{
|
||||
await DetermineActivityMaintenanceAuditResult(),
|
||||
await DetermineActivityTransferActionMaintenanceAuditResult(),
|
||||
await DetermineDeadActivityMaintenanceAuditResult(),
|
||||
await DetermineGoalMaintenanceAuditResult(),
|
||||
await DetermineGoalChangeMaintenanceAuditResult()
|
||||
};
|
||||
|
||||
Log.Information("ApplicationDbIntegrity: RunDataIntegrityAudit method Ended");
|
||||
|
||||
var overallMaintenanceResult = await DetermineOverallDataIntegrityAuditResult(allMaintenanceResults);
|
||||
|
||||
if (!overallMaintenanceResult.MaintenanceAutomationFailed && !overallMaintenanceResult.MaintenanceWasRequired)
|
||||
{
|
||||
Log.Information(DataIntegritySuccessMessage);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!overallMaintenanceResult.MaintenanceAutomationFailed && overallMaintenanceResult.MaintenanceWasRequired)
|
||||
{
|
||||
Log.Information(DataIntegrityPartialSuccessMessage);
|
||||
throw new Exception(DataIntegrityPartialSuccessMessage);
|
||||
}
|
||||
|
||||
if (!overallMaintenanceResult.MaintenanceAutomationFailed && overallMaintenanceResult.MaintenanceWasRequired)
|
||||
{
|
||||
Log.Information(DataIntegrityFailureMessage);
|
||||
throw new Exception(DataIntegrityFailureMessage);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"Failed to execute AppUserId integrity checks, Error: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<DataIntegrityAuditResult> DetermineOverallDataIntegrityAuditResult(List<DataIntegrityAuditResult> dataIntegrityAuditResults)
|
||||
{
|
||||
return await Task.FromResult(
|
||||
new DataIntegrityAuditResult
|
||||
{
|
||||
MaintenanceAutomationFailed = dataIntegrityAuditResults.Any(x => x.MaintenanceAutomationFailed),
|
||||
MaintenanceWasRequired = dataIntegrityAuditResults.Any(x => x.MaintenanceWasRequired)
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<DataIntegrityAuditResult> DetermineActivityMaintenanceAuditResult()
|
||||
{
|
||||
var dataIntegrityAuditResult = new DataIntegrityAuditResult();
|
||||
var targetEmployeeIds = _applicationDbContext.Activities.Where(x => x.EmployeeId != null && x.AppUserId == Guid.Empty)
|
||||
.Select(x => x.EmployeeId)
|
||||
.Distinct();
|
||||
|
||||
if (!targetEmployeeIds.Any())
|
||||
{
|
||||
return dataIntegrityAuditResult;
|
||||
}
|
||||
|
||||
dataIntegrityAuditResult.MaintenanceWasRequired = true;
|
||||
|
||||
Log.Warning("Found Activity records with empty AppUserIds, this should not happen and needs to be investigated");
|
||||
|
||||
foreach (var targetEmployeeId in targetEmployeeIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUsers = _applicationDbContext.AppUsers.Where(x => x.EmployeeId == targetEmployeeId);
|
||||
|
||||
if (appUsers.Count() != 1)
|
||||
{
|
||||
Log.Information($"{appUsers.Count()} returned from AppUser lookup on {targetEmployeeId} during DetermineActivityMaintenanceAuditResult, " +
|
||||
$"unable to perform automatic maintenance this needs to be addressed manually");
|
||||
dataIntegrityAuditResult.MaintenanceAutomationFailed = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
var appUser = await appUsers.FirstAsync();
|
||||
foreach (var item in _applicationDbContext.Activities.Where(x => x.EmployeeId == appUser.EmployeeId
|
||||
&& x.AppUserId == Guid.Empty))
|
||||
{
|
||||
item.AppUserId = appUser.Id;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
dataIntegrityAuditResult.MaintenanceAutomationFailed = true;
|
||||
Log.Error(ex, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return dataIntegrityAuditResult;
|
||||
}
|
||||
|
||||
private async Task<DataIntegrityAuditResult> DetermineActivityTransferActionMaintenanceAuditResult()
|
||||
{
|
||||
var dataIntegrityAuditResult = new DataIntegrityAuditResult();
|
||||
var targetEmployeeIds = _applicationDbContext.ActivityTransferActions.Where(x => x.NewActivityEmployeeId != null && x.NewAppUserId == Guid.Empty)
|
||||
.Select(x => x.NewActivityEmployeeId)
|
||||
.Distinct();
|
||||
|
||||
if (!targetEmployeeIds.Any())
|
||||
{
|
||||
return dataIntegrityAuditResult;
|
||||
}
|
||||
|
||||
dataIntegrityAuditResult.MaintenanceWasRequired = true;
|
||||
|
||||
Log.Information("Found ActivityTransferAction records with empty AppUserIds, this should not happen and needs to be investigated");
|
||||
|
||||
foreach (var targetEmployeeId in targetEmployeeIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUsers = _applicationDbContext.AppUsers.Where(x => x.EmployeeId == targetEmployeeId);
|
||||
|
||||
if (appUsers.Count() != 1)
|
||||
{
|
||||
Log.Information($"{appUsers.Count()} returned from AppUser lookup on {targetEmployeeId} during DetermineActivityTransferActionMaintenanceAuditResult, " +
|
||||
$"unable to perform automatic maintenance this needs to be addressed manually");
|
||||
dataIntegrityAuditResult.MaintenanceAutomationFailed = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
var appUser = await appUsers.FirstAsync();
|
||||
foreach (var item in _applicationDbContext.ActivityTransferActions.Where(x => x.NewActivityEmployeeId == appUser.EmployeeId
|
||||
&& x.NewAppUserId == Guid.Empty))
|
||||
{
|
||||
item.NewAppUserId = appUser.Id;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
dataIntegrityAuditResult.MaintenanceAutomationFailed = true;
|
||||
Log.Error(ex, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return dataIntegrityAuditResult;
|
||||
}
|
||||
|
||||
private void EnsureAuditCreateAndUpdateAppUserIds()
|
||||
{
|
||||
Log.Information("ApplicationDbIntegrity: EnsureAuditCreateAndUpdateAppUserIds method Started");
|
||||
|
||||
foreach (var appUser in _applicationDbContext.AppUsers)
|
||||
{
|
||||
try
|
||||
{
|
||||
SyncIdsWithDb(appUser, true).GetAwaiter().GetResult();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
Log.Information("ApplicationDbIntegrity: EnsureAuditCreateAndUpdateAppUserIds method Ended");
|
||||
}
|
||||
|
||||
private async Task<DataIntegrityAuditResult> DetermineDeadActivityMaintenanceAuditResult()
|
||||
{
|
||||
var dataIntegrityAuditResult = new DataIntegrityAuditResult();
|
||||
var targetEmployeeIds = _applicationDbContext.DeadActivities.Where(x => x.EmployeeId != null && x.AppUserId == Guid.Empty)
|
||||
.Select(x => x.EmployeeId)
|
||||
.Distinct();
|
||||
|
||||
if (!targetEmployeeIds.Any())
|
||||
{
|
||||
return dataIntegrityAuditResult;
|
||||
}
|
||||
|
||||
dataIntegrityAuditResult.MaintenanceWasRequired = true;
|
||||
|
||||
Log.Information("Found DeadActivity records with empty AppUserIds, this should not happen and needs to be investigated");
|
||||
|
||||
foreach (var targetEmployeeId in targetEmployeeIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUsers = _applicationDbContext.AppUsers.Where(x => x.EmployeeId == targetEmployeeId);
|
||||
|
||||
if (appUsers.Count() != 1)
|
||||
{
|
||||
Log.Information($"{appUsers.Count()} returned from AppUser lookup on {targetEmployeeId} during DetermineDeadActivityMaintenanceAuditResult, " +
|
||||
$"unable to perform automatic maintenance this needs to be addressed manually");
|
||||
dataIntegrityAuditResult.MaintenanceAutomationFailed = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
var appUser = await appUsers.FirstAsync();
|
||||
foreach (var item in _applicationDbContext.DeadActivities.Where(x => x.EmployeeId == appUser.EmployeeId
|
||||
&& x.AppUserId == Guid.Empty))
|
||||
{
|
||||
item.AppUserId = appUser.Id;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
dataIntegrityAuditResult.MaintenanceAutomationFailed = true;
|
||||
Log.Error(ex, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return dataIntegrityAuditResult;
|
||||
}
|
||||
|
||||
private async Task<DataIntegrityAuditResult> DetermineGoalMaintenanceAuditResult()
|
||||
{
|
||||
var dataIntegrityAuditResult = new DataIntegrityAuditResult();
|
||||
var targetEmployeeIds = _applicationDbContext.Goals.Where(x => x.EmployeeId != null && x.AppUserId == Guid.Empty).Select(x => x.EmployeeId).Distinct();
|
||||
|
||||
if (!targetEmployeeIds.Any())
|
||||
{
|
||||
return dataIntegrityAuditResult;
|
||||
}
|
||||
|
||||
dataIntegrityAuditResult.MaintenanceWasRequired = true;
|
||||
|
||||
Log.Information("Found Goal records with empty AppUserIds, this should not happen and needs to be investigated");
|
||||
|
||||
foreach (var targetEmployeeId in targetEmployeeIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUsers = _applicationDbContext.AppUsers.Where(x => x.EmployeeId == targetEmployeeId);
|
||||
|
||||
if (appUsers.Count() != 1)
|
||||
{
|
||||
Log.Information($"{appUsers.Count()} returned from AppUser lookup on {targetEmployeeId} during DetermineGoalMaintenanceAuditResult, " +
|
||||
$"unable to perform automatic maintenance this needs to be addressed manually");
|
||||
dataIntegrityAuditResult.MaintenanceAutomationFailed = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
var appUser = await appUsers.FirstAsync();
|
||||
foreach (var item in _applicationDbContext.Goals.Where(x => x.EmployeeId == appUser.EmployeeId
|
||||
&& x.AppUserId == Guid.Empty))
|
||||
{
|
||||
item.AppUserId = appUser.Id;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
dataIntegrityAuditResult.MaintenanceAutomationFailed = true;
|
||||
Log.Error(ex, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return dataIntegrityAuditResult;
|
||||
}
|
||||
|
||||
private async Task<DataIntegrityAuditResult> DetermineGoalChangeMaintenanceAuditResult()
|
||||
{
|
||||
var dataIntegrityAuditResult = new DataIntegrityAuditResult();
|
||||
var targetEmployeeIds = _applicationDbContext.GoalChanges.Where(x => x.PersonId != null && x.AppUserId == Guid.Empty)
|
||||
.Select(x => x.PersonId)
|
||||
.Distinct();
|
||||
|
||||
if (!targetEmployeeIds.Any())
|
||||
{
|
||||
return dataIntegrityAuditResult;
|
||||
}
|
||||
|
||||
dataIntegrityAuditResult.MaintenanceWasRequired = true;
|
||||
|
||||
Log.Information("Found GoalChange records with empty AppUserIds, this should not happen and needs to be investigated");
|
||||
|
||||
foreach (var targetEmployeeId in targetEmployeeIds)
|
||||
{
|
||||
try
|
||||
{
|
||||
var appUsers = _applicationDbContext.AppUsers.Where(x => x.EmployeeId == targetEmployeeId);
|
||||
|
||||
if (appUsers.Count() != 1)
|
||||
{
|
||||
Log.Information($"{appUsers.Count()} returned from AppUser lookup on {targetEmployeeId} during DetermineGoalChangeMaintenanceAuditResult, " +
|
||||
$"unable to perform automatic maintenance this needs to be addressed manually");
|
||||
dataIntegrityAuditResult.MaintenanceAutomationFailed = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
var appUser = await appUsers.FirstAsync();
|
||||
foreach (var item in _applicationDbContext.GoalChanges.Where(x => x.PersonId == appUser.EmployeeId
|
||||
&& x.AppUserId == Guid.Empty))
|
||||
{
|
||||
item.AppUserId = appUser.Id;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
dataIntegrityAuditResult.MaintenanceAutomationFailed = true;
|
||||
Log.Error(ex, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return dataIntegrityAuditResult;
|
||||
}
|
||||
|
||||
public async Task<bool> SyncAppUserUpdate(AppUser appUser)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var item in _applicationDbContext.Activities.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Activities.Where(x => x.LastUpdatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.LastUpdatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Activities.Where(x => x.AppUserId == appUser.Id))
|
||||
{
|
||||
item.EmployeeEmail = appUser.AdEmail;
|
||||
item.EmployeeId = appUser.EmployeeId;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.ActivityDetailUpdates.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.ActivityStateChanges.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.ActivityTransferActions.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.ActivityTransferActions.Where(x => x.LastUpdatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.LastUpdatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.AppUsers.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.AppUsers.Where(x => x.LastUpdatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.LastUpdatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Commissions.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Commissions.Where(x => x.LastUpdatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.LastUpdatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.DeadActivities.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.DeadActivities.Where(x => x.LastUpdatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.LastUpdatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.DeadActivities.Where(x => x.AppUserId == appUser.Id))
|
||||
{
|
||||
item.EmployeeEmail = appUser.AdEmail;
|
||||
item.EmployeeId = appUser.EmployeeId;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.DepartmentAssignments.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.DepartmentAssignments.Where(x => x.LastUpdatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.LastUpdatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.DepartmentLineItems.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.DepartmentLineItems.Where(x => x.LastUpdatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.LastUpdatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Departments.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Departments.Where(x => x.LastUpdatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.LastUpdatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.GoalChanges.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.GoalChanges.Where(x => x.AppUserId == appUser.Id))
|
||||
{
|
||||
item.PersonId = appUser.EmployeeId;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Goals.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Goals.Where(x => x.LastUpdatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.LastUpdatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Goals.Where(x => x.AppUserId == appUser.Id))
|
||||
{
|
||||
item.EmployeeId = appUser.EmployeeId;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.PayoutLineItems.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.PayoutLineItems.Where(x => x.AppUserId == appUser.Id))
|
||||
{
|
||||
item.EmployeeId = appUser.EmployeeId;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.RoleMappings.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.RoleMappings.Where(x => x.LastUpdatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.LastUpdatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.UserDepartmentHistories.Where(x => x.CreatedByAppUserId == appUser.Id)
|
||||
)
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.UserPermissionHistories.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.UserPermissionHistories.Where(x => x.AppUserId == appUser.Id))
|
||||
{
|
||||
item.EmployeeId = int.Parse(appUser.EmployeeId);
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.UserPermissions.Where(x => x.CreatedByAppUserId == appUser.Id))
|
||||
{
|
||||
item.CreatedBy = appUser.AppUserFullNameInFromContextFormat();
|
||||
}
|
||||
|
||||
await _applicationDbContext.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, ex.Message);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task<bool> SyncIdsWithDb(AppUser appUser, bool limitScopeToAuditCreateAndUpdate = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.Information($"ApplicationDbIntegrity: SyncIdsWithDb for User {appUser.FullName} Started");
|
||||
foreach (var item in _applicationDbContext.Activities.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.LastUpdatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Activities.Where(x => x.LastUpdatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.LastUpdatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.LastUpdatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
if (!limitScopeToAuditCreateAndUpdate)
|
||||
{
|
||||
foreach (var item in _applicationDbContext.Activities.Where(x => x.EmployeeEmail == appUser.AdEmail
|
||||
&& x.EmployeeId == appUser.EmployeeId
|
||||
&& x.AppUserId == Guid.Empty))
|
||||
{
|
||||
item.AppUserId = appUser.Id;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.ActivityDetailUpdates.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.ActivityStateChanges.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.ActivityTransferActions.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.ActivityTransferActions.Where(x => x.LastUpdatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.LastUpdatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.LastUpdatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.AppUsers.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.AppUsers.Where(x => x.LastUpdatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.LastUpdatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.LastUpdatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Commissions.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Commissions.Where(x => x.LastUpdatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.LastUpdatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.LastUpdatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.DeadActivities.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.DeadActivities.Where(x => x.LastUpdatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.LastUpdatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.LastUpdatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
if (!limitScopeToAuditCreateAndUpdate)
|
||||
{
|
||||
foreach (var item in _applicationDbContext.DeadActivities.Where(x => x.EmployeeEmail == appUser.AdEmail
|
||||
&& x.EmployeeId == appUser.EmployeeId
|
||||
&& x.AppUserId == Guid.Empty))
|
||||
{
|
||||
item.AppUserId = appUser.Id;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.DepartmentAssignments.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.DepartmentAssignments.Where(x => x.LastUpdatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.LastUpdatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.LastUpdatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
if (!limitScopeToAuditCreateAndUpdate)
|
||||
{
|
||||
foreach (var item in _applicationDbContext.DepartmentAssignments.Where(x => x.Employee.AdEmail == appUser.AdEmail
|
||||
&& x.Employee.EmployeeId == appUser.EmployeeId
|
||||
&& x.AppUserId == Guid.Empty))
|
||||
{
|
||||
item.AppUserId = appUser.Id;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.DepartmentLineItems.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.DepartmentLineItems.Where(x => x.LastUpdatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.LastUpdatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.LastUpdatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Departments.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Departments.Where(x => x.LastUpdatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.LastUpdatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.LastUpdatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.GoalChanges.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
if (!limitScopeToAuditCreateAndUpdate)
|
||||
{
|
||||
foreach (var item in _applicationDbContext.GoalChanges.Where(x => x.PersonId == appUser.EmployeeId
|
||||
&& x.AppUserId == Guid.Empty))
|
||||
{
|
||||
item.AppUserId = appUser.Id;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Goals.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.Goals.Where(x => x.LastUpdatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.LastUpdatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.LastUpdatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
if (!limitScopeToAuditCreateAndUpdate)
|
||||
{
|
||||
foreach (var item in _applicationDbContext.Goals.Where(x => x.EmployeeId == appUser.EmployeeId
|
||||
&& x.AppUserId == Guid.Empty))
|
||||
{
|
||||
item.AppUserId = appUser.Id;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.PayoutLineItems.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
if (!limitScopeToAuditCreateAndUpdate)
|
||||
{
|
||||
foreach (var item in _applicationDbContext.PayoutLineItems.Where(x => x.EmployeeId == appUser.EmployeeId
|
||||
&& x.AppUserId == Guid.Empty))
|
||||
{
|
||||
item.AppUserId = appUser.Id;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.RoleMappings.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.RoleMappings.Where(x => x.LastUpdatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.LastUpdatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.LastUpdatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.UserDepartmentHistories.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.UserPermissionHistories.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
if (!limitScopeToAuditCreateAndUpdate)
|
||||
{
|
||||
foreach (var item in _applicationDbContext.UserPermissionHistories.Where(x => x.EmployeeId.ToString() == appUser.EmployeeId
|
||||
&& x.AppUserId == Guid.Empty))
|
||||
{
|
||||
item.AppUserId = appUser.Id;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in _applicationDbContext.UserPermissions.Where(x => x.CreatedBy == appUser.AppUserFullNameInFromContextFormat()
|
||||
&& x.CreatedByAppUserId == Guid.Empty))
|
||||
{
|
||||
item.CreatedByAppUserId = appUser.Id;
|
||||
}
|
||||
|
||||
if (!limitScopeToAuditCreateAndUpdate)
|
||||
{
|
||||
foreach (var item in _applicationDbContext.UserPermissions.Where(x => x.AppUser.AdEmail == appUser.AdEmail
|
||||
&& x.AppUser.EmployeeId == appUser.EmployeeId
|
||||
&& x.AppUserId == Guid.Empty))
|
||||
{
|
||||
item.AppUserId = appUser.Id;
|
||||
}
|
||||
}
|
||||
|
||||
await _applicationDbContext.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, ex.Message);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Serilog;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
|
||||
public class CurrentUserService : ICurrentUserService
|
||||
{
|
||||
protected readonly IHttpContextAccessor HttpContextAccessor;
|
||||
|
||||
public CurrentUserService(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
HttpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
public ApplicationUser GetCurrentUser()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (HttpContextAccessor != null && HttpContextAccessor.HttpContext != null)
|
||||
{
|
||||
var userClaimsPrincipal = HttpContextAccessor.HttpContext.User;
|
||||
var parsedApplicationUser = new ApplicationUser
|
||||
{
|
||||
FirstName = userClaimsPrincipal.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.GivenName)?.Value,
|
||||
LastName = userClaimsPrincipal.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.Surname)?.Value,
|
||||
Email = userClaimsPrincipal.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.Upn)?.Value,
|
||||
Roles = userClaimsPrincipal.Claims.Where((claim) => claim.Type == ClaimTypes.Role).Select((claim) => claim?.Value).ToArray(),
|
||||
IsSystem = false,
|
||||
};
|
||||
Log.Debug($"ApplicationUser: {parsedApplicationUser.Email} successfully parsed from HttpContext");
|
||||
return parsedApplicationUser;
|
||||
}
|
||||
|
||||
Log.Debug("HttpContextAccessor or HttpContext are null, returning default System ApplicationUser");
|
||||
return DefaultSystemApplicationUser();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, ex.Message);
|
||||
return DefaultSystemApplicationUser();
|
||||
}
|
||||
}
|
||||
|
||||
private ApplicationUser DefaultSystemApplicationUser()
|
||||
{
|
||||
return new ApplicationUser()
|
||||
{
|
||||
FirstName = "Incentive",
|
||||
LastName = "Manager",
|
||||
Email = "",
|
||||
Roles = new[] { Role.UNKNOWN_ROLE.Name },
|
||||
IsSystem = true
|
||||
};
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
|
||||
public class DateTimeService : IDateTime
|
||||
{
|
||||
public DateTime Now => DateTime.Now;
|
||||
public DateTime UTCNow => DateTime.UtcNow;
|
||||
public DateTime ConvertDnaUnspecifiedTimeToUtc(DateTime dateTime) {
|
||||
var dnaAssumedTimeZone = TimeZoneConverter.TZConvert.GetTimeZoneInfo("America/Chicago");
|
||||
return TimeZoneInfo.ConvertTime(dateTime, dnaAssumedTimeZone, TimeZoneInfo.Utc);
|
||||
}
|
||||
|
||||
public DateTime? CSTWindowsNow
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
var centralTimeZone = TimeZoneConverter.TZConvert.GetTimeZoneInfo("Central Standard Time");
|
||||
return TimeZoneInfo.ConvertTimeFromUtc(UTCNow, centralTimeZone);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime? CSTLinuxNow
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
var centralTimeZone = TimeZoneConverter.TZConvert.GetTimeZoneInfo("America/Chicago");
|
||||
return TimeZoneInfo.ConvertTimeFromUtc(UTCNow, centralTimeZone);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime ConvertDateTimeFromCSTToUTCLinux(string dateTimeString)
|
||||
{
|
||||
var date = DateTime.Parse(dateTimeString);
|
||||
return TimeZoneInfo.ConvertTime(date, TimeZoneConverter.TZConvert.GetTimeZoneInfo("America/Chicago"), TimeZoneInfo.Utc);
|
||||
}
|
||||
public DateTime ConvertDateTimeFromCSTToUTCWindows(string dateTimeString)
|
||||
{
|
||||
var date = DateTime.Parse(dateTimeString);
|
||||
return TimeZoneInfo.ConvertTime(date, TimeZoneConverter.TZConvert.GetTimeZoneInfo("Central Standard Time"), TimeZoneInfo.Utc);
|
||||
}
|
||||
|
||||
public DateTime getNextBonusPeriod(DateTime today)
|
||||
{
|
||||
var seedDate = new DateTime(2021, 10, 01);
|
||||
while (seedDate.Date <= today.Date || PayPeriodInMonth(seedDate) != 2)
|
||||
{
|
||||
seedDate = seedDate.AddDays(14);
|
||||
}
|
||||
return seedDate;
|
||||
}
|
||||
|
||||
private int PayPeriodInMonth(DateTime input)
|
||||
{
|
||||
var period = 1;
|
||||
var previousPayDay = input.AddDays(-14);
|
||||
if (previousPayDay.Month == input.Month)
|
||||
{
|
||||
period = 2;
|
||||
}
|
||||
previousPayDay = previousPayDay.AddDays(-14);
|
||||
if (previousPayDay.Month == input.Month)
|
||||
{
|
||||
period = 3;
|
||||
}
|
||||
|
||||
return period;
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
|
||||
public interface IApplicationDbContext
|
||||
{
|
||||
DbSet<Goal> Goals { get; set; }
|
||||
DbSet<GoalChange> GoalChanges { get; set; }
|
||||
DbSet<Activity> Activities { get; set; }
|
||||
DbSet<ActivityDetail> ActivityDetails { get; set; }
|
||||
DbSet<ActivityStateChange> ActivityStateChanges { get; set; }
|
||||
DbSet<ActivityDetailUpdate> ActivityDetailUpdates { get; set; }
|
||||
public DbSet<Department> Departments { get; set; }
|
||||
public DbSet<AppUser> AppUsers { get; set; }
|
||||
public DbSet<UserDepartment> DepartmentAssignments { get; set; }
|
||||
public DbSet<RoleMapping> RoleMappings { get; set; }
|
||||
DbSet<Commission> Commissions { get; set; }
|
||||
public DbSet<ProcessorHistoryRecord> ProcessorRunHistory { get; set; }
|
||||
public DbSet<UserPermission> UserPermissions { get; set; }
|
||||
public DbSet<PayoutLineItem> PayoutLineItems { get; set; }
|
||||
public DbSet<UserAssignment> UserAssignments { get; set; }
|
||||
public DbSet<ActivityTransferAction> ActivityTransferActions { get; set; }
|
||||
public DbSet<DeadActivity> DeadActivities { get; set; }
|
||||
public DbSet<DepartmentLineItem> DepartmentLineItems { get; set; }
|
||||
public DbSet<UserDepartmentHistory> UserDepartmentHistories { get; set; }
|
||||
public DbSet<UserPermissionHistory> UserPermissionHistories { get; set; }
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken());
|
||||
public Task SeedRoleMappingData();
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
|
||||
public interface IApplicationDbIntegrityService
|
||||
{
|
||||
Task<bool> AppUserIdIntegrityMaintenanceSucceeded(CancellationToken cancellationToken);
|
||||
Task<bool> SyncAppUserUpdate(AppUser appUser);
|
||||
Task<bool> SyncIdsWithDb(AppUser appUser, bool limitScopeToAuditCreateAndUpdate = false);
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
|
||||
public interface ICurrentUserService
|
||||
{
|
||||
ApplicationUser GetCurrentUser();
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
|
||||
public interface IDateTime
|
||||
{
|
||||
DateTime Now { get; }
|
||||
DateTime UTCNow { get; }
|
||||
DateTime? CSTLinuxNow { get; }
|
||||
DateTime? CSTWindowsNow { get; }
|
||||
DateTime ConvertDateTimeFromCSTToUTCWindows(string dateTimeString);
|
||||
DateTime ConvertDateTimeFromCSTToUTCLinux(string dateTimeString);
|
||||
DateTime getNextBonusPeriod(DateTime today);
|
||||
}
|
||||
Reference in New Issue
Block a user