/// <summary>
        /// Gets product to product recommendation no data, caching or etc - use IRecommendations for business layer
        /// </summary>
        /// <param name="tenantId"></param>
        /// <param name="sourceId"></param>
        /// <param name="productKey"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public Result productToProductRecommendation(string tenantId, string sourceId, string productKey)
        {
            #region shared variables

            Result result = new Result();

            HttpStatusCode statusCode = HttpStatusCode.NotFound;
            List<ProductRecommendation> lstProductRecommendations = null;
            long _tenantId = 0;
            long _sourceId = 0;

            #endregion shared variables

            try
            {
                #region param validation

                tenantId.isValidId("Tenant ID");
                sourceId.isValidId("Source ID");
                productKey.requireNotNullOrEmpty("Product Key");

                _tenantId = long.Parse(tenantId);
                _sourceId = long.Parse(sourceId);

                #endregion param validation

                #region access to business logic layer

                AbstractRecommendations productRecommendations = new Recommendations(cacheSupport, null);
                lstProductRecommendations = productRecommendations.productToProductRecommendation(_tenantId, _sourceId, productKey, Constants.NUMBER_OF_RECOMMENDATIONS);

                #endregion access to business logic layer

                #region set return value

                //get status code - if no data not founds
                statusCode = RestUtils.getStatusCodeForContent<ProductRecommendation>(lstProductRecommendations);

                //Assign tenantId to result object
                result.tenantId = _tenantId;
                result.resultSet = lstProductRecommendations;

                #endregion set return value
            }
            catch (TenantNotFoundException txc)
            {
                //TODO: Log the error
                long.TryParse(tenantId, out _tenantId);
                result.tenantId = _tenantId;
                result.error = new RestError(txc.message, Constants.ERR_TENANT_NOT_FOUND);
                statusCode = txc.statusCode;
            }
            catch (NotFoundException nxc)
            {
                //TODO: Log the error
                long.TryParse(tenantId, out _tenantId);
                result.tenantId = _tenantId;
                result.error = new RestError(nxc.message, Constants.ERR_ITEM_NOT_FOUND);
                statusCode = nxc.statusCode;
            }
            catch (ArgumentException axc)
            {
                //TODO: Log the error
                long.TryParse(tenantId, out _tenantId);
                result.tenantId = _tenantId;
                result.error = new RestError(axc.Message, Constants.ERR_ARGUMENT_EXCEPTION);
                statusCode = HttpStatusCode.BadRequest;
            }
            catch (Exception exc)
            {
                //TODO: Log the error
                long.TryParse(tenantId, out _tenantId);
                result.tenantId = _tenantId;
                result.error = new RestError(exc.Message, Constants.ERR_GENERIC_EXCEPTION);
                statusCode = HttpStatusCode.BadRequest;
            }
            return RestUtils.RestResponse<Result>(WebOperationContext.Current, statusCode, result);
        }
Exemple #2
0
        /// <summary>
        /// Gets product to product recommendation no data, caching or etc - use IRecommendations for business layer
        /// </summary>
        /// <param name="tenantId"></param>
        /// <param name="sourceId"></param>
        /// <param name="productKey"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public Result productToProductRecommendation(string tenantId, string sourceId, string productKey)
        {
            #region shared variables

            Result result = new Result();

            HttpStatusCode statusCode = HttpStatusCode.NotFound;
            List <ProductRecommendation> lstProductRecommendations = null;
            long _tenantId = 0;
            long _sourceId = 0;

            #endregion shared variables

            try
            {
                #region param validation

                tenantId.isValidId("Tenant ID");
                sourceId.isValidId("Source ID");
                productKey.requireNotNullOrEmpty("Product Key");

                _tenantId = long.Parse(tenantId);
                _sourceId = long.Parse(sourceId);

                #endregion param validation

                #region access to business logic layer

                AbstractRecommendations productRecommendations = new Recommendations(cacheSupport, null);
                lstProductRecommendations = productRecommendations.productToProductRecommendation(_tenantId, _sourceId, productKey, Constants.NUMBER_OF_RECOMMENDATIONS);

                #endregion access to business logic layer


                #region set return value

                //get status code - if no data not founds
                statusCode = RestUtils.getStatusCodeForContent <ProductRecommendation>(lstProductRecommendations);

                //Assign tenantId to result object
                result.tenantId  = _tenantId;
                result.resultSet = lstProductRecommendations;

                #endregion set return value
            }
            catch (TenantNotFoundException txc)
            {
                //TODO: Log the error
                long.TryParse(tenantId, out _tenantId);
                result.tenantId = _tenantId;
                result.error    = new RestError(txc.message, Constants.ERR_TENANT_NOT_FOUND);
                statusCode      = txc.statusCode;
            }
            catch (NotFoundException nxc)
            {
                //TODO: Log the error
                long.TryParse(tenantId, out _tenantId);
                result.tenantId = _tenantId;
                result.error    = new RestError(nxc.message, Constants.ERR_ITEM_NOT_FOUND);
                statusCode      = nxc.statusCode;
            }
            catch (ArgumentException axc)
            {
                //TODO: Log the error
                long.TryParse(tenantId, out _tenantId);
                result.tenantId = _tenantId;
                result.error    = new RestError(axc.Message, Constants.ERR_ARGUMENT_EXCEPTION);
                statusCode      = HttpStatusCode.BadRequest;
            }
            catch (Exception exc)
            {
                //TODO: Log the error
                long.TryParse(tenantId, out _tenantId);
                result.tenantId = _tenantId;
                result.error    = new RestError(exc.Message, Constants.ERR_GENERIC_EXCEPTION);
                statusCode      = HttpStatusCode.BadRequest;
            }
            return(RestUtils.RestResponse <Result>(WebOperationContext.Current, statusCode, result));
        }