/// <summary>Convert from EmployerLiability DTO to entity</summary> /// <param name="dbContext">DB Context to use for attaching entity</param> /// <param name="dto">DTO to convert from</param> /// <param name="dtoEntities">Used internally to track which dtos have been converted to entites already (to avoid re-converting when circularly referenced)</param> /// <returns>Resultant EmployerLiability entity</returns> public static EmployerLiability FromDto(FACTS.Framework.DAL.DbContext dbContext, EmployerLiabilityDto dto, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities = null) { dtoEntities = dtoEntities ?? new Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity>(); if (dtoEntities.ContainsKey(dto)) { return((EmployerLiability)dtoEntities[dto]); } EmployerLiability entity = new EmployerLiability(); dtoEntities.Add(dto, entity); FromDtoSet(dbContext, dto, entity, dtoEntities); if (dbContext != null) { dbContext.Entry(entity).State = (dto.IsNew ? EntityState.Added : (dto.IsDeleted ? EntityState.Deleted : EntityState.Modified)); } return(entity); }
/// <summary>Convert from EmployerLiability DTO to entity</summary> /// <param name="dbContext">DB Context to use for attaching entity</param> /// <param name="dto">DTO to convert from</param> /// <param name="dtoEntities">Used internally to track which dtos have been converted to entites already (to avoid re-converting when circularly referenced)</param> /// <returns>Resultant EmployerLiability entity</returns> public static EmployerLiability FromDto(FACTS.Framework.DAL.DbContext dbContext, EmployerLiabilityDto dto, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities = null) { dtoEntities = dtoEntities ?? new Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity>(); if (dtoEntities.ContainsKey(dto)) { return((EmployerLiability)dtoEntities[dto]); } EmployerLiability entity = new EmployerLiability(); dtoEntities.Add(dto, entity); entity.CreateDateTime = dto.CreateDateTime; entity.CreateUserId = dto.CreateUserId; entity.EmployerId = dto.EmployerId; entity.GrossWagesPaid = dto.GrossWagesPaid; entity.HasEmployed10In20Weeks = dto.HasEmployed10In20Weeks; entity.HasEmployed1In20Weeks = dto.HasEmployed1In20Weeks; entity.HasPaid1KDomesticWages = dto.HasPaid1KDomesticWages; entity.HasPaid20KAgriculturalLaborWages = dto.HasPaid20KAgriculturalLaborWages; entity.HasPaid450RegularWages = dto.HasPaid450RegularWages; entity.LiabilityAmountMetQuarter = dto.LiabilityAmountMetQuarter; entity.LiabilityAmountMetYear = dto.LiabilityAmountMetYear; entity.UpdateDateTime = dto.UpdateDateTime; entity.UpdateNumber = dto.UpdateNumber; entity.UpdateProcess = dto.UpdateProcess; entity.UpdateUserId = dto.UpdateUserId; entity.Employer = (dto.Employer == null) ? null : Employer.FromDto(dbContext, dto.Employer, dtoEntities); if (dbContext != null) { dbContext.Entry(entity).State = (dto.IsNew ? EntityState.Added : (dto.IsDeleted ? EntityState.Deleted : EntityState.Modified)); } return(entity); }
protected static void FromDtoSet(FACTS.Framework.DAL.DbContext dbContext, EmployerLiabilityDto dto, EmployerLiability entity, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities) { entity.CreateDateTime = dto.CreateDateTime; entity.CreateUserId = dto.CreateUserId; entity.EmployerId = dto.EmployerId; entity.GrossWagesPaid = dto.GrossWagesPaid; entity.HasEmployed10In20Weeks = dto.HasEmployed10In20Weeks; entity.HasEmployed1In20Weeks = dto.HasEmployed1In20Weeks; entity.HasPaid1KDomesticWages = dto.HasPaid1KDomesticWages; entity.HasPaid20KAgriculturalLaborWages = dto.HasPaid20KAgriculturalLaborWages; entity.HasPaid450RegularWages = dto.HasPaid450RegularWages; entity.LiabilityAmountMetQuarter = dto.LiabilityAmountMetQuarter; entity.LiabilityAmountMetYear = dto.LiabilityAmountMetYear; entity.UpdateDateTime = dto.UpdateDateTime; entity.UpdateNumber = dto.UpdateNumber; entity.UpdateProcess = dto.UpdateProcess; entity.UpdateUserId = dto.UpdateUserId; entity.Employer = (dto.Employer == null) ? null : Employer.FromDto(dbContext, dto.Employer, dtoEntities); }
protected static void FromDtoSet(FACTS.Framework.DAL.DbContext dbContext, EmployerDto dto, Employer entity, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities) { entity.BusinessTypeCode = dto.BusinessTypeCode; entity.CreateDateTime = dto.CreateDateTime; entity.CreateUserId = dto.CreateUserId; entity.EmployerId = dto.EmployerId; entity.EntityName = dto.EntityName; entity.EntityTypeCode = dto.EntityTypeCode; entity.Fein = dto.Fein; entity.HasPhysicalLocation = dto.HasPhysicalLocation; entity.HasTelecommuter = dto.HasTelecommuter; entity.IsAcquired = dto.IsAcquired; entity.IsApplyingForREIM = dto.IsApplyingForREIM; entity.IsClientOfPEO = dto.IsClientOfPEO; entity.IsExemptUnderIRS501C3 = dto.IsExemptUnderIRS501C3; entity.IsIndividualContractor = dto.IsIndividualContractor; entity.IsPresentInMultipleLoc = dto.IsPresentInMultipleLoc; entity.IsProfessionalEmployerOrg = dto.IsProfessionalEmployerOrg; entity.IsServiceBegin = dto.IsServiceBegin; entity.LiabilityDate = dto.LiabilityDate; entity.LiabilityIncurredDate = dto.LiabilityIncurredDate; entity.NoOfEmployeesPaid = dto.NoOfEmployeesPaid; entity.NoOfLocation = dto.NoOfLocation; entity.RegistrationDate = dto.RegistrationDate; entity.ReportMethodCode = dto.ReportMethodCode; entity.ServiceBeginDate = dto.ServiceBeginDate; entity.StatusCode = dto.StatusCode; entity.StatusDate = dto.StatusDate; entity.SubjectivityCode = dto.SubjectivityCode; entity.UpdateDateTime = dto.UpdateDateTime; entity.UpdateNumber = dto.UpdateNumber; entity.UpdateProcess = dto.UpdateProcess; entity.UpdateUserId = dto.UpdateUserId; entity.UserName = dto.UserName; if (dto.AddressLinks != null) { foreach (AddressLinkDto addressLink in dto.AddressLinks) { entity.AddressLinks.Add(DbEntities.AddressLink.FromDto(dbContext, addressLink, dtoEntities)); } } if (dto.EmployerAccountTransactions != null) { foreach (EmployerAccountTransactionDto employerAccountTransaction in dto.EmployerAccountTransactions) { entity.EmployerAccountTransactions.Add(DbEntities.EmployerAccountTransaction.FromDto(dbContext, employerAccountTransaction, dtoEntities)); } } if (dto.EmployerContacts != null) { foreach (EmployerContactDto employerContact in dto.EmployerContacts) { entity.EmployerContacts.Add(DbEntities.EmployerContact.FromDto(dbContext, employerContact, dtoEntities)); } } entity.EmployerLiability = (dto.EmployerLiability == null) ? null : EmployerLiability.FromDto(dbContext, dto.EmployerLiability, dtoEntities); entity.EmployerPreference = (dto.EmployerPreference == null) ? null : EmployerPreference.FromDto(dbContext, dto.EmployerPreference, dtoEntities); if (dto.EmployerUnits != null) { foreach (EmployerUnitDto employerUnit in dto.EmployerUnits) { entity.EmployerUnits.Add(DbEntities.EmployerUnit.FromDto(dbContext, employerUnit, dtoEntities)); } } if (dto.PaymentMains != null) { foreach (PaymentMainDto paymentMain in dto.PaymentMains) { entity.PaymentMains.Add(DbEntities.PaymentMain.FromDto(dbContext, paymentMain, dtoEntities)); } } if (dto.PaymentProfiles != null) { foreach (PaymentProfileDto paymentProfile in dto.PaymentProfiles) { entity.PaymentProfiles.Add(DbEntities.PaymentProfile.FromDto(dbContext, paymentProfile, dtoEntities)); } } if (dto.TaxableAmountSums != null) { foreach (TaxableAmountSumDto taxableAmountSum in dto.TaxableAmountSums) { entity.TaxableAmountSums.Add(DbEntities.TaxableAmountSum.FromDto(dbContext, taxableAmountSum, dtoEntities)); } } if (dto.VoluntaryPlanWaiverRequests != null) { foreach (VoluntaryPlanWaiverRequestDto voluntaryPlanWaiverRequest in dto.VoluntaryPlanWaiverRequests) { entity.VoluntaryPlanWaiverRequests.Add(DbEntities.VoluntaryPlanWaiverRequest.FromDto(dbContext, voluntaryPlanWaiverRequest, dtoEntities)); } } if (dto.WageUnitDetails != null) { foreach (WageUnitDetailDto wageUnitDetail in dto.WageUnitDetails) { entity.WageUnitDetails.Add(DbEntities.WageUnitDetail.FromDto(dbContext, wageUnitDetail, dtoEntities)); } } }
/// <summary>Convert from Employer entity to DTO</summary> /// <param name="dbContext">DB Context to use for setting DTO state</param> /// <param name="dto">DTO to use if already created instead of creating new one (can be inherited class instead as opposed to base class)</param> /// <param name="entityDtos">Used internally to track which entities have been converted to DTO's already (to avoid re-converting when circularly referenced)</param> /// <returns>Resultant Employer DTO</returns> public EmployerDto ToDtoDeep(FACTS.Framework.DAL.DbContext dbContext, EmployerDto dto = null, Dictionary <BaseEntity, FACTS.Framework.Dto.BaseDto> entityDtos = null) { entityDtos = entityDtos ?? new Dictionary <BaseEntity, FACTS.Framework.Dto.BaseDto>(); if (entityDtos.ContainsKey(this)) { return((EmployerDto)entityDtos[this]); } dto = ToDto(dto); entityDtos.Add(this, dto); System.Data.Entity.Infrastructure.DbEntityEntry <Employer> entry = dbContext?.Entry(this); dto.IsNew = (entry?.State == EntityState.Added); dto.IsDeleted = (entry?.State == EntityState.Deleted); if (entry?.Collection(x => x.AddressLinks)?.IsLoaded == true) { foreach (AddressLink addressLink in AddressLinks) { dto.AddressLinks.Add(addressLink.ToDtoDeep(dbContext, entityDtos: entityDtos)); } } if (entry?.Collection(x => x.EmployerAccountTransactions)?.IsLoaded == true) { foreach (EmployerAccountTransaction employerAccountTransaction in EmployerAccountTransactions) { dto.EmployerAccountTransactions.Add(employerAccountTransaction.ToDtoDeep(dbContext, entityDtos: entityDtos)); } } if (entry?.Collection(x => x.EmployerContacts)?.IsLoaded == true) { foreach (EmployerContact employerContact in EmployerContacts) { dto.EmployerContacts.Add(employerContact.ToDtoDeep(dbContext, entityDtos: entityDtos)); } } if (entry?.Reference(x => x.EmployerLiability)?.IsLoaded == true) { dto.EmployerLiability = EmployerLiability?.ToDtoDeep(dbContext, entityDtos: entityDtos); } if (entry?.Reference(x => x.EmployerPreference)?.IsLoaded == true) { dto.EmployerPreference = EmployerPreference?.ToDtoDeep(dbContext, entityDtos: entityDtos); } if (entry?.Collection(x => x.EmployerUnits)?.IsLoaded == true) { foreach (EmployerUnit employerUnit in EmployerUnits) { dto.EmployerUnits.Add(employerUnit.ToDtoDeep(dbContext, entityDtos: entityDtos)); } } if (entry?.Collection(x => x.PaymentMains)?.IsLoaded == true) { foreach (PaymentMain paymentMain in PaymentMains) { dto.PaymentMains.Add(paymentMain.ToDtoDeep(dbContext, entityDtos: entityDtos)); } } if (entry?.Collection(x => x.PaymentProfiles)?.IsLoaded == true) { foreach (PaymentProfile paymentProfile in PaymentProfiles) { dto.PaymentProfiles.Add(paymentProfile.ToDtoDeep(dbContext, entityDtos: entityDtos)); } } if (entry?.Collection(x => x.TaxableAmountSums)?.IsLoaded == true) { foreach (TaxableAmountSum taxableAmountSum in TaxableAmountSums) { dto.TaxableAmountSums.Add(taxableAmountSum.ToDtoDeep(dbContext, entityDtos: entityDtos)); } } if (entry?.Collection(x => x.VoluntaryPlanWaiverRequests)?.IsLoaded == true) { foreach (VoluntaryPlanWaiverRequest voluntaryPlanWaiverRequest in VoluntaryPlanWaiverRequests) { dto.VoluntaryPlanWaiverRequests.Add(voluntaryPlanWaiverRequest.ToDtoDeep(dbContext, entityDtos: entityDtos)); } } if (entry?.Collection(x => x.WageUnitDetails)?.IsLoaded == true) { foreach (WageUnitDetail wageUnitDetail in WageUnitDetails) { dto.WageUnitDetails.Add(wageUnitDetail.ToDtoDeep(dbContext, entityDtos: entityDtos)); } } return(dto); }