Esempio n. 1
0
        public virtual async Task DeleteRestaurantAsync(RestaurantTableEntity restaurantTableEntity)
        {
            CloudTable tableRestaurants = _tableClient.GetTableReference("restaurants");

            var deleteOperation = TableOperation.Delete(restaurantTableEntity);
            await tableRestaurants.ExecuteAsync(deleteOperation);
        }
Esempio n. 2
0
        public virtual async Task UpdateRestaurantAsync(RestaurantTableEntity restaurantTableEntity)
        {
            CloudTable table = _tableClient.GetTableReference("restaurants");

            var mergeOperation = TableOperation.InsertOrMerge(restaurantTableEntity);
            await table.ExecuteAsync(mergeOperation);
        }
Esempio n. 3
0
        public virtual async Task <RestaurantTableEntity> InsertRestaurantAsync(RestaurantTableEntity restaurant)
        {
            CloudTable table = _tableClient.GetTableReference("restaurants");

            var insertOperation = TableOperation.Insert(restaurant);
            await table.ExecuteAsync(insertOperation);

            return(restaurant);
        }
Esempio n. 4
0
        public virtual async Task AddRestaurantRatingAsync(RestaurantRatingTableEntity restaurantRatingTableEntity, RestaurantTableEntity restaurantTableEntity)
        {
            CloudTable tableRestaurantsRatings = _tableClient.GetTableReference("restaurantsRatings");

            var insertOperation = TableOperation.Insert(restaurantRatingTableEntity);
            await tableRestaurantsRatings.ExecuteAsync(insertOperation);

            TableContinuationToken token      = null;
            var restaurantRatingTableEntities = new List <RestaurantRatingTableEntity>();

            do
            {
                var queryResult = await tableRestaurantsRatings.ExecuteQuerySegmentedAsync(new TableQuery <RestaurantRatingTableEntity>(), token);

                restaurantRatingTableEntities.AddRange(queryResult.Results);
                token = queryResult.ContinuationToken;
            } while (token != null);

            restaurantTableEntity.Rating = CalculateAverage(restaurantRatingTableEntities.Where(x => x.RestaurantRowKey == restaurantTableEntity.RowKey).Select(x => x.Rating));

            await UpdateRestaurantAsync(restaurantTableEntity);
        }