/// <summary>Convert from EmployerUnit 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 EmployerUnit DTO</returns> public EmployerUnitDto ToDtoDeep(FACTS.Framework.DAL.DbContext dbContext, EmployerUnitDto dto = null, Dictionary <BaseEntity, FACTS.Framework.Dto.BaseDto> entityDtos = null) { entityDtos = entityDtos ?? new Dictionary <BaseEntity, FACTS.Framework.Dto.BaseDto>(); if (entityDtos.ContainsKey(this)) { return((EmployerUnitDto)entityDtos[this]); } dto = ToDto(dto); entityDtos.Add(this, dto); System.Data.Entity.Infrastructure.DbEntityEntry <EmployerUnit> entry = dbContext?.Entry(this); dto.IsNew = (entry?.State == EntityState.Added); dto.IsDeleted = (entry?.State == EntityState.Deleted); if (entry?.Reference(x => x.Employer)?.IsLoaded == true) { dto.Employer = Employer?.ToDtoDeep(dbContext, entityDtos: entityDtos); } if (entry?.Collection(x => x.AddressLinks)?.IsLoaded == true) { foreach (AddressLink addressLink in AddressLinks) { dto.AddressLinks.Add(addressLink.ToDtoDeep(dbContext, entityDtos: entityDtos)); } } return(dto); }
protected static void FromDtoSet(FACTS.Framework.DAL.DbContext dbContext, EmployerUnitDto dto, EmployerUnit entity, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities) { entity.CountyCode = dto.CountyCode; entity.CreateDateTime = dto.CreateDateTime; entity.CreateUserId = dto.CreateUserId; entity.DoingBusinessAsName = dto.DoingBusinessAsName; entity.EmployerId = dto.EmployerId; entity.EmployerUnitSeqNo = dto.EmployerUnitSeqNo; entity.FirstWageDate = dto.FirstWageDate; entity.StatusCode = dto.StatusCode; entity.StatusDate = dto.StatusDate; 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 (dto.AddressLinks != null) { foreach (AddressLinkDto addressLink in dto.AddressLinks) { entity.AddressLinks.Add(DbEntities.AddressLink.FromDto(dbContext, addressLink, dtoEntities)); } } }
public EmployerRegistrationViewModel() { EmployerDto = new EmployerDto() { EmployerLiability = new EmployerLiabilityDto(), EmployerPreference = new EmployerPreferenceDto() }; EmployerContactDto = new EmployerContactDto(); EmployerUnitDto = new EmployerUnitDto(); ListAddressLinkDto = new List <AddressLinkDto>(); }
public EmployerRegistrationViewModel() { EmployerDto = new EmployerDto() { EmployerLiability = new EmployerLiabilityDto(), EmployerPreference = new EmployerPreferenceDto(), IsProfessionalEmployerOrg = false, IsClientOfPEO = false, IsIndividualContractor = false, IsExemptUnderIRS501C3 = false, IsApplyingForREIM = false, IsAcquired = false, IsPresentInMultipleLoc = false }; EmployerContactDto = new EmployerContactDto(); EmployerUnitDto = new EmployerUnitDto(); ListAddressLinkDto = new List <AddressLinkDto> { new AddressLinkDto() }; }
/// <summary> /// Set Pending Fields for EmployerUnitDto /// </summary> /// <param name="employerUnitDto"></param> /// <param name="listAddressLinkDto"></param> /// <returns></returns> private static EmployerUnitDto SetPendingFieldsEmployerUnitDto(EmployerUnitDto employerUnitDto, List <AddressLinkDto> listAddressLinkDto) { string countyCode = "0"; AddressLinkDto physicalAddress = listAddressLinkDto.FirstOrDefault(addressLink => addressLink.AddressTypeCode == LookupTable_AddressType.Physical); employerUnitDto.EmployerUnitSeqNo = 1; employerUnitDto.DoingBusinessAsName = Shared.Utility.StringUtil.ToUpper(employerUnitDto.DoingBusinessAsName); employerUnitDto.StatusCode = LookupTable_EmployerStatus.Active; employerUnitDto.StatusDate = DateTimeUtil.Now; //TODO: when CountyCode is NULL, county code is determined based on the zip code //County zip mapping for WA needs to be populated in the lookup data employerUnitDto.CountyCode = physicalAddress?.Address?.CountyCode ?? countyCode; return(employerUnitDto); }
/// <summary> /// /// </summary> /// <param name="employerUnitDto"></param> /// <returns></returns> static EmployerUnit AddEmployerUnit(EmployerUnitDto employerUnitDto) { string countyCode = "0"; AddressLinkDto physicalAddress = employerUnitDto.Employer.AddressLinks.FirstOrDefault(addressLink => addressLink.AddressTypeCode == LookupTable_AddressType.Physical); EmployerUnit employerUnit = new EmployerUnit { EmployerUnitSeqNo = 1, DoingBusinessAsName = Shared.Utility.StringUtil.ToUpper(employerUnitDto.DoingBusinessAsName), FirstWageDate = employerUnitDto.FirstWageDate, StatusCode = LookupTable_EmployerStatus.Active, StatusDate = DateTimeUtil.Now, //TODO: when CountyCode is NULL, county code is determined based on the zip code //County zip mapping for WA needs to be populated in the lookup data CountyCode = physicalAddress.Address.CountyCode }; return(employerUnit); }
/// <summary>Convert from EmployerUnit 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 EmployerUnit entity</returns> public static EmployerUnit FromDto(FACTS.Framework.DAL.DbContext dbContext, EmployerUnitDto dto, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities = null) { dtoEntities = dtoEntities ?? new Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity>(); if (dtoEntities.ContainsKey(dto)) { return((EmployerUnit)dtoEntities[dto]); } EmployerUnit entity = new EmployerUnit(); dtoEntities.Add(dto, entity); entity.CountyCode = dto.CountyCode; entity.CreateDateTime = dto.CreateDateTime; entity.CreateUserId = dto.CreateUserId; entity.DoingBusinessAsName = dto.DoingBusinessAsName; entity.EmployerId = dto.EmployerId; entity.EmployerUnitSeqNo = dto.EmployerUnitSeqNo; entity.FirstWageDate = dto.FirstWageDate; entity.StatusCode = dto.StatusCode; entity.StatusDate = dto.StatusDate; 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 (dto.AddressLinks != null) { foreach (AddressLinkDto addressLink in dto.AddressLinks) { entity.AddressLinks.Add(DbEntities.AddressLink.FromDto(dbContext, addressLink, dtoEntities)); } } if (dbContext != null) { dbContext.Entry(entity).State = (dto.IsNew ? EntityState.Added : (dto.IsDeleted ? EntityState.Deleted : EntityState.Modified)); } return(entity); }
/// <summary>Convert from EmployerUnit 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 EmployerUnit entity</returns> public static EmployerUnit FromDto(FACTS.Framework.DAL.DbContext dbContext, EmployerUnitDto dto, Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity> dtoEntities = null) { dtoEntities = dtoEntities ?? new Dictionary <FACTS.Framework.Dto.BaseDto, BaseEntity>(); if (dtoEntities.ContainsKey(dto)) { return((EmployerUnit)dtoEntities[dto]); } EmployerUnit entity = new EmployerUnit(); 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 EmployerUnit entity to DTO w/o checking entity state or entity navigation</summary> /// <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> /// <returns>Resultant EmployerUnit DTO</returns> public EmployerUnitDto ToDto(EmployerUnitDto dto = null) { dto = dto ?? new EmployerUnitDto(); dto.IsNew = false; dto.CountyCode = CountyCode; dto.CreateDateTime = CreateDateTime; dto.CreateUserId = CreateUserId; dto.DoingBusinessAsName = DoingBusinessAsName; dto.EmployerId = EmployerId; dto.EmployerUnitSeqNo = EmployerUnitSeqNo; dto.FirstWageDate = FirstWageDate; dto.StatusCode = StatusCode; dto.StatusDate = StatusDate; dto.UpdateDateTime = UpdateDateTime; dto.UpdateNumber = UpdateNumber; dto.UpdateProcess = UpdateProcess; dto.UpdateUserId = UpdateUserId; return(dto); }
/// <summary> /// Set Pending Fields for EmployerDto /// </summary> /// <param name="employerDto"></param> /// <param name="employerUnitDto"></param> /// <returns></returns> private static EmployerDto SetPendingFieldsEmployerDto(EmployerDto employerDto, EmployerUnitDto employerUnitDto) { var employerLiabilityDto = employerDto.EmployerLiability; int liabilityIncurredYear = employerLiabilityDto.LiabilityAmountMetYear.HasValue ? employerLiabilityDto.LiabilityAmountMetYear.Value : 0; int liabilityIncurredQtr = employerLiabilityDto.LiabilityAmountMetYear.HasValue ? Convert.ToInt32(DateUtil.GetQuarterNumber(employerLiabilityDto.LiabilityAmountMetQuarter)) : 0; DateTime?liabilityDate = GetLiabilityDate(liabilityIncurredYear, liabilityIncurredQtr, employerDto.EntityTypeCode, employerUnitDto.FirstWageDate); string paymentMehtodCode = GetPaymentMethod(); employerDto.RegistrationDate = DateTimeUtil.Now; employerDto.LiabilityDate = liabilityDate; employerDto.LiabilityIncurredDate = liabilityDate; employerDto.ReportMethodCode = paymentMehtodCode; employerDto.SubjectivityCode = GetSubjectivityCode(paymentMehtodCode); employerDto.StatusCode = LookupTable_EmployerStatus.Active; employerDto.StatusDate = DateTimeUtil.Now; return(employerDto); }