public async Task <ActionResult> GetRecommendations([FromBody] RecommendationEvalContext evalContext)
        {
            var recommendationService = _providerFactory.GetProvider(evalContext.Provider);

            if (recommendationService == null)
            {
                throw new NotSupportedException(evalContext.Provider);
            }
            evalContext.StoreId = WorkContext.CurrentStore.Id;
            evalContext.UserId  = WorkContext.CurrentUser.Id;
            var result = await recommendationService.GetRecommendationsAsync(evalContext);

            return(Json(result));
        }
Exemple #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            object retVal       = new RecommendationEvalContext();
            var    obj          = JObject.Load(reader);
            var    providerName = obj.SelectToken("provider");

            if (providerName != null)
            {
                var provider = _providerFactory.GetProvider(providerName.Value <string>());
                if (provider != null)
                {
                    retVal = provider.CreateEvalContext();
                }
            }
            serializer.Populate(obj.CreateReader(), retVal);
            return(retVal);
        }