public static TweezersObject Find(string collectionName, bool withInternalObjects = false, bool withInternalFields = false, bool safe = false) { TweezersObject obj = InternalFind(collectionName, withInternalObjects, withInternalFields); if (obj == null && !safe) { throw new TweezersValidationException( TweezersValidationResult.Reject($"Could not find collection with name {collectionName}")); } return(obj); }
public static void AddObject(TweezersObject obj) { TweezersObject dbObj = InternalFind(obj.CollectionName, true); if (dbObj?.Internal ?? false) { throw new ArgumentException("trying to override an internal object"); } DeleteObject(obj.CollectionName); DatabaseProxy.Add(ObjectMetadataCollectionName, obj.CollectionName, JObject.FromObject(obj)); }
private static TweezersObject InternalFind(string collectionName, bool withInternalObjects = false, bool withInternalFields = false) { JObject tweezersDbJObject = DatabaseProxy.Get(ObjectMetadataCollectionName, collectionName); TweezersObject dbObj = tweezersDbJObject.ToStrongType <TweezersObject>(); if (dbObj != null) { TweezersObject clone = JObject.FromObject(dbObj).ToStrongType <TweezersObject>(); if (clone.Internal && !withInternalObjects) { return(null); } if (clone.Internal) { clone.Fields = clone.Fields.Where(f => withInternalFields || !f.Value.FieldProperties.UiIgnore) .ToDictionary(f => f.Key, f => f.Value); } return(clone); } return(null); }