コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Thumbnail.ImageUrl = GetThumbnailUrl(Entity);

            CreateRequestLink.NavigateUrl = GetFirstChildUrl();

            var maxLatestArticlesSetting = ServiceContext.GetSiteSettingValueByName(Website, "service_request_max_kb_articles");

            int maxLatestArticles;

            maxLatestArticles = int.TryParse(maxLatestArticlesSetting, out maxLatestArticles) ? maxLatestArticles : 3;

            var latestArticles = Enumerable.Empty <Entity>().AsQueryable();

            var subject = Entity.GetAttributeValue <EntityReference>("adx_subjectid");

            if (subject != null)
            {
                latestArticles = XrmContext.CreateQuery("kbarticle")
                                 .Where(k => k.GetAttributeValue <OptionSetValue>("statecode") != null &&
                                        k.GetAttributeValue <OptionSetValue>("statecode").Value == (int)Enums.KbArticleState.Published &&
                                        k.GetAttributeValue <bool?>("msa_publishtoweb").GetValueOrDefault(false) &&
                                        k.GetAttributeValue <EntityReference>("subjectid").Id == subject.Id)
                                 .OrderByDescending(k => k.GetAttributeValue <DateTime>("createdon"))
                                 .Take(maxLatestArticles);
            }

            LatestArticlesList.DataSource = latestArticles;
            LatestArticlesList.DataBind();
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var portalContext      = PortalCrmConfigurationManager.CreatePortalContext();
            var context            = PortalCrmConfigurationManager.CreateServiceContext();
            var site               = portalContext.Website;
            var serviceRequestType = context.CreateQuery("adx_servicerequesttype").FirstOrDefault(s => s.GetAttributeValue <string>("adx_entityname") == CurrentStepEntityLogicalName);

            if (serviceRequestType == null)
            {
                throw new ApplicationException(string.Format("Service Request Type couldn't be found for the entity type {0}.", CurrentStepEntityLogicalName));
            }

            var website = context.CreateQuery("adx_website").FirstOrDefault(w => w.GetAttributeValue <Guid>("adx_websiteid") == site.Id);

            var maxLatestArticlesSetting = context.GetSiteSettingValueByName(website, "service_request_max_kb_articles");

            int maxLatestArticles;

            maxLatestArticles = int.TryParse(maxLatestArticlesSetting, out maxLatestArticles) ? maxLatestArticles : 10;

            var latestArticles = new List <Entity>();

            var subject = serviceRequestType.GetAttributeValue <EntityReference>("adx_subject");

            if (subject != null)
            {
                latestArticles = context.CreateQuery("kbarticle").Where(k => k.GetAttributeValue <OptionSetValue>("statecode") != null && k.GetAttributeValue <OptionSetValue>("statecode").Value == (int)Enums.KbArticleState.Published && k.GetAttributeValue <bool>("msa_publishtoweb") && k.GetAttributeValue <EntityReference>("subjectid") == subject).OrderByDescending(k => k.GetAttributeValue <DateTime>("createdon")).Take(maxLatestArticles).ToList();
            }

            //if (!latestArticles.Any())
            //{
            //	MoveToNextStep();
            //}

            LatestArticlesList.DataSource = latestArticles;

            LatestArticlesList.DataBind();
        }