GlobalDemo.DAL.Azure.StorageRepository.GetPhotoFromTableAsync C# (CSharp) Method

GetPhotoFromTableAsync() public method

This is the most efficient way to retrieve, using both the partition key and row key
public GetPhotoFromTableAsync ( string tableName, string partitionKey, string rowKey ) : Task
tableName string
partitionKey string
rowKey string
return Task
        public async Task<PhotoModel> GetPhotoFromTableAsync(            
            string tableName,
            string partitionKey,
            string rowKey)
        {            
            var client = _account.CreateCloudTableClient();
            var table = client.GetTableReference(tableName);

            var operation = TableOperation.Retrieve<PhotoEntity>(partitionKey, rowKey);
            var result = await table.ExecuteAsync(operation);
            var entity = result.Result as PhotoEntity;
            return new PhotoModel(entity);
        }

Usage Example

        public async Task<IHttpActionResult> GetPhotoModel(string id)
        {
            var cache = RedisCache.Connection.GetDatabase();
            var repo = new RedisRepository(cache);

            //Get a single item from the cache based on its ID
            var photo = await repo.GetPhotoByIDAsync(id);

            if (null == photo)
            {
                //Not in the cache.  Retrieve from storage.
                string connectionString = SettingsHelper.LocalStorageConnectionString;
                string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
                var storageRepo = new StorageRepository(connectionString);
                photo = await storageRepo.GetPhotoFromTableAsync( DAL.Azure.StorageConfig.PhotosBlobContainerName, owner, id);
                if (null == photo)
                {
                    //Not found in cache or storage.                      
                }
                else
                {                    
                    //Update the cache using the cache aside pattern.
                    await repo.AddPhotoToUserCacheAsync(photo);
                }
            }
            if (null != photo)
            {
                return Ok(photo);
            }
            else
            {
                return NotFound();
            }
        }