|
1 | 1 | using Microsoft.Extensions.Options;
|
2 |
| -using Polly; |
| 2 | + |
3 | 3 | using System.Text.Json;
|
| 4 | + |
4 | 5 | using Umbraco.Forms.Core;
|
5 | 6 | using Umbraco.Forms.Core.Enums;
|
6 | 7 | using Umbraco.Forms.Core.Persistence.Dtos;
|
@@ -43,10 +44,10 @@ public override WorkflowExecutionStatus Execute(WorkflowExecutionContext context
|
43 | 44 | var contacts = _contactService.Get(email).Result;
|
44 | 45 |
|
45 | 46 | var result = _contactService.CreateOrUpdate(new ContactRequestDto
|
46 |
| - { |
47 |
| - Contact = contacts.Contacts.Count > 0 |
| 47 | + { |
| 48 | + Contact = contacts.Contacts.Count > 0 |
48 | 49 | ? contacts.Contacts.First() : Build(context.Record)
|
49 |
| - }, |
| 50 | + }, |
50 | 51 | contacts.Contacts.Count > 0).Result;
|
51 | 52 |
|
52 | 53 | if (!result) return WorkflowExecutionStatus.Failed;
|
@@ -76,18 +77,21 @@ public override List<Exception> ValidateSettings()
|
76 | 77 | /// </summary>
|
77 | 78 | /// <param name="record"></param>
|
78 | 79 | /// <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) |
88 | 81 | {
|
89 | 82 | var mappings = JsonSerializer.Deserialize<List<ContactMappingDto>>(ContactMappings);
|
90 | 83 |
|
| 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 | + { |
91 | 95 | var mappingItem = mappings.FirstOrDefault(p => p.ContactField == name);
|
92 | 96 |
|
93 | 97 | return mappingItem != null
|
|
0 commit comments