コード例 #1
0
        /// <summary>
        /// Gets the sample rendering model.
        /// </summary>
        /// <param name="rendering">The rendering.</param>
        /// <param name="propertyBag">The property bag.</param>
        /// <returns>
        /// An initilaized sample rendering model is returned.
        /// </returns>
        public SamplesJsonResult GetSamples(IVisitorContext visitorContext, GetSamplesInputModel inputModel, StringPropertyCollection propertyBag = null)
        {
            Assert.ArgumentNotNull(inputModel, nameof(inputModel));

            var jsonResult = ModelProvider.GetModel <SamplesJsonResult>();

            try
            {
                var response = SampleManager.GetSamples(StorefrontContext.CurrentStorefront, visitorContext, propertyBag);
                if (!response.ServiceProviderResult.Success)
                {
                    jsonResult.SetErrors(response.ServiceProviderResult);
                    return(jsonResult);
                }

                var samples = response.Result;
                if (samples != null)
                {
                    jsonResult.Initialize(samples);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message, e, this);
                jsonResult.SetErrors("GetSample", e);
                return(jsonResult);
            }

            return(jsonResult);
        }
コード例 #2
0
        public JsonResult GetSamples(GetSamplesInputModel inputModel)
        {
            var validationModel = new BaseJsonResult(SitecoreContext, StorefrontContext);

            ValidateModel(validationModel);
            if (validationModel.HasErrors)
            {
                return(Json(validationModel));
            }

            var jsonData = SampleRepository.GetSamples(VisitorContext, inputModel);

            return(Json(jsonData));
        }