Inheritance: GalaSoft.MvvmLight.ObservableObject
Ejemplo n.º 1
0
        private void AssignRoles(Team team)
        {
            if (team.SecurityRoles == null || team.SecurityRoles.Count == 0)
            {
                return;
            }

            var query = new QueryExpression("role");
            query.Distinct = true;
            query.ColumnSet = new ColumnSet("roleid");
            query.Criteria.AddCondition("name", ConditionOperator.In, team.SecurityRoles.ToArray());
            query.Criteria.AddCondition("businessunitid", ConditionOperator.Equal, team.DestinationBusinessUnitId);

            var result = OrganizationService.RetrieveMultiple(query);

            if (result == null || result.Entities == null && result.Entities.Count != team.SecurityRolesCount)
            {
                throw new Exception("Could not find all security roles in the destination for team with name: " + team.Name);
            }

            var roles = result.Entities
                .Select(e => new EntityReference("role", e.Id))
                .ToList();

            OrganizationService.Associate("team", team.TeamId,
                new Relationship("teamroles_association"),
                new EntityReferenceCollection(roles));
        }
Ejemplo n.º 2
0
        private void SetCurrency(Team team)
        {
            if (string.IsNullOrEmpty(team.Currency))
            {
                return;
            }

            var query = new QueryExpression("transactioncurrency");
            query.PageInfo = new PagingInfo();
            query.PageInfo.Count = 1;
            query.PageInfo.PageNumber = 1;
            query.ColumnSet = new ColumnSet("transactioncurrencyid");
            query.Criteria.AddCondition("currencyname", ConditionOperator.Equal, team.Currency);

            var result = OrganizationService.RetrieveMultiple(query);

            if (result != null && result.Entities != null && result.Entities.Count == 1)
            {
                team.DestinationCurrencyId = result.Entities.First().Id;
            }
            else
            {
                throw new Exception("Could not locate a single currency with name " + team.Currency);
            }
        }
Ejemplo n.º 3
0
        private void SetOwner(Team team)
        {
            var query = new QueryExpression("systemuser");
            query.PageInfo = new PagingInfo();
            query.PageInfo.Count = 1;
            query.PageInfo.PageNumber = 1;
            query.ColumnSet = new ColumnSet("systemuserid");
            query.Criteria.AddCondition("domainname", ConditionOperator.Equal, team.AdministratorDomainName);

            var result = OrganizationService.RetrieveMultiple(query);

            if (result != null && result.Entities != null && result.Entities.Count == 1)
            {
                team.DestinationAdministratorId = result.Entities.First().Id;
            }
            else
            {
                throw new Exception("Could not locate a single user with domainname " + team.AdministratorDomainName);
            }
        }
Ejemplo n.º 4
0
        private void RemoveRoles(Team team)
        {
            var query = new QueryExpression("role");
            query.Distinct = true;
            query.ColumnSet = new ColumnSet("roleid");

            if (team.SecurityRoles != null && team.SecurityRoles.Count > 0)
            {
                query.Criteria.AddCondition("name", ConditionOperator.NotIn, team.SecurityRoles.ToArray());
            }

            query.Criteria.AddCondition("businessunitid", ConditionOperator.Equal, team.DestinationBusinessUnitId);

            var teamLink = query.AddLink("teamroles", "roleid", "roleid", JoinOperator.Inner);
            teamLink.LinkCriteria.AddCondition("teamid", ConditionOperator.Equal, team.TeamId);

            var result = OrganizationService.RetrieveMultiple(query);

            if (result == null || result.Entities == null || result.Entities.Count == 0)
            {
                // Nothing to remove
                return;
            }

            var roles = result.Entities
                .Select(e => new EntityReference("role", e.Id))
                .ToList();

            OrganizationService.Disassociate("team", team.TeamId,
                new Relationship("teamroles_association"),
                new EntityReferenceCollection(roles));
        }