コード例 #1
0
        public async Task <IActionResult> Update([FromBody] DropshipItemModel model)
        {
            //Get username from jwt
            var username = HttpContext.User.Identity.Name;

            model.Username = username;

            //Get integration information
            var oauth = await oauthdb.RetrieveOAuth <OAuthShopifyModel>(username);

            if (oauth == null)
            {
                return(NotFound("Integration not configured properly"));
            }

            //Get aliexpress item details
            var sourceItem = await search.ItemSearch(model.Source);

            if (sourceItem == null)
            {
                return(NotFound("Aliexpress link was incorrect"));
            }

            if (sourceItem == null)
            {
                return(NotFound("Aliexpress source is incorrect"));
            }

            //Get shpoify item details
            var shopifyProducts = await shopify.GetProductsByID(username, new string[] { model.ListingID }, oauth);

            var product = shopifyProducts.FirstOrDefault();

            if (product == null)
            {
                return(NotFound("Shopify listing is incorrect"));
            }

            //Apply rules to shopify item
            if (model.Rules.ApplyRules(sourceItem, product))
            {
                //Update shopify item with rule results
                var updatedProduct = await shopify.UpdateProduct(username, product, oauth);
            }

            //Save the model in the DB
            await dbItems.UpdateRules(model);

            return(Ok());
        }
コード例 #2
0
        //Obsolete version of this method

        /*      public async Task AddProduct(string username, DropshipItemModel model)
         *    {
         *        if (model.Source.Link.EmptyOrNull())
         *            return;
         *
         *        switch(model.Source.Source)
         *        {
         *            case "Aliexpress":
         *                await AddProduct(username, model.Source);
         *                break;
         *
         *            default:
         *                throw new Exception("Invalid DropshipItemModel Source");
         *        }
         *    }
         */

        //Obsolete method, this is now done in the DropshippingController

        /*
         * public async Task UpdateProduct(string username, DropshipItem item)
         * {
         * await shopify.UpdateProduct(username, item.Product);
         * } */

        public async Task SyncProduct(string username, DropshipItem item)
        {
            var sourceItem = await search.ItemSearch(item.Dropshipping.Source);

            if (sourceItem == null)
            {
                return;
            }

            var rules = item.Dropshipping.Rules ?? DropshipListingRules.Default;

            var creds = await oauthdb.RetrieveOAuth <OAuthShopifyModel>(username);

            if (rules.ApplyRules(sourceItem, item.Product) && creds != null)
            {
                await shopify.UpdateProduct(username, item.Product, creds);
            }
        }