public List <Guid> MapClaim(IOrganizationService svc, MappedRow mappedRow, BordereauTemplate template, BordereauProcess bxProcess) { ThrowIf.Argument.IsNull(svc, "svc"); ThrowIf.Argument.IsNull(mappedRow, "mappedRow"); ThrowIf.Argument.IsNull(template, "template"); ThrowIf.Argument.IsNull(bxProcess, "bxProcess"); Guid createdClaimId = Guid.Empty; List <Guid> createdClaim = new List <Guid>(); try { //Get the template columns var templateColumns = template.TemplateColumns.ToArray(); var country = bxProcess.CountryRef; //Get the distinct claim orders that will differentiate between multiple claims var retreievedClaimOrders = templateColumns .Where(c => c.ClaimOrder != null) .Select(c => c.ClaimOrder) .Distinct(); var order = mappedRow.Attributes .ForEntity("new_claim") .Where(c => c.TemplateColumn.ClaimOrder != null) .Select(c => c.TemplateColumn.ClaimOrder) .Distinct(); //Get all the common fields between all claims var claimAttributeValue = mappedRow.Attributes .ForEntity("new_claim") .ForClaimOrder(null); mapAttribute.claimStatus = mappedRow.Attributes .ForAttribute("statuscode") .FirstOrDefault().AsOptionSet(); CheckClaimAttributes(svc, mappedRow); foreach (var claimOrder in retreievedClaimOrders) { #region Claim //Get the fileds based on the Claim Order var claimValueBasedOnClaimOrder = mappedRow.Attributes .ForEntity("new_claim") .ForClaimOrder(claimOrder); var reserveFieldRowValue = claimValueBasedOnClaimOrder .ForAttribute("new_reserve") .FirstOrDefault().AsDecimal(); var peril = claimValueBasedOnClaimOrder .ForAttribute("new_peril1") .FirstOrDefault().AsString(); var subPeril = claimValueBasedOnClaimOrder .ForAttribute("new_subperil") .FirstOrDefault().AsString(); mapAttribute.excess = claimValueBasedOnClaimOrder .ForAttribute("new_policyexcess") .FirstOrDefault().AsDecimal(); //If reserve field is empty we dont create a claim //if (peril != null && peril != "" && subPeril != null && subPeril != "") if (subPeril != null && subPeril != "") { if (reserveFieldRowValue != null && reserveFieldRowValue > 0) { //GetClaimValues(svc, mappedRow, claimOrder); mapAttribute.Reserve = reserveFieldRowValue; if (claimValueBasedOnClaimOrder.Where(c => c.AttributeName == "new_claimedamount").Select(c => c.Value).FirstOrDefault() != null) { mapAttribute.ClaimedAmount = claimValueBasedOnClaimOrder .ForAttribute("new_claimedamount") .FirstOrDefault() .AsDecimal(); } //Get the broker claim reference var claimRefValue = mappedRow.Attributes .ForEntity("new_claim") .ForAttribute("new_claimreference") .FirstOrDefault().AsString(); mapAttribute.claimFolderReferenceValue = mappedRow.Attributes .ForEntity("new_claim") .ForAttribute("new_claimreference") .FirstOrDefault().AsString(); mapAttribute.brokerId = bxProcess.BrokerRef.Id; mapAttribute.bxprocessId = bxProcess.Id; mapAttribute.lossTypeDescription = claimValueBasedOnClaimOrder .ForAttribute("new_losstypedescription") .FirstOrDefault().AsString(); mapAttribute.BrokerClaimReference = claimAttributeValue .ForAttribute("new_claimreference") .FirstOrDefault().AsString(); var riskSubClass = mappedRow.Attributes.ForEntity("new_claim").ForClaimOrder(claimOrder).ForAttribute("new_insuredrisk").FirstOrDefault(); //Map the claim fields to be imported Claim claim = new Claim(svc); if (riskSubClass.Value != "Buildings and Contents") { GetClaimValues(svc, mappedRow, claimOrder, riskSubClass.Value); claim.CreateOrUpdateClaim(mapAttribute); } else { GetClaimValues(svc, mappedRow, claimOrder, "Buildings"); claim.CreateOrUpdateClaim(mapAttribute); GetClaimValues(svc, mappedRow, claimOrder, "Contents"); claim.CreateOrUpdateClaim(mapAttribute); //continue; } //createdClaimId = claim.CreateOrUpdateClaim(); //if (createdClaimId != Guid.Empty) // createdClaim.Add(createdClaimId); #endregion Claim #region Payment //Get the payment fields and map ClaimPayment payment = new ClaimPayment(svc, mappedRow, country, claimOrder); payment.CreateOrUpdatePayment(createdClaimId, mapAttribute.policy.FirstOrDefault()); if (mapAttribute.claimStatus.Value == 100000001) { payment.UpdateClaimPaymentStatus(createdClaimId); } #endregion Payment #region Recovery ClaimRecovery recovery = new ClaimRecovery(svc, mappedRow, country, claimOrder); recovery.CreateOrUpdateRecovery(createdClaimId, mapAttribute.policy.FirstOrDefault()); if (mapAttribute.claimStatus.Value == 100000001) { recovery.UpdateClaimRecoveryStatus(createdClaimId); //payment.UpdateClaimPaymentStatus(createdClaimId); } #endregion } } } #region RoleInClaim //var retreievedRoleTypeOrder = templateColumns // .Where(c => c.ClaimOrder == claimOrder && c.ClaimRoleTypeOrder != null) // .Select(c => c.ClaimRoleTypeOrder).Distinct(); var retreievedRoleTypeOrder = templateColumns .Where(c => c.ClaimRoleTypeOrder != null) .Select(c => c.ClaimRoleTypeOrder).Distinct(); Guid createdVehicleId = Guid.Empty; Entity roleInClaim = null; foreach (var roleTypeOrder in retreievedRoleTypeOrder) { //var allRoleAttributes = mappedRow.Attributes.ForClaimOrder(claimOrder).ForRoleNumber(roleTypeOrder); var allRoleAttributes = mappedRow.Attributes.ForRoleNumber(roleTypeOrder); var contactFirstname = allRoleAttributes.ForAttribute("firstname").FirstOrDefault().AsString(); var contactLastName = allRoleAttributes.ForAttribute("lastname").FirstOrDefault().AsString(); if (contactFirstname != null && contactLastName != null) { roleInClaim = CreateRoleInClaim(svc, allRoleAttributes, createdClaimId, country); } var riskClass = bxProcess.RiskClassRef.Name; if (riskClass.ToLower() == "vehicle") { var check = allRoleAttributes.Where(c => c.AttributeName == "new_registrationnumber").FirstOrDefault(); if (check != null) { var vehicleRegistrationNo = allRoleAttributes.ForAttribute("new_registrationnumber").FirstOrDefault().AsString(); if (vehicleRegistrationNo != null) { createdVehicleId = CreateVehicle(svc, allRoleAttributes, createdClaimId); } if (createdVehicleId != Guid.Empty) { roleInClaim["new_vehicleid"] = new EntityReference("new_vehicle", createdVehicleId); svc.Update(roleInClaim); } } } } #endregion } catch (InvalidPluginExecutionException e) { throw new InvalidPluginExecutionException(e.Message, e.InnerException); } //catch (Exception ex) //{ // throw new Exception(ex.Message); //} return(createdClaim); }