コード例 #1
0
        private Entity GetEntityFromContext(ILocalPluginExecutionContext localContext)
        {
            var target = localContext.TargetEntity;
            var entity = new Entity(target.LogicalName);

            if (localContext.HasPreImage)
            {
                var preImage = localContext.PreImage;
                foreach (var preImageAttribute in preImage.Attributes)
                {
                    entity[preImageAttribute.Key] = target.Contains(preImageAttribute.Key) ? target[preImageAttribute.Key] : preImageAttribute;
                }
            }

            foreach (var targetAttribute in target.Attributes)
            {
                entity[targetAttribute.Key] = targetAttribute.Value;
            }

            return(entity);
        }
コード例 #2
0
        public void Execute(ILocalPluginExecutionContext localContext, IRepositoryFactory repoFactory)
        {
            if (this.CheckIfUserIsAdmin(localContext, repoFactory))
            {
                return;
            }

            var entity = GetEntityFromContext(localContext);

            var metadataRequest = new RetrieveEntityRequest()
            {
                LogicalName   = entity.LogicalName,
                EntityFilters = Microsoft.Xrm.Sdk.Metadata.EntityFilters.Attributes
            };

            var allRequredAttributes = GetAllRequiredAttributes(repoFactory, metadataRequest);

            foreach (var attribute in allRequredAttributes)
            {
                var errorMessage = $"Attribute {attribute.LogicalName} is required. Please specify value for this attribute before saving record.";
                if (!entity.Contains(attribute.LogicalName))
                {
                    throw new InvalidPluginExecutionException(errorMessage);
                }
                else
                {
                    var value = entity[attribute.LogicalName];
                    if (value == null)
                    {
                        throw new InvalidPluginExecutionException(errorMessage);
                    }
                    else if (value is string && string.IsNullOrEmpty(value as string))
                    {
                        throw new InvalidPluginExecutionException(errorMessage);
                    }
                }
            }
        }
コード例 #3
0
 public override void Execute(ILocalPluginExecutionContext localContext, IRepositoryFactory repoFactory, ITracingService service)
 {
     throw new System.NotImplementedException();
 }
コード例 #4
0
 public abstract void Execute(ILocalPluginExecutionContext localContext, IRepositoryFactory repoFactory, ITracingService service);
コード例 #5
0
        private bool CheckIfUserIsAdmin(ILocalPluginExecutionContext localContext, IRepositoryFactory repoFactory)
        {
            var generalRepository = repoFactory.Get <IBaseRepository>();

            return(generalRepository.IsAdmin(localContext.Context.InitiatingUserId));
        }