public async Task UpdateProduct(DropshipItemModel model) { var json = JsonConvert.SerializeObject(model); var jsonContent = new JsonContent(json); var response = await api.Post(ApiEndpoints.DropshipUpdateProduct, jsonContent); }
public async Task <HttpResponseMessage> AddProduct(DropshipItemModel item) { var json = JsonConvert.SerializeObject(item); var jsonContent = new JsonContent(json); var response = await api.Post(ApiEndpoints.DropshipAddProductDropshipItem, jsonContent); return(response); }
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()); }
public async Task <IActionResult> AddProduct(DropshipItemModel model) { if (!ModelState.IsValid) { return(View(model)); } var response = await dropship.AddProduct(model); if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { ModelState.AddModelError("All", await response.Content.ReadAsStringAsync()); return(View(model)); } return(RedirectToAction("Products")); }
public async Task <IActionResult> Product(int itemid, [FromForm] DropshipItemModel item) { item.ID = itemid; var json = JsonConvert.SerializeObject(item); var response = await api.Put(ApiEndpoints.DropshipUpdateProduct, new JsonContent(json)); if (response.IsSuccessStatusCode) { return(RedirectToAction("Products")); } else { var message = await response.Content.ReadAsStringAsync(); ModelState.AddModelError("All", message); return(View(item)); } }
public async Task <DropshipItemModel> Update(DropshipItemModel model) { await dbItems.Save(model); return(model); }
public async Task <IActionResult> Add([FromBody] DropshipItemModel model) { var item = model.Source; var username = "******"; if (HttpContext.User.Identity.IsAuthenticated) { username = HttpContext.User.Identity.Name; } if (item.Link.EmptyOrNull() && !item.Title.EmptyOrNull() && !item.ID.EmptyOrNull()) { item.Link = SearchEndpoints.AliexpressItemUrl(item.Title, item.ID); } var detail = await search.ItemSearch(item); if (detail == null) { return(NotFound("Aliexpress link was incorrect")); } model.Source.Title = detail.Name; model.Source.ID = detail.ItemID; //Get integration access tokens var oauth = await oauthdb.RetrieveOAuth <OAuthShopifyModel>(username); if (oauth == null) { return(NotFound("No dropshipping integration setup for user")); } //Create the dropship item and model var dropshipItem = new DropshipItem() { Dropshipping = new DropshipItemModel() { Source = item, Username = username, Rules = model.Rules, OAuthID = oauth.ID }, Product = new ShopifyProductModel() { BodyHtml = detail.Description, Title = detail.Name.Replace("/", "-"), //Fix slash in name issue Variants = new List <ShopifyVarant>() { new ShopifyVarant() { InventoryPolicy = InventoryPolicy.Deny, InventoryManagement = InventoryManagement.Shopify, RequiresShipping = true, Taxable = true } } } }; if (detail.ImageUrls != null) { //Add images from shopify var images = new List <ShopifyImageType>(); foreach (var image in detail.ImageUrls) { images.Add(new ShopifyImageType() { Src = image }); } //Set the first image to the main dropship model image if (images.Count > 0) { dropshipItem.Dropshipping.Image = images[0].Src; } dropshipItem.Product.Images = images.ToArray(); } //Apply dropshipping rules dropshipItem.Dropshipping.Rules.ApplyRules(detail, dropshipItem.Product); //Add product var product = await shopify.AddProduct(username, dropshipItem.Product, oauth); dropshipItem.Dropshipping.ListingID = product.ID; await dbItems.InsertItem(dropshipItem.Dropshipping); return(Ok()); }