using Microsoft.EntityFrameworkCore; using LCU.API.Internal.RepoApi.Repos.Models.Settings; using LCU.API.Internal.RepoApi.Repos.Models; using LCU.API.Collections.CollectionsApiLib.Models; using LCU.API.Internal.RepoApi.Repos.Models.Producer; using LCU.API.Internal.RepoApi.Repos.Models.Reporting; using System.Data.Entity.Infrastructure; using LCU.Library.Internal.RepoApiModels.Models; namespace LCU.API.Internal.RepoApi.Repos.Persistence { public class AppDbContext : DbContext { public DbSet AccountTypeCodes { get; set; } public DbSet AllowedStatusChanges { get; set; } public DbSet Auctions { get; set; } public DbSet AuctionAssignments { get; set; } public DbSet AuctionAssignmentNotes { get; set; } public DbSet AuditRecords { get; set; } public DbSet BodyStyleCodes { get; set; } public DbSet Borrowers { get; set; } public DbSet CleaningLevelCodes { get; set; } public DbSet Collaterals { get; set; } public DbSet CollateralTypes { get; set; } public DbSet CollateralTypesToVehicleTypes { get; set; } public DbSet EventAlerts { get; set; } public DbSet FloorPriceValuesUsed { get; set; } public DbSet HoldStatusCodes { get; set; } public DbSet ImsAutoFileData { get; set; } public DbSet Letters { get; set; } public DbSet LoanCategories { get; set; } public DbSet LocationTypeCodes { get; set; } public DbSet ProcessingReceipts { get; set; } public DbSet RepoAccounts { get; set; } public DbSet RepoCompanies { get; set; } public DbSet RepoManualStatuses { get; set; } public DbSet RepoStatusChanges { get; set; } public DbSet VehicleTypeCodes { get; set; } public DbSet VehicleFloorPricingParameters { get; set; } public DbSet RefundStatuses { get; set; } public DbSet AuctionAssignmentToCollaterals { get; set; } public DbSet RepoCompanySelections { get; set; } public DbSet SavedLocations { get; set; } public DbSet ExternalUsers { get; set; } public DbSet SixtyPLusCollectors { get; set; } public DbSet RepoSyncRunInfo { get; set; } public DbSet RepoSyncBatch { get; set; } // Queries for Reporting / etc //TODO REMOVING FOR testing //public DbQuery StandardReportEntries { get; set; } //public DbQuery ActiveAccountEntries { get; set; } public AppDbContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.Entity().ToTable("EventAlert"); builder.Entity().HasKey(p => p.Id); builder.Entity().Property(p => p.Id).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.AccountNo).IsRequired(); builder.Entity().Property(p => p.DateAdded).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.CreatedBy).IsRequired().HasMaxLength(25); builder.Entity().Property(p => p.Message).IsRequired(); builder.Entity().Property(p => p.EmailRecipient); builder.Entity().Property(p => p.EmailBody); builder.Entity().ToTable("Borrowers"); builder.Entity().HasKey(p => new { p.RepoId, p.IndividualId }); builder.Entity().Property(p => p.IndividualName).IsRequired(); builder.Entity().Property(p => p.OwnershipType).IsRequired(); builder.Entity().ToTable("ProcessingReceipt"); builder.Entity().HasKey(p => new { p.AccountNo, p.AccountId, p.CaseId }); builder.Entity().Property(p => p.AccountId); builder.Entity().Property(p => p.CaseId); builder.Entity().Property(p => p.QueuedBy); builder.Entity().Property(p => p.Message); //TODO: DO this for repocompanyselection repo type builder.Entity().Property(p => p.Outcome) .HasConversion(x => x.ToString(), x => (RepoProcessingResult)Enum.Parse(typeof(RepoProcessingResult), x)); builder.Entity().Property(p => p.Processed); builder.Entity().ToTable("Repos"); builder.Entity().HasKey(p => p.RepoId); builder.Entity().Property(p => p.RepoId).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.AccountNo).IsRequired(); builder.Entity().Property(p => p.Status).IsRequired(); builder.Entity().Property(p => p.SubStatus); builder.Entity().HasMany(p => p.Borrowers); builder.Entity().HasMany(p => p.Collaterals); builder.Entity().HasMany(p => p.RepoStatusChanges); builder.Entity().HasOne(p => p.RefundStatus).WithOne().IsRequired(false); builder.Entity().Property(p => p.RedemptionExpiredDate); builder.Entity().HasOne(p => p.SixtyPlusCollector); builder.Entity().ToTable("RepoStatusChanges"); builder.Entity().HasKey(p => new { p.RepoId, p.Id }); builder.Entity().Property(p => p.RepoId).IsRequired(); builder.Entity().Property(p => p.StatusFrom).IsRequired(); builder.Entity().Property(p => p.StatusTo).IsRequired(); builder.Entity().Property(p => p.ChangedBy).IsRequired(); builder.Entity().Property(p => p.ChangedDate).IsRequired().ValueGeneratedOnAdd(); builder.Entity().ToTable("AuditTable"); builder.Entity().HasKey(p => p.ID); builder.Entity().Property(p => p.DatePerformed).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.Description).IsRequired(); builder.Entity().Property(p => p.Action).IsRequired(); builder.Entity().Property(p => p.ClassName).IsRequired(); builder.Entity().Property(p => p.PerformedBy).IsRequired(); builder.Entity().Property(p => p.KeyRepresentation).IsRequired(); builder.Entity().Property(p => p.PropertyValues); builder.Entity().ToTable("Collaterals"); builder.Entity().HasKey(p => p.CollateralId); builder.Entity().Property(p => p.CollateralId).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.RepoId).IsRequired(); builder.Entity().Property(p => p.Vin); builder.Entity().Property(p => p.Make); builder.Entity().Property(p => p.Model); builder.Entity().Property(p => p.Year); builder.Entity().Property(p => p.Description); builder.Entity().Property(p => p.VehicleType); builder.Entity().Property(p => p.BodyStyle); builder.Entity().Property(p => p.Inoperable); builder.Entity().Property(p => p.CollateralTypeId); builder.Entity().Property(p => p.RetitledInLandmarkName); builder.Entity().Property(p => p.RefCollateralId); builder.Entity().HasMany(p => p.AuctionAssignmentToCollaterals); builder.Entity().HasMany(p => p.RepoCompanySelections); builder.Entity().ToTable("RepoManualStatus"); builder.Entity().HasKey(p => p.ID); builder.Entity().Property(p => p.ID).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.Description).IsRequired(); builder.Entity().Property(p => p.IsActiveStatus).IsRequired(); builder.Entity().Property(p => p.WatchForStatusChanges).IsRequired(); builder.Entity().ToTable("AccountTypeCodes"); builder.Entity().HasKey(p => p.ID); builder.Entity().Property(p => p.ID).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.Description).IsRequired(); builder.Entity().Property(p => p.IsVisible).IsRequired(); builder.Entity().Property(p => p.CategoryId); builder.Entity().ToTable("AllowedStatusChanges"); builder.Entity().HasKey(p => p.ID); builder.Entity().Property(p => p.ID).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.CurrentStatus).IsRequired(); builder.Entity().Property(p => p.AllowedChangeStatus).IsRequired(); builder.Entity().ToTable("BodyStyleCodes"); builder.Entity().HasKey(p => p.Code); builder.Entity().Property(p => p.Code).IsRequired(); builder.Entity().Property(p => p.Description).IsRequired(); builder.Entity().ToTable("CleaningLevelCodes"); builder.Entity().HasKey(p => p.Code); builder.Entity().Property(p => p.Code).IsRequired(); builder.Entity().Property(p => p.Description).IsRequired(); builder.Entity().ToTable("CollateralTypes"); builder.Entity().HasKey(p => p.ID); builder.Entity().Property(p => p.ID).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.Description).IsRequired(); builder.Entity().Property(p => p.LookupHandler).IsRequired(); builder.Entity().ToTable("HoldStatusCodes"); builder.Entity().HasKey(p => p.Code); builder.Entity().Property(p => p.Code).IsRequired(); builder.Entity().Property(p => p.Description).IsRequired(); builder.Entity().ToTable("LoanCategories"); builder.Entity().HasKey(p => p.ID); builder.Entity().Property(p => p.ID).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.CategoryName).IsRequired(); builder.Entity().ToTable("LocationTypeCodes"); builder.Entity().HasKey(p => p.Code); builder.Entity().Property(p => p.Code).IsRequired(); builder.Entity().Property(p => p.Description).IsRequired(); builder.Entity().ToTable("VehicleTypeCodes"); builder.Entity().HasKey(p => p.Code); builder.Entity().Property(p => p.Code).IsRequired(); builder.Entity().Property(p => p.Description).IsRequired(); builder.Entity().ToTable("CollateralTypesToVehicleTypes"); builder.Entity().HasKey(p => p.ID); builder.Entity().Property(p => p.ID).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.VehicleTypeId).IsRequired(); builder.Entity().ToTable("VehicleFloorPricingParameters"); builder.Entity().HasKey(p => p.Id); builder.Entity().Property(p => p.Id).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.LowCondition).IsRequired(); builder.Entity().Property(p => p.HighCondition).IsRequired(); builder.Entity().Property(p => p.NADAFirstValue).IsRequired(); builder.Entity().Property(p => p.NADASecondValue).IsRequired(); builder.Entity().Property(p => p.MMRAdjustedValue).IsRequired(); builder.Entity().Property(p => p.PercentageOf).IsRequired(); builder.Entity().Property(p => p.ValuationServiceType).IsRequired(); builder.Entity().ToTable("Letters"); builder.Entity().HasKey(p => p.ActionCode); builder.Entity().Property(p => p.Description).IsRequired(); builder.Entity().Property(p => p.DaysToWait); builder.Entity().Property(p => p.WhenLetterIsSent); builder.Entity().ToTable("FloorPriceValuesUsed"); builder.Entity().HasKey(p => new { p.AuctionAssignmentId, p.CollateralValuationId }); builder.Entity().Property(p => p.AuctionAssignmentId).IsRequired(); builder.Entity().Property(p => p.RepoId).IsRequired(); builder.Entity().Property(p => p.CollateralValuationId).IsRequired(); builder.Entity().Property(p => p.Condition); builder.Entity().Property(p => p.LowParam); builder.Entity().Property(p => p.HighParam); builder.Entity().Property(p => p.PercentageOf); builder.Entity().Property(p => p.AuctionGuideBookPrice); builder.Entity().Property(p => p.WasAuctionGuideBookPriceUsed); builder.Entity().Property(p => p.MMRNationalAdjustedPrice); builder.Entity().Property(p => p.MMRRegionalAdjustedPrice); builder.Entity().Property(p => p.WasMMRNationalAdjustedPriceUsed); builder.Entity().Property(p => p.WasMMRRegionalAdjustedPriceUsed); builder.Entity().Property(p => p.NADALowAdjustedAuctionValue); builder.Entity().Property(p => p.NADAAverageAdjustedAuctionValue); builder.Entity().Property(p => p.NADAHighAdjustedAuctionValue); builder.Entity().Property(p => p.WasNADALowAdjustedAuctionValueUsed); builder.Entity().Property(p => p.WasNADAAverageAdjustedAuctionValueUsed); builder.Entity().Property(p => p.WasNADAHighAdjustedAuctionValueUsed); builder.Entity().Property(p => p.NADAMMRFloorPrice); builder.Entity().HasOne(p => p.CollateralValuation); // Only added code-referenced fields for below entities builder.Entity().ToTable("Auctions"); builder.Entity().HasKey(p => p.AuctionID); builder.Entity().Property(p => p.AuctionID).IsRequired(); builder.Entity().Property(p => p.Name); builder.Entity().Property(p => p.Active); builder.Entity().Property(p => p.Address_Line_1); builder.Entity().Property(p => p.Address_Line_2); builder.Entity().Property(p => p.City); builder.Entity().Property(p => p.Country); builder.Entity().Property(p => p.Fax); builder.Entity().Property(p => p.Latitude); builder.Entity().Property(p => p.Longitude); builder.Entity().Property(p => p.Phone); builder.Entity().Property(p => p.State); builder.Entity().Property(p => p.ZIP); builder.Entity().ToTable("AuctionAssignments"); builder.Entity().HasKey(p => p.ID); builder.Entity().Property(p => p.ID).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.AuctionId).IsRequired(); builder.Entity().Property(p => p.AuctionCustomerNo).IsRequired(); builder.Entity().Property(p => p.CollateralVIN); builder.Entity().Property(p => p.DateSubmitted); builder.Entity().Property(p => p.FloorPrice); builder.Entity().Property(p => p.FloorPriceResponseCode); builder.Entity().Property(p => p.FloorPriceResponseDescription); builder.Entity().Property(p => p.FloorPriceSubmissionErrors); builder.Entity().Property(p => p.HoldStatus); builder.Entity().Property(p => p.HoldUntil); builder.Entity().Property(p => p.RedeemedDate); builder.Entity().Property(p => p.VehicleType); builder.Entity().Property(p => p.BodyStyle); builder.Entity().Property(p => p.Inoperable); builder.Entity().Property(p => p.RetailValue); builder.Entity().Property(p => p.AuctionNotes); builder.Entity().Property(p => p.AvailablePickupDate); builder.Entity().Property(p => p.LegalSaleDate); builder.Entity().Property(p => p.CleaningLevel); builder.Entity().Property(p => p.SubmissionErrors); builder.Entity().Property(p => p.SubmissionResponseCode); builder.Entity().Property(p => p.SubmissionResponseDescription); builder.Entity().Property(p => p.SentTitleDocsDate); builder.Entity().Property(p => p.TitleSentResponseCode); builder.Entity().Property(p => p.TitleSentResponseDescription); builder.Entity().Property(p => p.TitleSentSubmissionErrors); builder.Entity().Property(p => p.AddedThroughRepoDatabase); builder.Entity().Property(p => p.IsActive).HasDefaultValue(true); builder.Entity().HasOne(p => p.AutoIMS); builder.Entity().HasOne(p => p.Auction); builder.Entity().HasMany(p => p.AuctionAssignmentToCollaterals); builder.Entity().HasOne(p => p.FloorPriceValuesUsed); builder.Entity().ToTable("AuctionAssignmentNotes"); builder.Entity().HasKey(p => p.Id); builder.Entity().Property(p => p.Id).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.AuctionAssignmentId).IsRequired(); builder.Entity().Property(p => p.AuctionCustomerNo).IsRequired(); builder.Entity().Property(p => p.DateWritten); builder.Entity().Property(p => p.Origin); builder.Entity().Property(p => p.Text); builder.Entity().Property(p => p.Type); builder.Entity().ToTable("ImsAutoFileData"); builder.Entity().HasKey(p => new { p.VIN, p.RepoId }); builder.Entity().Property(p => p.RepoId).IsRequired(); builder.Entity().Property(p => p.AuctionCustomerNo).IsRequired(); builder.Entity().Property(p => p.VIN).IsRequired(); builder.Entity().Property(p => p.AssignmentAccepted); builder.Entity().Property(p => p.AuctionAssignmentId); builder.Entity().Property(p => p.DateReceivedFromAutoIMS); builder.Entity().Property(p => p.AnnouncedConditions); builder.Entity().Property(p => p.ApprovedVehicleGrade); builder.Entity().Property(p => p.ArbitrationReason); builder.Entity().Property(p => p.AsIs100KMiles); builder.Entity().Property(p => p.AuctionAge); builder.Entity().Property(p => p.AuctionGuideBookPrice); builder.Entity().Property(p => p.BuyerId); builder.Entity().Property(p => p.BuyerName); builder.Entity().Property(p => p.ChargeAmount); builder.Entity().Property(p => p.CheckAmount); builder.Entity().Property(p => p.ClientAge); builder.Entity().Property(p => p.ClientCancelled); builder.Entity().Property(p => p.CollateralImagePath); builder.Entity().Property(p => p.CollisionDamage); builder.Entity().Property(p => p.ConditionReportLink); builder.Entity().Property(p => p.DateEnteredAutoIMS); builder.Entity().Property(p => p.DatePickedUp); builder.Entity().Property(p => p.DateofLoss); builder.Entity().Property(p => p.DaysRun); builder.Entity().Property(p => p.DaysRunHighestBidRecordedbyAuction); builder.Entity().Property(p => p.DaystoDelivery); builder.Entity().Property(p => p.Description); builder.Entity().Property(p => p.FloorPriceAccepted); builder.Entity().Property(p => p.FundsSent); builder.Entity().Property(p => p.GrossPercentFloor); builder.Entity().Property(p => p.HighestBid); builder.Entity().Property(p => p.InspectedDate); builder.Entity().Property(p => p.IsDrivable); builder.Entity().Property(p => p.IsOperable); builder.Entity().Property(p => p.MMR); builder.Entity().Property(p => p.MMRNationalAdjustedPrice); builder.Entity().Property(p => p.MMRRegionalAdjustedPrice); builder.Entity().Property(p => p.NetPercentFloor); builder.Entity().Property(p => p.OTHERAdvancedOther); builder.Entity().Property(p => p.OTHERAdvancedStorage); builder.Entity().Property(p => p.OTHERAdvancedTow); builder.Entity().Property(p => p.OTHERMiscellaneous); builder.Entity().Property(p => p.OTHERTotal); builder.Entity().Property(p => p.OtherAdvanceFees); builder.Entity().Property(p => p.ScheduledSaleDate); builder.Entity().Property(p => p.SoldDate); builder.Entity().Property(p => p.Status); builder.Entity().Property(p => p.SalePrice); builder.Entity().Property(p => p.ShipmentDate); builder.Entity().Property(p => p.StorageCost); builder.Entity().Property(p => p.StorageRatePerDay); builder.Entity().Property(p => p.StatedMileage); builder.Entity().Property(p => p.TitleNumber); builder.Entity().Property(p => p.TitleReceived); builder.Entity().Property(p => p.TitleReturned); builder.Entity().Property(p => p.TitleState); builder.Entity().Property(p => p.TitleStatus); builder.Entity().Property(p => p.TitleStatusfromAuction); builder.Entity().Property(p => p.TotalCharges); builder.Entity().Property(p => p.TowCost); builder.Entity().Property(p => p.VehicleDecimalGradeCode); builder.Entity().Property(p => p.VehicleGrade); builder.Entity().ToTable("RepoCompany"); builder.Entity().HasKey(p => p.ID); builder.Entity().Property(p => p.ID).IsRequired().ValueGeneratedOnAdd(); builder.Entity().Property(p => p.Name); builder.Entity().Property(p => p.Email); builder.Entity().ToTable("RefundStatuses"); builder.Entity().HasKey(p => p.RepoId); builder.Entity().ToTable("AuctionAssignmentsToCollaterals"); builder.Entity().HasKey(p => new { p.AuctionAssignmentId, p.CollateralId }); builder.Entity() .HasOne(aa2c => aa2c.AuctionAssignment) .WithMany(auctionAssignment => auctionAssignment.AuctionAssignmentToCollaterals) .HasForeignKey(aa2c => aa2c.AuctionAssignmentId); builder.Entity() .HasOne(aa2c => aa2c.Collateral) .WithMany(Collateral => Collateral.AuctionAssignmentToCollaterals) .HasForeignKey(aa2c => aa2c.CollateralId); builder.Entity().ToTable("RepoCompanySelections"); builder.Entity().HasKey(p => p.Id); builder.Entity().Property(p => p.RepoType) .HasConversion(x => x.ToString(), x => (RepoType)Enum.Parse(typeof(RepoType), x)); builder.Entity().Property(p => p.Processed); builder.Entity().ToTable("SavedLocations"); builder.Entity().HasKey(p => p.ID); builder.Entity().ToTable("UserCache"); builder.Entity().HasKey(p => p.Id); builder.Entity().Property(p => p.Name); builder.Entity().Property(p => p.Code); builder.Entity().ToTable("SixtyPlusCollector"); builder.Entity().HasKey(p => p.SixtyPlusCollectorId); } } }