public async Task <string> ReLoadAll(string accessToken) { try { if (!Is_Instagram_Sync_Running) { Is_Instagram_Sync_Running = true; //Get all instagram posts var posts = await _IInstagramGraphApi.GetInstagramPosts(accessToken); //Convert instagram posts to TB products ProductsList productsList = ConvertInstagramPostToProducts(posts); //Delete all existing data _ProductsRepository.DeleteAllProducts(); _ProductsRepository.DeleteAllProductsDetails(); //Add products to DB _ProductsRepository.AddProducts(productsList.Products); _ProductsRepository.AddProductsDetails(productsList.ProductsDetails); ////Backup existing images //FTPHandler.BackupDirectory(IMAGES_FOLDER_NAME, ftpUsername, ftpPassword); ////Create images //CreateNewImages(productsList, ftpUsername, ftpPassword); return("Done"); } else { return("Already_Running"); } } finally { Is_Instagram_Sync_Running = false; } }
public void GrabJsonShoppingSvc(string input) { var url = ShoppingApiAddress + "&callname=" + input + "&ResponseEncodingType=JSON&appid=" + appID; var arr = GetDataFromWebClient <Models.ShoppingSvcItem.Json>(url); var items = arr.ItemArray.Items; var itemsFinal = new List <StoreItem>(); foreach (var item in items) { if (itemsFinal.FindAll(x => x.ItemID == item.ItemID).Count < 1) //Sometimes there are items with duplicate PK { itemsFinal.Add(ConvertJsonShoppingSvcToStoreItem(item)); } } repo.AddProducts(itemsFinal); repo.Save(); }