Skip to content

Commit 70ddc68

Browse files
committed
Contact mapping updates
1 parent 935b48c commit 70ddc68

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/Umbraco.Forms.Integrations.Crm.ActiveCampaign/ActiveCampaignContactsWorkflow.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.Extensions.Options;
2-
using Polly;
2+
33
using System.Text.Json;
4+
45
using Umbraco.Forms.Core;
56
using Umbraco.Forms.Core.Enums;
67
using Umbraco.Forms.Core.Persistence.Dtos;
@@ -43,10 +44,10 @@ public override WorkflowExecutionStatus Execute(WorkflowExecutionContext context
4344
var contacts = _contactService.Get(email).Result;
4445

4546
var result = _contactService.CreateOrUpdate(new ContactRequestDto
46-
{
47-
Contact = contacts.Contacts.Count > 0
47+
{
48+
Contact = contacts.Contacts.Count > 0
4849
? contacts.Contacts.First() : Build(context.Record)
49-
},
50+
},
5051
contacts.Contacts.Count > 0).Result;
5152

5253
if (!result) return WorkflowExecutionStatus.Failed;
@@ -76,18 +77,21 @@ public override List<Exception> ValidateSettings()
7677
/// </summary>
7778
/// <param name="record"></param>
7879
/// <returns></returns>
79-
private ContactDto Build(Record record) => new ContactDto
80-
{
81-
Email = ReadMapping(record, "email"),
82-
FirstName = ReadMapping(record, "firstName"),
83-
LastName = ReadMapping(record, "lastName"),
84-
Phone = ReadMapping(record, "phone")
85-
};
86-
87-
private string ReadMapping(Record record, string name)
80+
private ContactDto Build(Record record)
8881
{
8982
var mappings = JsonSerializer.Deserialize<List<ContactMappingDto>>(ContactMappings);
9083

84+
return new ContactDto
85+
{
86+
Email = ReadMappingValue(record, mappings, "email"),
87+
FirstName = ReadMappingValue(record, mappings, "firstName"),
88+
LastName = ReadMappingValue(record, mappings, "lastName"),
89+
Phone = ReadMappingValue(record, mappings, "phone")
90+
};
91+
}
92+
93+
private string ReadMappingValue(Record record, List<ContactMappingDto> mappings, string name)
94+
{
9195
var mappingItem = mappings.FirstOrDefault(p => p.ContactField == name);
9296

9397
return mappingItem != null

0 commit comments

Comments
 (0)