public ConditionType CreateConditionType(Guid tenantId, int code, DataTypeCodes dataTypeCode, string name, string description) { if (tenantId == default(Guid)) { throw new ArgumentException("A valid tenant id must not be empty.", nameof(tenantId)); } if (code <= 0) { throw new ArgumentException("A valid condition type id must be greater than 0.", nameof(code)); } if (!Enum.IsDefined(ConditionTypeFactory.DataTypeCodesType, dataTypeCode)) { throw new ArgumentException($"A unknown data type code was specified: {dataTypeCode.ToString()}", nameof(dataTypeCode)); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("A valid name for the condition type was not provided.", nameof(name)); } return(new ConditionType(tenantId, code, dataTypeCode) { Description = description, Name = name }); }
private async Task <IConditionNode> CreateConditionNodeRecursive(Guid tenantId, CreateConditionNodeBase createConditionNodeBase) { switch (createConditionNodeBase) { case CreateComposedConditionNode cccn: LogicalOperatorCodes logicalOperatorCode = (LogicalOperatorCodes)cccn.LogicalOperatorCode; List <IConditionNode> conditionNodes = new List <IConditionNode>(); foreach (CreateConditionNodeBase ccnb in cccn.ChildNodes) { IConditionNode conditionNode = await this.CreateConditionNodeRecursive(tenantId, ccnb); conditionNodes.Add(conditionNode); } return(this.conditionNodeAbstractFactory.CreateComposedConditionNode(logicalOperatorCode, conditionNodes)); case CreateValueConditionNode cvcn: ConditionTypeKey conditionTypeKey = ConditionTypeKey.New(tenantId, cvcn.ConditionTypeCode); ConditionType conditionType = await this.conditionTypeRepository.GetById(conditionTypeKey); DataTypeCodes dataTypeCode = (DataTypeCodes)cvcn.DataTypeCode; OperatorCodes operatorCode = (OperatorCodes)cvcn.OperatorCode; return(this.conditionNodeAbstractFactory.CreateValueConditionNode(conditionType, dataTypeCode, operatorCode, cvcn.RightHandOperand)); default: throw new NotSupportedException("Unsupported condition node creation."); } }
public ConditionType(Guid tenantId, int code, DataTypeCodes dataTypeCode) { this.DataTypeCode = dataTypeCode; this.Key = new ConditionTypeKey { Code = code, TenantId = tenantId }; }
protected override string ValidateCurrent(CreateValueConditionNode createValueConditionNode, Guid tenantId) { DataTypeCodes dataTypeCode = (DataTypeCodes)createValueConditionNode.DataTypeCode; if (Enum.IsDefined(typeof(DataTypeCodes), dataTypeCode) && !this.IsValidDataTypeValue(dataTypeCode, createValueConditionNode.RightHandOperand)) { return(string.Format(InvariantResources.R010, dataTypeCode.ToString(), createValueConditionNode.RightHandOperand?.ToString())); } return(null); }
protected override string ValidateCurrent(CreateValueConditionNode createValueConditionNode, Guid tenantId) { DataTypeCodes dataTypeCode = (DataTypeCodes)createValueConditionNode.DataTypeCode; if (!Enum.IsDefined(typeof(DataTypeCodes), dataTypeCode)) { return(string.Format(InvariantResources.R008, createValueConditionNode.DataTypeCode)); } return(null); }
private bool IsValidDataTypeValue(DataTypeCodes dataTypeCode, object value) { string valueStringRepresentation = value?.ToString() ?? string.Empty; switch (dataTypeCode) { case DataTypeCodes.Integer: return(Int32.TryParse(valueStringRepresentation, out int integer)); case DataTypeCodes.Decimal: return(Decimal.TryParse(valueStringRepresentation, out decimal @decimal)); case DataTypeCodes.String: return(value != null); default: throw new NotSupportedException("Unsupported data type."); } }
public IValueConditionNode CreateValueConditionNode(ConditionType conditionType, DataTypeCodes dataTypeCode, OperatorCodes operatorCode, object rightHandOperand) { if (conditionType == null) { throw new ArgumentNullException(nameof(conditionType)); } if (!Enum.IsDefined(typeof(DataTypeCodes), dataTypeCode)) { throw new ArgumentException("Specified invalid value for data type code.", nameof(dataTypeCode)); } if (!Enum.IsDefined(typeof(OperatorCodes), operatorCode)) { throw new ArgumentException("Specified invalid value for operator code.", nameof(operatorCode)); } if (rightHandOperand == null) { throw new ArgumentNullException(nameof(rightHandOperand)); } switch (dataTypeCode) { case DataTypeCodes.Integer: return(new IntegerConditionNode(conditionType.Key.Code, operatorCode, Convert.ToInt32(rightHandOperand))); case DataTypeCodes.Decimal: return(new DecimalConditionNode(conditionType.Key.Code, operatorCode, Convert.ToDecimal(rightHandOperand))); case DataTypeCodes.String: return(new StringConditionNode(conditionType.Key.Code, operatorCode, rightHandOperand.ToString())); default: throw new NotSupportedException("Unsupported data type."); } }
public IConditionNode CreateValueConditionNode(ConditionType conditionType, DataTypeCodes dataTypeCode, OperatorCodes operatorCode, object rightHandOperand) { return this.valueConditionNodeFactory.CreateValueConditionNode(conditionType, dataTypeCode, operatorCode, rightHandOperand); }
private DataTypeDto ConvertToDto(DataTypeCodes dtc) => new DataTypeDto { Code = dtc.AsInteger(), Name = dtc.ToString() };