public static DateTime?ParseCustomFieldDate(InsightlyCustomFieldObject obj, string field) { if (obj == null || string.IsNullOrWhiteSpace(field)) { return(null); } return(DateTime.TryParse(obj?.CUSTOMFIELDS?.Where(cf => cf?.FIELD_NAME == field)?.FirstOrDefault()?.FIELD_VALUE?.ToString(), out DateTime date) ? (DateTime?)date : null); }
public static CustomField CreateCustomField(this InsightlyCustomFieldObject obj, string fieldName, object fieldValue) { if (obj.CUSTOMFIELDS == null) { obj.CUSTOMFIELDS = new List <CustomField>(); } var customField = new CustomField() { FIELD_NAME = fieldName, FIELD_VALUE = fieldValue }; obj.CUSTOMFIELDS.Add(customField); return(customField); }
public static object ExtractCustomFieldValue(this InsightlyCustomFieldObject obj, string fieldName) { return(obj?.CUSTOMFIELDS?.Where(cf => cf.FIELD_NAME == fieldName)?.FirstOrDefault()?.FIELD_VALUE); }
public static CustomField ExtractCustomField(this InsightlyCustomFieldObject obj, string fieldName, object fieldValue = null) { return(obj?.CUSTOMFIELDS?.Where(cf => cf.FIELD_NAME == fieldName)?.FirstOrDefault() ?? CreateCustomField(obj, fieldName, fieldValue)); }