Beispiel #1
0
        /// <summary>
        ///     Decodes the entity.
        /// </summary>
        /// <param name="entityNugget">The entity nugget.</param>
        /// <param name="persistChanges">If true, the nugget is intended to be persisted.</param>
        /// <returns></returns>
        public static IEntity DecodeEntity(EntityNugget entityNugget, bool persistChanges = false)
        {
            if (entityNugget == null)
            {
                return(null);
            }
            if (entityNugget.DataV1 == null)
            {
                return(null);
            }

            // Recover EntityData
            JsonEntityQueryResult jeqr = entityNugget.DataV1;

            jeqr.ResolveIds( );
            long       id         = jeqr.Ids.FirstOrDefault( );
            EntityData entityData = jeqr.GetEntityData(id);

            // Bulk-check security (to fill security cache)
            var entitiesToCheck = jeqr.Entities.Where(je => je.Id > 0).Select(je => new EntityRef(je.Id)).ToList( );

            Factory.EntityAccessControlService.Check(entitiesToCheck, new[] { Permissions.Read });

            // Load as a modified entity structure
#pragma warning disable 618
            var svc = new EntityInfoService( );
#pragma warning restore 618
            IEntity entity = svc.DecodeEntity(entityData, persistChanges);
            return(entity);
        }