public static async Task <ShoppingFavorite> InsertOrMergeShoppingFavoriteAsync(CloudTable table, ShoppingFavorite entity) { if (entity == null) { throw new ArgumentNullException("entity"); } try { // Create the InsertOrReplace table operation TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(entity); // Execute the operation. TableResult result = await table.ExecuteAsync(insertOrMergeOperation); ShoppingFavorite insertedCustomer = result.Result as ShoppingFavorite; if (result.RequestCharge.HasValue) { Console.WriteLine("Request Charge of InsertOrMerge Operation: " + result.RequestCharge); } return(insertedCustomer); } catch (StorageException e) { Console.WriteLine(e.Message); Console.ReadLine(); throw; } }
public static async Task <ShoppingFavorite> RetrieveEntityUsingPointQueryAsync(CloudTable table, string partitionKey, string rowKey) { try { TableOperation retrieveOperation = TableOperation.Retrieve <ShoppingFavorite>(partitionKey, rowKey); TableResult result = await table.ExecuteAsync(retrieveOperation); ShoppingFavorite favorite = result.Result as ShoppingFavorite; if (favorite != null) { Console.WriteLine("\t{0}\t{1}\t{2}", favorite.PartitionKey, favorite.RowKey, favorite.Name); } if (result.RequestCharge.HasValue) { Console.WriteLine("Request Charge of Retrieve Operation: " + result.RequestCharge); } return(favorite); } catch (StorageException e) { Console.WriteLine(e.Message); Console.ReadLine(); throw; } }
public async Task <ShoppingFavorite> AddToFavorites(ProductPrice game) { var shoppingFavorite = new ShoppingFavorite(ShopTypeEnum.PSStore, game.Id) { Name = game.Name, Discount = game.Discount, DiscountDate = String.IsNullOrWhiteSpace(game.Discount) ? null : (DateTime?)DateTime.Now, DiscountedPrice = game.DiscountedPrice, FavoritesDate = DateTime.Now, Price = game.Price, Media = game.Media, Store = (int)ShopTypeEnum.PSStore }; var table = await ShoppingTrackerDAL.CreateTableAsync(ShoppingTrackerDAL.SHOPPING_FAVORITES_TABLE); var favorite = await ShoppingTrackerDAL.InsertOrMergeShoppingFavoriteAsync(table, shoppingFavorite); return(favorite); }
private static async Task <string> UpdateFavoritePSStoreAsync(Microsoft.Azure.Cosmos.Table.CloudTable table, ShoppingFavorite favorite, ILogger log) { var baseAddress = "https://web.np.playstation.com/api/graphql/v1/op?operationName=productRetrieveForCtasWithPrice&variables=%7B%22productId%22%3A%22{0}%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%228532da7eda369efdad054ca8f885394a2d0c22d03c5259a422ae2bb3b98c5c99%22%7D%7D"; string offer = null; using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("x-psn-store-locale-override", "it-IT"); HttpResponseMessage response = await client.GetAsync(String.Format(baseAddress, favorite.RowKey)); if (response.IsSuccessStatusCode) { var jsonResponse = await response.Content.ReadAsStringAsync(); var game = JsonConvert.DeserializeObject <PsStoreGame>(jsonResponse); if (game.data.productRetrieve != null) { if (favorite.DiscountedPrice != game.data.productRetrieve.webctas[0].price.discountedPrice) { offer = $"{favorite.Name} - Old Price: {favorite.DiscountedPrice} - New Price: {game.data.productRetrieve.webctas[0].price.discountedPrice} - Discount: {game.data.productRetrieve.webctas[0].price.discountText}"; log.LogInformation($"Discount {game.data.productRetrieve.webctas[0].price.discountText} for favorite {favorite.Name} - Old Price: {favorite.DiscountedPrice} - New Price: {game.data.productRetrieve.webctas[0].price.discountedPrice}"); } favorite.Discount = String.IsNullOrEmpty(game.data.productRetrieve.webctas[0].price.discountText) ? String.Empty : game.data.productRetrieve.webctas[0].price.discountText; favorite.DiscountedPrice = game.data.productRetrieve.webctas[0].price.discountedPrice; favorite.DiscountDate = DateTime.Now; favorite.Price = game.data.productRetrieve.webctas[0].price.basePrice; await ShoppingTrackerDAL.InsertOrMergeShoppingFavoriteAsync(table, favorite); } else { log.LogError($"Product is no more available in the store: {favorite.Name}"); } } else { log.LogError($"Impossible to update favorite: {favorite.Name}"); } } return(offer); }