コード例 #1
0
        public IActionResult SendProductToStore(PostStoreProductModel storeProductModel)
        {
            var product        = _commonService.GetProductToSendStore(storeProductModel.StoreProduct);
            var attributePairs = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(storeProductModel.AttributesQuery))
            {
                foreach (var pair in storeProductModel.AttributesQuery.Split("&&"))
                {
                    var splitedPair = pair.Split("==");
                    attributePairs.Add(splitedPair.First(), splitedPair.Last());
                }
            }
            var errorMessage = "";
            var storeProduct = _n11Service.SendProduct(product, attributePairs, ref errorMessage);

            if (storeProduct != null)
            {
                storeProduct.attribute_query = storeProductModel.AttributesQuery;
                _localService.AddOrUpdateStoreProduct(storeProduct);
                var textStyle = storeProduct.sale_price > product.price ? "success" : storeProduct.sale_price < product.price ? "warning" : "info";
                return(Json(new { isSucced = true, productId = storeProduct.product_id, storeId = storeProduct.store_id, price = storeProduct.sale_price, currency = storeProduct.currency ?? "TL", textStyle = textStyle }));
            }
            return(Json(new { isSucced = false, errorMessage = errorMessage }));
        }