public ENTWFStateEO() { ENTWFStateProperties = new ENTWFStatePropertyEOList(); }
private void ValidateWorkflow(HRPaidTimeOffDataContext db, ref ENTValidationErrors validationErrors, ENTBaseEO item) { //If the current owner is required. if (CurrentOwnerENTUserAccountId == 0) { validationErrors.Add("Please select the " + WFOwnerGroups.GetByENTWFOwnerGroupId(Convert.ToInt32(CurrentState.ENTWFOwnerGroupId)).OwnerGroupName + "."); } if (OriginalItem == null) { throw new Exception("The original item was not sent to the workflow save method."); } else { //Check required fields. ENTWFStatePropertyEOList entWFStateProperties = new ENTWFStatePropertyEOList(); entWFStateProperties.Load(db, WFItem.CurrentWFStateId); Type objectType = Type.GetType(Workflow.ENTWorkflowObjectName); foreach (ENTWFStatePropertyEO entWFStateProperty in entWFStateProperties) { if (entWFStateProperty.Required) { PropertyInfo property = objectType.GetProperty(entWFStateProperty.PropertyName); string errorMessage = "The " + entWFStateProperty.PropertyName + " is required."; if (property.PropertyType.IsEnum) { Array a = Enum.GetValues(property.PropertyType); int value = Convert.ToInt32(property.GetValue(item, null)); bool isValid = false; foreach (int i in a) { if (i == value) { isValid = true; break; } } if (isValid == false) { validationErrors.Add(errorMessage); } } else { switch (property.PropertyType.Name) { case "Int32": if (Convert.ToInt32(property.GetValue(item, null)) == 0) { validationErrors.Add(errorMessage); } break; case "String": if ((property.GetValue(item, null) == null) || (property.GetValue(item, null).ToString() == string.Empty)) { validationErrors.Add(errorMessage); } break; case "DateTime": if ((property.GetValue(item, null) == null) || (Convert.ToDateTime(property.GetValue(item, null)) == DateTime.MinValue)) { validationErrors.Add(errorMessage); } break; case "Nullable`1": if (property.GetValue(item, null) == null) { validationErrors.Add(errorMessage); } break; default: throw new Exception("Property type unknown."); } } } //Check if this field is read only. Only check read only fields if the record was already submitted. if (((ENTBaseWorkflowEO)OriginalItem).CurrentState.ID != 0) { if (entWFStateProperty.ReadOnly) { PropertyInfo property = objectType.GetProperty(entWFStateProperty.PropertyName); if (property.GetValue(item, null).ToString() != property.GetValue(OriginalItem, null).ToString()) { validationErrors.Add("The " + entWFStateProperty.PropertyName + " can not be changed."); } } } } } }