Example #1
0
        public EntityReference GetRootEntityReference(Guid accountId)
        {
            Account         crmAccount    = new Account();
            EntityReference entityRef     = new EntityReference(LogicalName, accountId);
            EntityReference rootEntityRef = new EntityReference(LogicalName, accountId);

            string accountId1   = string.Format("{0}.{1}", AccountAlias1, crmAccount.Id.Key);
            string accountName1 = string.Format("{0}.{1}", AccountAlias1, crmAccount.Name.Key);

            string accountId2   = string.Format("{0}.{1}", AccountAlias2, crmAccount.Id.Key);
            string accountName2 = string.Format("{0}.{1}", AccountAlias2, crmAccount.Name.Key);

            string parentAccountId2 = string.Format("{0}.{1}", AccountAlias2, crmAccount.ParentAccountId.Key);

            AliasedValue aliasValue = null;

            for (; entityRef != null;)
            {
                List <Entity> accountSet = SvcHelper.RetrieveMultiple(new FetchExpression(GetFetchXml(entityRef.Id)));
                entityRef = null;
                if (accountSet[0].Contains(accountId2))
                {
                    if (accountSet[0].Contains(parentAccountId2))
                    {
                        aliasValue = accountSet[0].GetAttributeValue <AliasedValue>(parentAccountId2);
                        entityRef  = (EntityReference)aliasValue.Value;
                    }
                    else
                    {
                        aliasValue       = accountSet[0].GetAttributeValue <AliasedValue>(accountId2);
                        rootEntityRef.Id = (Guid)aliasValue.Value;
                        if (accountSet[0].Contains(accountName2))
                        {
                            aliasValue         = accountSet[0].GetAttributeValue <AliasedValue>(accountName2);
                            rootEntityRef.Name = (string)aliasValue.Value;
                        }
                    }
                }
                else if (accountSet[0].Contains(accountId1))
                {
                    aliasValue       = accountSet[0].GetAttributeValue <AliasedValue>(accountId1);
                    rootEntityRef.Id = (Guid)aliasValue.Value;
                    if (accountSet[0].Contains(accountName1))
                    {
                        aliasValue         = accountSet[0].GetAttributeValue <AliasedValue>(accountName1);
                        rootEntityRef.Name = (string)aliasValue.Value;
                    }
                }
            }

            return(rootEntityRef);
        }
Example #2
0
        public ArticleResultViewModel(INavigationService navigationService)
        {
            _navigationService = navigationService;
            svcHelper          = new SvcHelper();

            Messenger.Default.Register <NotificationMessage>(this, async m =>
            {
                switch (m.Notification)
                {
                case "LoadMore":
                    IsBusy = true;
                    await GetArticles();
                    IsBusy = false;
                    break;
                }
            });
            page           = 1;
            Articles       = new ObservableRangeCollection <Article>();
            resourceLoader = new ResourceLoader();
        }
Example #3
0
        private async void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
        {
            if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
            {
                SvcHelper svcHelper = new SvcHelper();
                Gender    currentGender;

                if (rBtnIsMenChecked.IsChecked.Value)
                {
                    currentGender = Gender.Male;
                }
                else
                {
                    currentGender = Gender.Female;
                }
                bool IsErrorHappened = ((ArticleSearchViewModel)this.DataContext).ContainErrors();
                if (!IsErrorHappened)
                {
                    var articles = await svcHelper.GetArticles(sender.Text, currentGender, 1, 5);

                    sender.ItemsSource = articles.Select(a => a.Name);
                }
            }
        }
Example #4
0
 public static void Using <TServiceContract>(Action <TServiceContract> action) where TServiceContract : class
 {
     SvcHelper.Using <TServiceContract>(action, "*");
 }