Skip to content

Instantly share code, notes, and snippets.

@serialseb
Created July 16, 2014 10:41
Show Gist options
  • Save serialseb/3d607b1b049353658049 to your computer and use it in GitHub Desktop.
Save serialseb/3d607b1b049353658049 to your computer and use it in GitHub Desktop.
Projector
using System;
using System.Globalization;
using System.Linq;
using CTM.Common.PafAddress;
using CTM.Home.Common.Domain;
using CTM.Home.Common.ValueTypes;
using CTM.Home.Domain.Concepts;
using CTM.Home.Domain.Events;
using CTM.Home.ViewModels;
using TestNewProjections;
namespace CTM.Home.Projections.Projections
{
public class RiskViewProjection : IProject<RiskViewModel>.WithBuilder
{
readonly IAmAViewModelMigrator<ContactDetailsViewModel> contactDetailsViewModelMigrator;
//ContentCoverViewModel contentCoverViewModel;
public RiskViewProjection(IAmAViewModelMigrator<ContactDetailsViewModel> contactDetailsViewModelMigrator)
{
this.contactDetailsViewModelMigrator = contactDetailsViewModelMigrator;
}
public void Build(IEventHandlerBuilder<RiskViewModel> builder)
{
builder
.On<PropertyDetailsSpecified>(Handle)
.On<RebuildCostSpecified>(Handle)
.On<RebuildCostEstimated>(Handle)
.On<RebuildCostEstimationFailed>(Handle)
.On<PolicyDetailsSpecified>(Handle)
.On<PolicyHolderDetailsSpecified>(Handle)
.On<JointPolicyHolderDetailsSpecified>(Handle)
.On<BuildingConstructionSpecified>(Handle)
.On<PropertySecurityDetailsSpecified>(Handle)
.On<ResidentsDetailsSpecified>(Handle)
.On<RiskCreated>(Handle)
.On<TermsAndConditionsAccepted>(Handle)
.On<ContactDetailsSpecified>(Handle)
.On<LocksOnPropertySpecified>(Handle)
.On<PreviousClaimSpecified>(Handle)
.On<PreviousClaimModified>(Handle)
.On<PreviousClaimRemoved>(Handle)
.On<DefaultContentsCoverCalculated>(Handle)
.On<ContentsCoverDetailsSpecified>(Handle)
.On<PersonalPossessionCoverDetailsSpecified>(Handle)
.On<PreviousClaimsEarliestDateCalculated>(Handle)
.On<ChildMindingOccupationSpecified>(Handle)
.On<ChildrenMindedAtInsuredProperty>(Handle)
.On<ChildMindingOccupationNotSpecified>(Handle)
.On<ContentItemSpecified>(Handle)
.On<ContentItemModified>(Handle)
.On<SpecifiedItemDeleted>(Handle)
.On<BikeAdded>(Handle)
.On<BikeUpdated>(Handle)
.On<BikeDeleted>(Handle)
.On<BuildingVoluntaryExcessChanged>(Handle)
.On<ContentsVoluntaryExcessChanged>(Handle)
.On<CoverTypeModified>(Handle)
.On<NumberOfBedroomsOfPropertyHasChanged>(Handle)
.On<BuildingsAccidentalDamageChanged>(Handle)
.On<ContentsAccidentalDamageChanged>(Handle)
.On<ResetCoverTypeModification>(Handle)
.On<PolicyStartDateChanged>(Handle)
.On<CommunicationPreferencesSpecified>(Handle)
.On<RiskRetrieved>(Handle)
.On<SubmittedForQuoting>(Handle)
.On<RiskCopiedFromLegacy>(Handle);
}
static string DefaultCoverTypeForRiskCreatedEventsBeforeEventVersion3(RiskCreated anEvent)
{
return string.IsNullOrWhiteSpace(anEvent.CoverType)
? CoverType.BuildingsAndContents.Value
: anEvent.CoverType;
}
void Handle(IStore<RiskViewModel> store, ChildrenMindedAtInsuredProperty anEvent)
{
store.Value.Residents.ChildMinding.ChildMindingRegistration = anEvent.AreTheChildrenRegistered;
store.Value.Residents.ChildMinding.ChildMindingNumberOfChildren = anEvent.NumberOfChildren;
store.Value.Residents.ChildMinding.ChildMindingProperty = anEvent.ChildMindingProperty;
}
void Handle(IStore<RiskViewModel> store, RebuildCostEstimated anEvent)
{
store.Value.RebuildCost.RebuildCostInfoFromBCIS =
new RebuildCost(anEvent.ExpectedTotal,
anEvent.MaximumTotal,
anEvent.MinimumTotal);
}
void Handle(IStore<RiskViewModel> store, RebuildCostEstimationFailed anEvent)
{
store.Value.RebuildCost.RebuildCostInfoFromBCIS = RebuildCost.NotSuccessful();
}
void Handle(IStore<RiskViewModel> store, RiskCreated anEvent)
{
store.Value.YourPolicy = new YourPolicyViewModel
{
CoverType = DefaultCoverTypeForRiskCreatedEventsBeforeEventVersion3(anEvent)
};
}
void Handle(IStore<RiskViewModel> store, LocksOnPropertySpecified anEvent)
{
store.Value.Locks = new LocksOnYourPropertyViewModel
{
LocksOnMainDoor = anEvent.LocksOnMainDoor,
HasExternalSlidingDoors = anEvent.HasExternalSlidingDoors,
LocksOnExternalSlidingDoors = anEvent.LocksOnExternalSlidingDoors,
HasOtherExternalDoors = anEvent.HasOtherExternalDoors,
LocksOnOtherExternalDoors = anEvent.LocksOnOtherExternalDoors,
};
}
void Handle(IStore<RiskViewModel> store, PolicyHolderDetailsSpecified anEvent)
{
store.Value.PersonalDetails = store.Value.PersonalDetails ?? new PersonalDetailsViewModel();
store.Value.PersonalDetails.JointPolicyHolderOption = "Single";
store.Value.PersonalDetails.PolicyHolder.Title = anEvent.Title;
store.Value.PersonalDetails.PolicyHolder.FirstName = anEvent.FirstName;
store.Value.PersonalDetails.PolicyHolder.Surname = anEvent.Surname;
store.Value.PersonalDetails.PolicyHolder.BirthDay =
anEvent.DateOfBirth.Day.ToString(CultureInfo.InvariantCulture);
store.Value.PersonalDetails.PolicyHolder.BirthMonth =
anEvent.DateOfBirth.Month.ToString(CultureInfo.InvariantCulture);
store.Value.PersonalDetails.PolicyHolder.BirthYear =
anEvent.DateOfBirth.Year.ToString(CultureInfo.InvariantCulture);
store.Value.PersonalDetails.PolicyHolder.MaritalStatus = anEvent.MaritalStatus;
store.Value.PersonalDetails.PolicyHolder.EmploymentStatus = anEvent.EmploymentStatus;
store.Value.PersonalDetails.PolicyHolder.BusinessType = anEvent.BusinessType;
store.Value.PersonalDetails.PolicyHolder.BusinessCode = anEvent.BusinessCode;
store.Value.PersonalDetails.PolicyHolder.OccupationCode = anEvent.OccupationCode;
store.Value.PersonalDetails.PolicyHolder.OccupationType = anEvent.OccupationType;
store.Value.PersonalDetails.PolicyHolder.SecondaryOccupationCode = anEvent.SecondaryOccupationCode;
store.Value.PersonalDetails.PolicyHolder.SecondaryOccupationType = anEvent.SecondaryOccupationType;
store.Value.PersonalDetails.PolicyHolder.HasSecondaryOccupation = anEvent.HasSecondaryOccupation;
store.Value.PersonalDetails.PolicyHolder.SecondaryBusinessCode = anEvent.SecondaryBusinessCode;
store.Value.PersonalDetails.PolicyHolder.SecondaryBusinessType = anEvent.SecondaryBusinessType;
store.Value.PersonalDetails.PolicyHolder.SelfEmployed = anEvent.SelfEmployed;
}
void Handle(IStore<RiskViewModel> store, ChildMindingOccupationNotSpecified anEvent)
{
store.Value.Residents = store.Value.Residents ?? new ResidentsDetailsViewModel();
store.Value.Residents.ChildMinding = store.Value.Residents.ChildMinding ??
new ChildMinderViewModel();
store.Value.Residents.ChildMinding.ShowChildMindingSection = false;
}
void Handle(IStore<RiskViewModel> store, ChildMindingOccupationSpecified anEvent)
{
store.Value.Residents = store.Value.Residents ?? new ResidentsDetailsViewModel();
store.Value.Residents.ChildMinding = store.Value.Residents.ChildMinding ??
new ChildMinderViewModel();
store.Value.Residents.ChildMinding.ShowChildMindingSection = true;
}
void Handle(IStore<RiskViewModel> store, PolicyStartDateChanged anEvent)
{
store.Value.YourPolicy.PolicyStartDate = anEvent.NewPolicyStartDate;
}
void Handle(IStore<RiskViewModel> store, JointPolicyHolderDetailsSpecified anEvent)
{
var model = store.Value;
model.PersonalDetails = model.PersonalDetails ?? new PersonalDetailsViewModel();
model.PersonalDetails.JointPolicyHolderOption = "Joint";
model.PersonalDetails.JointPolicyHolder.Title = anEvent.Title;
model.PersonalDetails.JointPolicyHolder.FirstName = anEvent.FirstName;
model.PersonalDetails.JointPolicyHolder.Surname = anEvent.Surname;
model.PersonalDetails.JointPolicyHolder.BirthDay =
anEvent.DateOfBirth.Day.ToString(CultureInfo.InvariantCulture);
model.PersonalDetails.JointPolicyHolder.BirthMonth =
anEvent.DateOfBirth.Month.ToString(CultureInfo.InvariantCulture);
model.PersonalDetails.JointPolicyHolder.BirthYear =
anEvent.DateOfBirth.Year.ToString(CultureInfo.InvariantCulture);
model.PersonalDetails.JointPolicyHolder.MaritalStatus = anEvent.MaritalStatus;
model.PersonalDetails.JointPolicyHolder.EmploymentStatus = anEvent.EmploymentStatus;
model.PersonalDetails.JointPolicyHolder.SelfEmployed =
anEvent.SelfEmployed;
model.PersonalDetails.JointPolicyHolderRelationshipStatus = anEvent.RelationshpStatus;
model.PersonalDetails.JointPolicyHolder.OccupationCode = anEvent.OccupationCode;
model.PersonalDetails.JointPolicyHolder.OccupationType = anEvent.OccupationType;
model.PersonalDetails.JointPolicyHolder.BusinessCode = anEvent.BusinessCode;
model.PersonalDetails.JointPolicyHolder.BusinessType = anEvent.BusinessType;
model.PersonalDetails.JointPolicyHolder.SecondaryOccupationCode =
anEvent.SecondaryOccupationCode;
model.PersonalDetails.JointPolicyHolder.SecondaryOccupationType =
anEvent.SecondaryOccupationType;
model.PersonalDetails.JointPolicyHolder.SecondaryBusinessCode = anEvent.SecondaryBusinessCode;
model.PersonalDetails.JointPolicyHolder.SecondaryBusinessType = anEvent.SecondaryBusinessType;
model.PersonalDetails.JointPolicyHolder.HasSecondaryOccupation = anEvent.HasSecondaryOccupation;
}
void Handle(IStore<RiskViewModel> store, PropertyDetailsSpecified anEvent)
{
var propertyDetails = new PropertyDetailsViewModel
{
NumOfBathrooms = anEvent.NumberOfRooms.Bathrooms.ToString(CultureInfo.InvariantCulture),
NumOfBedrooms = anEvent.NumberOfRooms.Bedrooms.ToString(CultureInfo.InvariantCulture),
NumOfOtherRooms = anEvent.NumberOfRooms.OtherRooms.ToString(CultureInfo.InvariantCulture),
NumOfReceptionRooms =
anEvent.NumberOfRooms.ReceptionRooms.ToString(CultureInfo.InvariantCulture),
OwnershipStatus = anEvent.OwnershipStatus.Value,
PropertySubType = anEvent.PropertySubType,
PropertyType = anEvent.PropertyType.Value,
TenantType = anEvent.TennantType,
YearBuilt = anEvent.YearBuilt.Year.ToString(CultureInfo.InvariantCulture),
};
store.Value.Property = propertyDetails;
store.Value.BuildingConstruction.RequiresRoofConstructionQuestions =
Property.HasRoof(store.Value.Property.PropertyType, store.Value.Property.PropertySubType);
var propertySecurity = store.Value.Security ??
new PropertySecurityDetailsViewModel
();
propertySecurity.CanHaveSeparateLockableEntrance =
anEvent.SeparateLockableProperty;
if (store.Value.RebuildCost == null) store.Value.RebuildCost = new RebuildCostViewModel();
store.Value.RebuildCost.PropertyType = anEvent.PropertyType.Value;
store.Value.RebuildCost.PropertySubType = anEvent.PropertySubType;
store.Value.RebuildCost.PropertyYearBuilt = anEvent.YearBuilt.Year.ToString();
store.Value.RebuildCost.TotalNumberOfRoomsExcludingBathrooms =
anEvent.NumberOfRooms.TotalExcludingBathrooms();
store.Value.RebuildCost.NumberOfBedrooms = anEvent.NumberOfRooms.Bedrooms;
}
void Handle(IStore<RiskViewModel> store, PolicyDetailsSpecified anEvent)
{
var address = new PostOfficeAddress
{
AbbreviatedOptionalCounty = anEvent.Address.AbbreviatedOptionalCounty,
AdministrativeCounty = anEvent.Address.AdministrativeCounty,
AbbreviatedPostalCounty = anEvent.Address.AbbreviatedPostalCounty,
Building = anEvent.Address.Building,
DPS = anEvent.Address.DPS,
Department = anEvent.Address.Department,
DependentLocality = anEvent.Address.DependentLocality,
DependentThoroughfare = anEvent.Address.DependentThoroughfare,
DoubleDependentLocality = anEvent.Address.DoubleDependentLocality,
Number = anEvent.Address.Number,
OptionalCounty = anEvent.Address.OptionalCounty,
OrganisationName = anEvent.Address.OrganisationName,
PostalCounty = anEvent.Address.PostalCounty,
SubBuilding = anEvent.Address.SubBuilding,
Thoroughfare = anEvent.Address.Thoroughfare,
Town = anEvent.Address.Town,
TraditionalCounty = anEvent.Address.TraditionalCounty,
Postcode = anEvent.Address.Postcode
};
var model = store.Value;
model.YourPolicy = new YourPolicyViewModel
{
PolicyStartDate = anEvent.PolicyStartDate,
CoverType = anEvent.CoverType.Value,
AddressModel = new AddressViewModel
{
SelectedAddress = new Address(address, FormattedAddress.From(address)),
IsAddressManuallyEntered = anEvent.IsAddressManuallyEntered
}
};
if (model.RebuildCost == null)
model.RebuildCost = new RebuildCostViewModel();
model.RebuildCost.PropertyPostCode = anEvent.Address.Postcode;
}
void Handle(IStore<RiskViewModel> store, PreviousClaimsEarliestDateCalculated anEvent)
{
store.Value.Residents.EarliestPreviousClaimDate =
anEvent.EarliestDate.ToString("MMMM dd, yyyy");
}
void Handle(IStore<RiskViewModel> store, BuildingConstructionSpecified anEvent)
{
store.Value.BuildingConstruction = new BuildingConstructionViewModel
{
RoofConstruction = anEvent.RoofType.Key,
ExternalWallType = anEvent.ExternalWalls,
PropertyListedStatus = anEvent.PropertyListed,
MoreThanHalfRoofIsFlat = anEvent.IsMoreThanHalfOfRoofFlat,
IsWithin400MOfWater = anEvent.IsCloseToWater,
PropertyBusinessUse = anEvent.BusinessUse,
IsInGoodStateOfRepair = anEvent.InGoodStateRepair,
FlatRoofLastResurfacedYear = anEvent.RoofLastCovered,
HasOperationalSmokeDetectors = anEvent.HasOperationalSmokeDetectors,
RequiresRoofConstructionQuestions =
Property.HasRoof(store.Value.Property.PropertyType,
store.Value.Property.PropertySubType)
};
if (store.Value.RebuildCost == null)
store.Value.RebuildCost = new RebuildCostViewModel();
store.Value.RebuildCost.PropertyExternalWallType = anEvent.ExternalWalls;
store.Value.RebuildCost.PropertyRoofConstruction = anEvent.RoofType.Key;
}
void Handle(IStore<RiskViewModel> store, TermsAndConditionsAccepted anEvent)
{
store.Value.TermsAndConditionsAccepted = true;
}
void Handle(IStore<RiskViewModel> store, ResidentsDetailsSpecified anEvent)
{
store.Value.Residents.AnyResidentHasBeenBankrupt = anEvent.HasbeenBankrupt;
store.Value.Residents.AnyResidentHasInsuranceRefused = anEvent.HasInsuranceRefused;
store.Value.Residents.SelectedResidentsType = anEvent.ResidentsType.Value;
store.Value.Residents.SelectedOccupancyStatus = anEvent.OccupanyStatus;
store.Value.Residents.SelectedDurationFosterChildrenInYourCare =
anEvent.DurationOfFosterCare.Value;
store.Value.Residents.SelectedNumOfFosterChildren =
anEvent.NumberOfFosterChildren.ToString(CultureInfo.InvariantCulture);
store.Value.Residents.SelectedNumOfNonFamilyMembers =
anEvent.NumberOfNonFamilyMembers.ToString(CultureInfo.InvariantCulture);
store.Value.Residents.AnyResidentHasConvictions = anEvent.HasConviction;
store.Value.Residents.EmptyFor45Days = anEvent.EmptyFor45Days;
store.Value.Residents.DaysLeftEmpty = anEvent.ConsecutiveDaysEmpty;
store.Value.Residents.SelectedUnoccupiedForHowLong = anEvent.UnnoccupiedForHowLong;
store.Value.Residents.SelectedUnoccupiedReason = anEvent.UnnoccupiedReason;
store.Value.Residents.AnyResidentHasInsuranceClaims =
anEvent.AnyResidentHasInsuranceClaims;
}
void Handle(IStore<RiskViewModel> store, PropertySecurityDetailsSpecified anEvent)
{
store.Value.Security.HasKeyOperatedLocksOnWindows = anEvent.HasKeyOperatedLocksOnWindows;
store.Value.Security.HasSeparateLockableEntrance = anEvent.HasSeparateLockableEntrance;
store.Value.Security.HasNeighbourhoodWatch = anEvent.HasNeighbourhoodWatch;
store.Value.Security.HasLockableSafeFitted = anEvent.HasLockableSafeFitted;
store.Value.Security.IsOccupiedBetween9And5 = anEvent.IsOccupiedBetween9And5;
store.Value.Security.HasBurglarAlarmFitted = anEvent.HasBurglarAlarmFitted;
store.Value.Security.ContentsInsuranceYears = anEvent.ContentsInsuranceYears;
store.Value.Security.AlarmMaintenanceStatus = anEvent.AlarmMaintenanceStatus;
}
void Handle(IStore<RiskViewModel> store, RebuildCostSpecified anEvent)
{
store.Value.RebuildCost.RebuildCost = anEvent.RebuildCost.ToString(CultureInfo.InvariantCulture);
store.Value.RebuildCost.SufferedFromSubsidence = anEvent.HasSufferedFromSubsidence;
store.Value.RebuildCost.CracksOnExternalWalls = anEvent.HasCracksOnExternalWalls;
store.Value.RebuildCost.UnderpinningorStructuralSupport = anEvent.HasUndepinningOrStructuralSupport;
store.Value.RebuildCost.ContinuesToSufferDamage = anEvent.ContinuesToSufferDamage;
store.Value.RebuildCost.YearsBuildingInsuranceHeld = anEvent.YearsBuildingsInsuranceHeld;
}
void Handle(IStore<RiskViewModel> store, RiskRetrieved anEvent)
{
store.Value.ContactDetails =
contactDetailsViewModelMigrator.Migrate(store.Value.ContactDetails).ToMigrationVersion(2);
}
void Handle(IStore<RiskViewModel> store, ContactDetailsSpecified anEvent)
{
var contactDetailsSpecifiedEvent =
new ContactDetailsSpecifiedEventMigrator().Migrate(anEvent).ToMigratedVersion(2);
var contactDetailsViewModel = new ContactDetailsViewModel
{
ContactMeByEmail = contactDetailsSpecifiedEvent.EmailOptionSelected,
ContactMeByTelephone = contactDetailsSpecifiedEvent.TelephoneOptionSelected,
ContactMeByPost = contactDetailsSpecifiedEvent.PostOptionSelected,
ContactMeByTextSms = contactDetailsSpecifiedEvent.TextOptionSelected,
EmailAddress = contactDetailsSpecifiedEvent.EmailAddress.ToLower(),
TelephoneNumber = contactDetailsSpecifiedEvent.TelephoneNumber,
InsuredAddress = contactDetailsSpecifiedEvent.InsuredAddress,
ContactAddress = contactDetailsSpecifiedEvent.ContactAddress,
ReasonForAlternateAddress = contactDetailsSpecifiedEvent.ReasonForAlternateAddress,
UseInsuredAddress = contactDetailsSpecifiedEvent.UseInsuredAddress,
OutBoundingOptIn = contactDetailsSpecifiedEvent.OutBoundingOptIn,
AddressModel = new AddressViewModel
{
SelectedAddress = new Address(anEvent.ContactAddress, FormattedAddress.From(anEvent.ContactAddress)),
IsAddressManuallyEntered = anEvent.IsAddressManuallyEntered
}
};
store.Value.ContactDetails = contactDetailsViewModel;
}
void Handle(IStore<RiskViewModel> store, CommunicationPreferencesSpecified preferences)
{
store.Value.ContactDetails.ContactMeByEmail = preferences.EmailOptionSelected;
store.Value.ContactDetails.ContactMeByTelephone = preferences.TelephoneOptionSelected;
store.Value.ContactDetails.ContactMeByPost = preferences.PostOptionSelected;
store.Value.ContactDetails.ContactMeByTextSms = preferences.TextOptionSelected;
}
void Handle(IStore<RiskViewModel> store, DefaultContentsCoverCalculated anEvent)
{
var contentCoverViewModel = store.Value.ContentsCover
?? ( store.Value.ContentsCover = new ContentCoverViewModel());
contentCoverViewModel.DefaultContentCover =
anEvent.DefaultContentsAmount.ToString(CultureInfo.InvariantCulture);
contentCoverViewModel.HighRiskItemTotalValue =
anEvent.TotalHighRiskItemsValue.ToString(CultureInfo.InvariantCulture);
contentCoverViewModel.MostExpensiveHighRiskItem =
anEvent.MostExpensiveHighRiskItemValue.ToString(CultureInfo.InvariantCulture);
}
void Handle(IStore<RiskViewModel> store, ContentsCoverDetailsSpecified anEvent)
{
var contentCoverViewModel = store.Value.ContentsCover
?? (store.Value.ContentsCover = new ContentCoverViewModel());
contentCoverViewModel.ContentCover =
anEvent.ContentsCoverValue.ToString(CultureInfo.InvariantCulture);
contentCoverViewModel.HighRiskItemTotalValue =
anEvent.TotalValueOfHighRiskItems.ToString(CultureInfo.InvariantCulture);
contentCoverViewModel.MostExpensiveHighRiskItem =
anEvent.MostExpensiveHighRiskItem.ToString(CultureInfo.InvariantCulture);
contentCoverViewModel.HasContentsSpecifiedItems = anEvent.HasContentsSpecifiedItems;
contentCoverViewModel.HasContentsSpecifiedBikes = anEvent.HasBikes;
contentCoverViewModel.UserHasEditedContentsCoverAmountsManually =
anEvent.HasEditedContentsCoverPreviously;
}
void Handle(IStore<RiskViewModel> store, NumberOfBedroomsOfPropertyHasChanged anEvent)
{
var contentCoverViewModel = store.Value.ContentsCover
?? (store.Value.ContentsCover = new ContentCoverViewModel());
contentCoverViewModel.DefaultContentCover =
anEvent.DefaultContentsAmount.ToString(CultureInfo.InvariantCulture);
}
void Handle(IStore<RiskViewModel> store, PreviousClaimSpecified anEvent)
{
var claim = new PreviousClaimViewModel(anEvent.IncidentCause,
anEvent.ClaimType,
anEvent.ClaimDate.Month.ToString(CultureInfo.InvariantCulture),
anEvent.ClaimDate.Year.ToString(CultureInfo.InvariantCulture),
anEvent.DamageAmount.ToString(CultureInfo.InvariantCulture),
anEvent.IncidentOccuredAtThisProperty,
anEvent.NoDamage,
anEvent.ClaimId);
store.Value.Residents.PreviousClaims.Add(claim);
}
void Handle(IStore<RiskViewModel> store, PreviousClaimModified anEvent)
{
var existingPreviousClaim =
store.Value.Residents.PreviousClaims.Single(
clm => clm.ClaimId.Equals(anEvent.ClaimId));
existingPreviousClaim.IncidentCause = anEvent.IncidentCause;
existingPreviousClaim.ClaimType = anEvent.ClaimType;
existingPreviousClaim.ClaimAmount = anEvent.DamageAmount.ToString(CultureInfo.InvariantCulture);
existingPreviousClaim.NoDamage = anEvent.NoDamage;
existingPreviousClaim.IncidentAtThisProperty =
anEvent.IncidentOccuredAtThisProperty;
existingPreviousClaim.ClaimMonth =
anEvent.ClaimDate.Month.ToString(CultureInfo.InvariantCulture);
existingPreviousClaim.ClaimYear = anEvent.ClaimDate.Year.ToString(CultureInfo.InvariantCulture);
}
void Handle(IStore<RiskViewModel> store, PreviousClaimRemoved anEvent)
{
store.Value.Residents.PreviousClaims.RemoveAll(_ => _.ClaimId.Equals(anEvent.ClaimId));
}
void Handle(IStore<RiskViewModel> store, ContentItemSpecified anEvent)
{
var specifiedItem = new SpecifiedItemViewModel
{
Type = anEvent.ItemType,
Description = anEvent.ItemDescription,
Value = anEvent.ItemValue.ToString(CultureInfo.InvariantCulture),
ItemId = anEvent.ItemId.ToString()
};
store.Value.ContentsCover.SpecifiedItems.Add(specifiedItem);
}
void Handle(IStore<RiskViewModel> store, ContentItemModified anEvent)
{
var specifiedItemViewModel =
store.Value.ContentsCover.SpecifiedItems.First(x => x.ItemId.Equals(anEvent.ItemId.ToString()));
specifiedItemViewModel.Description = anEvent.ItemDescription;
specifiedItemViewModel.Value = anEvent.ItemValue.ToString(CultureInfo.InvariantCulture);
specifiedItemViewModel.Type = anEvent.ItemType;
}
void Handle(IStore<RiskViewModel> store, SpecifiedItemDeleted anEvent)
{
store.Value.ContentsCover.SpecifiedItems.RemoveAll(
specifiedItem =>
specifiedItem.ItemId.Equals(anEvent.SpecifiedItemId));
}
void Handle(IStore<RiskViewModel> store, BikeAdded anEvent)
{
var specifiedBike = new BikeViewModel
{
Description = anEvent.BikeDescription,
Value = anEvent.BikeValue.ToString(),
ItemId = anEvent.BikeId.ToString()
};
store.Value.ContentsCover.SpecifiedBikes.Add(specifiedBike);
}
void Handle(IStore<RiskViewModel> store, BikeDeleted anEvent)
{
store.Value.ContentsCover.SpecifiedBikes
.RemoveAll(bike => bike.ItemId == anEvent.BikeId.ToString());
}
void Handle(IStore<RiskViewModel> store, BikeUpdated anEvent)
{
var matchingBike =
store.Value.ContentsCover.SpecifiedBikes.SingleOrDefault(_ => _.ItemId == anEvent.BikeId.ToString());
if (matchingBike != null)
{
matchingBike.Value = anEvent.BikeValue.ToString();
matchingBike.Description = anEvent.BikeDescription;
}
;
}
void Handle(IStore<RiskViewModel> store, PersonalPossessionCoverDetailsSpecified anEvent)
{
store.Value.ContentsCover.HasPersonalPossessions = anEvent.HasPersonalPossessionsCover;
store.Value.ContentsCover.PersonalPossessionsCoverAmount =
anEvent.PersonalPossessionsCoverAmount.ToString();
}
void Handle(IStore<RiskViewModel> store, BuildingVoluntaryExcessChanged anEvent)
{
store.Value.RebuildCost.Excess = anEvent.Excess;
}
void Handle(IStore<RiskViewModel> store, ContentsVoluntaryExcessChanged anEvent)
{
store.Value.ContentsCover.Excess = anEvent.Excess;
}
void Handle(IStore<RiskViewModel> store, CoverTypeModified anEvent)
{
store.Value.YourPolicy.CoverType = anEvent.CoverType.Value;
}
void Handle(IStore<RiskViewModel> store, ContentsAccidentalDamageChanged anEvent)
{
store.Value.ContentsCover.AccidentalDamage = anEvent.Value;
}
void Handle(IStore<RiskViewModel> store, BuildingsAccidentalDamageChanged anEvent)
{
store.Value.RebuildCost.AccidentalDamage = anEvent.Value;
}
void Handle(IStore<RiskViewModel> store, ResetCoverTypeModification anEvent)
{
store.Value.YourPolicy.CoverType = anEvent.CoverTypeToresetTo.Value;
}
void Handle(IStore<RiskViewModel> store, SubmittedForQuoting anEvent)
{
store.Value.SubmittedForQuoting = new SubmittedForQuotingModel(anEvent.SubmittedAt,
anEvent.RiskVersionWhenSubmitted);
}
void Handle(IStore<RiskViewModel> store, RiskCopiedFromLegacy anEvent)
{
store.Value.RiskWasCopiedFromLegacy = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment