コード例 #1
0
        public IHttpActionResult Get()
        {
            if (User == null || User.Identity == null)
            {
                return(Unauthorized());
            }
            long currentUserId = User.Identity.GetUserId <long>();

            if (currentUserId <= 0)
            {
                return(Unauthorized());
            }
            var systemUser = SystemUser.Get(currentUserId, this._context);

            if (systemUser == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(systemUser));
            }
        }
コード例 #2
0
        protected override void Execute(CodeActivityContext executionContext)
        {
            // Extract the tracing service
            ITracingService tracingService = executionContext.GetExtension <ITracingService>();

            try
            {
                //Create the context
                IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
                IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
                IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

                DynamicUrlParser parser           = new DynamicUrlParser();
                EntityReference  primaryEntity    = parser.ConvertToEntityReference(service, RecordUrl.Get <string>(executionContext));
                string           relationshipName = RelationshipName.Get <string>(executionContext);

                Guid   ownerId   = Guid.Empty;
                string ownerType = string.Empty;

                EntityReference owner = SystemUser.Get <EntityReference>(executionContext);
                if (owner != null)
                {
                    ownerId   = owner.Id;
                    ownerType = owner.LogicalName;
                }
                else
                {
                    owner = Team.Get <EntityReference>(executionContext);
                    if (owner != null)
                    {
                        ownerId   = owner.Id;
                        ownerType = owner.LogicalName;
                    }
                }

                if (ownerId != Guid.Empty)
                {
                    string childEntityName = null, childEntityAttribute = null;
                    if (relationshipName.Contains(';'))
                    {
                        string[] relationshipNames = relationshipName.Split(';');
                        foreach (string rel in relationshipNames)
                        {
                            OneToManyRelationshipMetadata oneToNRelationship = RetrieveRelationshipInfo(service, primaryEntity, relationshipName);
                            if (oneToNRelationship != null)
                            {
                                childEntityName      = oneToNRelationship.ReferencingEntity;
                                childEntityAttribute = oneToNRelationship.ReferencingAttribute;
                                RetrieveAndUpdateRelatedRecords(service, primaryEntity, childEntityName, childEntityAttribute, ownerId, ownerType);
                            }
                        }
                    }
                    else
                    {
                        OneToManyRelationshipMetadata oneToNRelationship = RetrieveRelationshipInfo(service, primaryEntity, relationshipName);
                        if (oneToNRelationship != null)
                        {
                            childEntityName      = oneToNRelationship.ReferencingEntity;
                            childEntityAttribute = oneToNRelationship.ReferencingAttribute;
                            RetrieveAndUpdateRelatedRecords(service, primaryEntity, childEntityName, childEntityAttribute, ownerId, ownerType);
                        }
                    }
                }
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                throw new Exception("XrmWorkflowTools.AssignChildRecords: " + ex.Message);
            }
        }