// Get deals count
        private int GetDealCount()
        {
            var options = new GetItemsByQueryOptions(new Query("/sitecore/content/home/deals//*"))
            {
                InferType = true,
                Lazy      = Glass.Mapper.LazyLoading.Disabled
            };
            var deals = _sitecoreService.GetItems <BaseDeal>(options);

            return(deals != null?deals.Count() : 0);
        }
Beispiel #2
0
        public Item GetEvent(Item currentItem)
        {
            var sitecoreContext = sitecoreServiceFactory.GetSitecoreService();
            var options         = new GetItemsByQueryOptions
            {
                Query        = new Query("./*"),
                RelativeItem = currentItem,
                VersionCount = true,
                Lazy         = LazyLoading.Disabled
            };

            var nexti = sitecoreContext.GetItems <UsergroupEvent>(options);
            var next  = nexti.Where(i => i.Date > DateTime.Now).OrderBy(d => d.Date).FirstOrDefault();

            return(next != null?context.Database.GetItem(new ID(next.Id)) : null);
        }
Beispiel #3
0
        /// <summary>
        /// Maps data from the CMS value to the .Net property value
        /// </summary>
        /// <param name="mappingContext">The mapping context.</param>
        /// <returns>System.Object.</returns>
        public override object MapToProperty(AbstractDataMappingContext mappingContext)
        {
            var scConfig  = Configuration as SitecoreQueryConfiguration;
            var scContext = mappingContext as SitecoreDataMappingContext;

            string query = ParseQuery(scConfig.Query, scContext.Item);



            if (scConfig.PropertyInfo.PropertyType.IsGenericType)
            {
                var options = new GetItemsByQueryOptions();

                options.Copy(mappingContext.Options);

                options.Query    = Sc.Query.New(query);
                options.Language = scContext.Item.Language;

                scConfig.GetPropertyOptions(options);

                if (scConfig.IsRelative)
                {
                    options.RelativeItem = scContext.Item;
                }

                var result = scContext.Service.GetItems(options);
                return(result);
            }
            else
            {
                var options = new GetItemByQueryOptions();
                options.Copy(mappingContext.Options);
                options.Query    = Sc.Query.New(query);
                options.Language = scContext.Item.Language;

                scConfig.GetPropertyOptions(options);

                if (scConfig.IsRelative)
                {
                    options.RelativeItem = scContext.Item;
                }


                return(scContext.Service.GetItem(options));
            }
        }
 public AbstractGetItemsByQueryBuilder(GetItemsByQueryOptions options)
     : base(options)
 {
     _options = options;
 }
        public ActionResult Deals()
        {
            // product path
            string dealPath = "/sitecore/content/home/deals/london";
            // product Id
            string dealID = "{0CD5C7B6-D994-49BF-BB62-AC303D99A5D3}";
            // product name
            string dealName = "sydney";
            // query by product name
            string dealQuery = $"/sitecore/content/home/deals//*[contains(@@name,'{dealName.ToLower()}')]";
            // query type 1 to get multiple products
            string dealsPathType1 = "/sitecore/content/home/deals/*";
            // query type 2 to get multiple products
            string dealsPathType2 = "/sitecore/content/home/deals//*";

            BaseDeal target = _sitecoreService.GetItem <BaseDeal>(dealPath, x => x.LazyDisabled());

            #region Single Item

            #region  Get Item by Id
            //Example 1
            var options = new GetItemByIdOptions(new Guid(dealID))
            {
                InferType = true,
                Lazy      = Glass.Mapper.LazyLoading.Disabled
            };
            var target2 = _sitecoreService.GetItem <BaseDeal>(options);
            #endregion

            #region  Get Item by Path
            // Example 2
            var options1 = new GetItemByPathOptions(dealPath)
            {
                InferType = true,
                Lazy      = Glass.Mapper.LazyLoading.Disabled
            };
            var target3 = _sitecoreService.GetItem <BaseDeal>(options1);
            #endregion

            #region  Get Item by Query
            // Example 3
            var options4 = new GetItemByQueryOptions(new Query(dealQuery))
            {
                InferType = true,
                Lazy      = Glass.Mapper.LazyLoading.Disabled
            };
            var target4 = _sitecoreService.GetItem <BaseDeal>(options4);
            #endregion

            #endregion

            #region Multiple Items

            #region  Get Item by Query
            //Example 1
            var options10 = new GetItemsByQueryOptions(new Query(dealsPathType1))
            {
                InferType = true,
                Lazy      = Glass.Mapper.LazyLoading.Disabled
            };
            var target10 = _sitecoreService.GetItems <BaseDeal>(options10);

            //Example 2
            var options11 = new GetItemsByQueryOptions(new Query(dealsPathType2))
            {
                InferType = true,
                Lazy      = Glass.Mapper.LazyLoading.Disabled
            };
            var target11 = _sitecoreService.GetItems <BaseDeal>(options11);

            #endregion

            #endregion

            return(View("~/Areas/basic/Views/Home/Deals.cshtml", target11));
        }