Esempio n. 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);
        }
Esempio n. 2
0
        public HttpResponseMessage <bool> UpdateWorkflow(long id, [FromBody] EC.EntityNugget entityNugget)
        {
            using (Profiler.Measure("WorkflowController.UpdateWorkflow"))
            {
                HttpResponseMessage <bool> result = null;

                DatabaseContext.RunWithRetry(() =>
                {
                    Action updateAction = () =>
                    {
                        MDL.IEntity updatedEntity = EC.EntityNugget.DecodeEntity(entityNugget, true);

                        var wf = updatedEntity.As <MDL.Workflow>();

                        if (updatedEntity == null)
                        {
                            throw new WebArgumentException("Workflow update does not contain data");
                        }

                        if (updatedEntity.Id != id)
                        {
                            throw new WebArgumentException("Request and nugget ids do not match");
                        }


                        updatedEntity.Save();
                    };

                    bool isCloned = WorkflowUpdateHelper.Update(id, updateAction);

                    result = new HttpResponseMessage <bool>(isCloned);
                });

                return(result);
            }
        }