using System.Linq; using System.Collections.Generic; using Newtonsoft.Json.Linq; using System.Text; namespace AyaNova.Biz { //************************************************ // This contains all the fields that are customizable on all object edit forms // it is used for both validation and driving the UI etc //See the DataList folder / namespace for LIST related similar class public static class AyaFormFieldDefinitions { //DEFINE VALID KEYS HERE public const string WIDGET_KEY = "widget"; public const string USER_KEY = "user"; public static List AyaFormFieldDefinitionKeys { get { List l = new List{ WIDGET_KEY, USER_KEY }; return l; } } public static bool IsValidFormFieldDefinitionKey(string key) { return AyaFormFieldDefinitionKeys.Contains(key); } public static List AyaFormFields(string key) { /* ***************************** WARNING: Be careful here, if a standard field is hideable and also it's DB SCHEMA is set to NON NULLABLE then the CLIENT end needs to set a default ***************************** Otherwise the hidden field can't be set and the object can't be saved EVER */ List l = new List(); switch (key) { case WIDGET_KEY: #region WIDGET_KEY l.Add(new AyaFormFieldDefinition { LtKey = "WidgetName", FieldKey = "Name", Hideable = false }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetSerial", FieldKey = "Serial" }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetDollarAmount", FieldKey = "DollarAmount" }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCount", FieldKey = "Count" }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetUserType", FieldKey = "UserType" }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetStartDate", FieldKey = "StartDate" }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetEndDate", FieldKey = "EndDate" }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetNotes", FieldKey = "Notes" }); //More to do on this, maybe the datatype should be a LINK or something for UI purposes //circle back on this when there is enough infrastructure to test l.Add(new AyaFormFieldDefinition { LtKey = "User", FieldKey = "userid" }); l.Add(new AyaFormFieldDefinition { LtKey = "Active", FieldKey = "Active", Hideable = false }); l.Add(new AyaFormFieldDefinition { LtKey = "Tags", FieldKey = "Tags" }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom1", FieldKey = "WidgetCustom1", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom2", FieldKey = "WidgetCustom2", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom3", FieldKey = "WidgetCustom3", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom4", FieldKey = "WidgetCustom4", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom5", FieldKey = "WidgetCustom5", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom6", FieldKey = "WidgetCustom6", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom7", FieldKey = "WidgetCustom7", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom8", FieldKey = "WidgetCustom8", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom9", FieldKey = "WidgetCustom9", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom10", FieldKey = "WidgetCustom10", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom11", FieldKey = "WidgetCustom11", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom12", FieldKey = "WidgetCustom12", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom13", FieldKey = "WidgetCustom13", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom14", FieldKey = "WidgetCustom14", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom15", FieldKey = "WidgetCustom15", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "WidgetCustom16", FieldKey = "WidgetCustom16", IsCustomField = true }); break; #endregion case USER_KEY: #region USER_KEY l.Add(new AyaFormFieldDefinition { LtKey = "Name", FieldKey = "Name", Hideable = false }); l.Add(new AyaFormFieldDefinition { LtKey = "UserEmployeeNumber", FieldKey = "EmployeeNumber" }); l.Add(new AyaFormFieldDefinition { LtKey = "AuthorizationRoles", FieldKey = "Roles", Hideable = false }); l.Add(new AyaFormFieldDefinition { LtKey = "UserNotes", FieldKey = "Notes" }); l.Add(new AyaFormFieldDefinition { LtKey = "UserType", FieldKey = "UserType", Hideable = false }); l.Add(new AyaFormFieldDefinition { LtKey = "Active", FieldKey = "Active", Hideable = false }); l.Add(new AyaFormFieldDefinition { LtKey = "Tags", FieldKey = "Tags" }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom1", FieldKey = "UserCustom1", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom2", FieldKey = "UserCustom2", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom3", FieldKey = "UserCustom3", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom4", FieldKey = "UserCustom4", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom5", FieldKey = "UserCustom5", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom6", FieldKey = "UserCustom6", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom7", FieldKey = "UserCustom7", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom8", FieldKey = "UserCustom8", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom9", FieldKey = "UserCustom9", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom10", FieldKey = "UserCustom10", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom11", FieldKey = "UserCustom11", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom12", FieldKey = "UserCustom12", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom13", FieldKey = "UserCustom13", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom14", FieldKey = "UserCustom14", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom15", FieldKey = "UserCustom15", IsCustomField = true }); l.Add(new AyaFormFieldDefinition { LtKey = "UserCustom16", FieldKey = "UserCustom16", IsCustomField = true }); break; #endregion default: throw new System.ArgumentOutOfRangeException($"AyaFormFieldDefinitions: {key} is not valid"); } return l; } public static string TranslateLTCustomFieldToInternalCustomFieldName(string lTCustomFieldName) { var i = System.Convert.ToInt32(System.Text.RegularExpressions.Regex.Replace( lTCustomFieldName, // Our input "[^0-9]", // Select everything that is not in the range of 0-9 "" // Replace that with an empty string. )); return $"c{i}"; } }//eoc ObjectFields public class AyaFormFieldDefinition { //CLIENT / SERVER Unique identifier used at BOTH client and server //also the sql displaycolumnname if identical public string FieldKey { get; set; } //CLIENT Use only for display public string LtKey { get; set; } //CLIENT form customization public bool Hideable { get; set; } //CLIENT / SERVER - client display server validation purposes public bool IsCustomField { get; set; } public AyaFormFieldDefinition() { //most common defaults Hideable = true; IsCustomField = false; } }//eoc }//ens