/// <summary> /// Modifies a given QueryCriteria to exclude inactive items /// </summary> /// <typeparam name="T">Type of object to return</typeparam> /// <param name="criteria">QueryCriteria to adjust</param> /// <returns></returns> private static QueryCriteria ExcludeInactiveItems <T>(QueryCriteria criteria) where T : TypeProjection { PropertyPathHelper pathHelper = new PropertyPathHelper(); pathHelper.PropertyName = "ObjectStatus"; pathHelper.ObjectClass = ClassConstants.GetClassIdByType <T>(); QueryCriteriaExpression activeItemsOnly = new QueryCriteriaExpression { PropertyName = pathHelper.ToString(), PropertyType = QueryCriteriaPropertyType.Property, Operator = QueryCriteriaExpressionOperator.Equal, Value = EnumerationConstants.ConfigItem.BuiltinValues.ObjectStatus.Active.ToString("D") }; QueryCriteria newCriteria = criteria; if (newCriteria.Expressions.Count > 0) { newCriteria.GroupingOperator = QueryCriteriaGroupingOperator.And; } else { newCriteria.GroupingOperator = QueryCriteriaGroupingOperator.SimpleExpression; } newCriteria.Expressions.Add(activeItemsOnly); return(newCriteria); }
/// <summary> /// Creates a new TypeProjection of derived type T and returns it /// </summary> /// <typeparam name="T">TypeProjection derived type</typeparam> /// <param name="authToken">AuthorizationToken to use</param> /// <returns></returns> internal static async Task <T> CreateBlankObject <T>(AuthorizationToken authToken, string name, string displayName, dynamic objProps = null) where T : TypeProjection { // See if we have a CI matching this name first T item = await GetByFullName <T>(authToken, name); if (item != null) { string fullName = ClassConstants.GetClassNameByType <T>() + ":" + name; throw new CiresonDuplicateItemException("An object by the name " + fullName + " already exists."); } // Setup the CI dynamic ci = new ExpandoObject(); ci.formJson = new ExpandoObject(); ci.formJson.isDirty = true; ci.formJson.original = null; ci.formJson.current = new ExpandoObject(); ci.formJson.current.BaseId = null; ci.formJson.current.ClassTypeId = ClassConstants.GetClassIdByType <T>(); ci.formJson.current.ClassName = ClassConstants.GetClassNameByType <T>(); ci.formJson.current.Name = name; ci.formJson.current.DisplayName = displayName; ci.formJson.current.TimeAdded = "0001-01-01T00:00:00"; //ci.formJson.current.ObjectStatus = new ExpandoObject(); //ci.formJson.current.ObjectStatus.Id = EnumerationConstants.TypeProjection.BuiltinValues.ObjectStatus.Active; // Merge another property object in if (objProps != null) { IDictionary <string, object> ciDict = (IDictionary <string, object>)ci.formJson.current; foreach (var property in objProps.GetType().GetProperties()) { if (property.CanRead) { ciDict[property.Name] = property.GetValue(objProps); } } } // Create the new TypeProjection, then return the full-property object T newCI = await CreateObjectFromData <T>(authToken, ci); return(await GetByBaseId <T>(authToken, newCI.BaseId)); }