Add project files.
This commit is contained in:
66
paperless-ngx-export/Models/CustomFieldParsed.cs
Normal file
66
paperless-ngx-export/Models/CustomFieldParsed.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace paperless_ngx_export.Models
|
||||
{
|
||||
public class CustomFieldParsed
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public object? Value { get; set; }
|
||||
public Type DataType { get; set; }
|
||||
|
||||
public string StringValue => (string)Value;
|
||||
|
||||
public DateTime DateValue => Value != null && DataType == typeof(DateTime) ? (DateTime)Value : DateTime.MinValue;
|
||||
|
||||
public static CustomFieldParsed FromCustomFieldKeyValuePair(CustomFieldKeyValuePair pair, IEnumerable<CustomField> customFields)
|
||||
{
|
||||
if (pair.value != null && customFields.FirstOrDefault(cf => cf.Id == pair.field) is CustomField field)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (field.data_type)
|
||||
{
|
||||
case CustomField_DataType.date:
|
||||
return new CustomFieldParsed
|
||||
{
|
||||
Name = field.name,
|
||||
Value = DateTime.Parse(pair.value),
|
||||
DataType = typeof(DateTime)
|
||||
};
|
||||
break;
|
||||
case CustomField_DataType.select:
|
||||
return new CustomFieldParsed
|
||||
{
|
||||
Name = field.name,
|
||||
Value = field.extra_data.select_options.First(so => so.id == pair.value).label,
|
||||
DataType = typeof(string)
|
||||
};
|
||||
break;
|
||||
default:
|
||||
return new CustomFieldParsed
|
||||
{
|
||||
Name = field.name,
|
||||
Value = pair.value,
|
||||
DataType = typeof(string)
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Name}: {Value} ({DataType.Name})";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user