Example #1
0
        /// <summary>
        /// </summary>
        /// <returns></returns>
        protected static Entity GetCompleteEntity(IPluginExecutionContext context)
        {
            var result = default(Entity);

            if (context.InputParameters.Contains(ParameterName.Target) && context.InputParameters[ParameterName.Target] is Entity)
            {
                result = (Entity)context.InputParameters[ParameterName.Target];
            }

            if (context.PostEntityImages.Keys.Count > 0)
            {
                var postImage = context.PostEntityImages[context.PostEntityImages.Keys.First()];

                if (result == null)
                {
                    result = postImage;
                }
                else
                {
                    result = result.Merge(postImage);
                }
            }

            if (context.PreEntityImages.Keys.Count > 0)
            {
                var preImage = context.PreEntityImages[context.PreEntityImages.Keys.First()];

                if (result == null)
                {
                    result = preImage;
                }
                else
                {
                    result = result.Merge(preImage);
                }
            }

            if (result == null || result.Id.Equals(Guid.Empty))
            {
                var id = context.GetEntityId();
                if (!id.Equals(Guid.Empty))
                {
                    if (result == null)
                    {
                        result = new Entity(context.PrimaryEntityName, id);
                    }
                    else
                    {
                        result.Id = id;
                    }
                }
            }

            return(result);
        }