public class LoginFormSubmit : SubmitActionBase<string>
{
public LoginFormSubmit(ISubmitActionData submitActionData) : base(submitActionData)
{
}
protected override bool TryParse(string data, out string target)
{
target = string.Empty;
return true;
}
//Override the Execute method to insert data to API
protected override bool Execute(string data, FormSubmitContext formSubmitContext)
{
ApiModel customData = new ApiModel();
try
{
Log.Info("FormSubmit Execute Method Started..", typeof(FormSubmit));
var firstNameField = GetFieldByName(ApiConstants.FirstName, formSubmitContext.Fields);
customData.First_Name__c = GetValue(firstNameField);
var emailField = GetFieldByName(ApiConstants.Email, formSubmitContext.Fields);
customData.Email__c = GetValue(emailField);
CreateContact contact = new CreateContact();
contact.CreateContactBasedOnSession(customData.First_Name__c, customData.Email__c);
return true;
}
catch (Exception e)
{
Log.Error("Login Save:", e, typeof(FormSubmit));
Log.Error(string.Concat("Login save", e.Message.ToString()), typeof(FormSubmit));
return false;
}
}
private static IViewModel GetFieldByName(string fieldName, IList<IViewModel> fields)
{
return fields?.FirstOrDefault(f => f.Name == fieldName) != null ? fields.FirstOrDefault(f => f.Name == fieldName) : null;
}
private static string GetValue(object field)
{
return field?.GetType().GetProperty("Value")?.GetValue(field, null)?.ToString() ?? string.Empty;
}
}```
[![enter image description here][1]][1]
[1]: https://i.sstatic.net/2XKyo.png
Bumped by Community user
Bumped by Community user
Bumped by Community user