コード例 #1
0
        public void UpdateAlbumData(string owner, string albumId, string thumbnailUrl)
        {
            var context = new PhotoAlbumDataContext();

            var albumRow = new AlbumRow(new Album()
            {
                AlbumId = albumId, Owner = owner
            });
            var album = context.Albums.Where(a => a.PartitionKey == albumRow.PartitionKey && a.RowKey == albumRow.RowKey && a.ThumbnailUrl == thumbnailUrl)
                        .AsTableServiceQuery()
                        .FirstOrDefault();

            if (album != null)
            {
                // get the first the photo in the album to update the thumbnail
                var photoRow = new PhotoRow(new Photo {
                    Owner = owner.ToLowerInvariant(), AlbumId = albumId
                });
                var otherPhoto = context.Photos.Where(p => p.PartitionKey == photoRow.PartitionKey).Take(1).SingleOrDefault();

                // if the album is empty, we set the HasPhotos property to false to hide it from the UI
                if (otherPhoto != null)
                {
                    album.ThumbnailUrl = otherPhoto.ThumbnailUrl;
                }
                else
                {
                    album.ThumbnailUrl = string.Empty;
                    album.HasPhotos    = false;
                }

                this.UpdateAlbum(album.ToModel());
            }
        }
コード例 #2
0
        public void UpdateAlbum(Album album)
        {
            var context  = new PhotoAlbumDataContext();
            var albumRow = new AlbumRow(album);

            // attach and update the photo row
            context.AttachTo(PhotoAlbumDataContext.AlbumTable, albumRow, "*");
            context.UpdateObject(albumRow);

            context.SaveChanges();
        }
コード例 #3
0
 public static Album ToModel(this AlbumRow row)
 {
     return(new Album()
     {
         AlbumId = row.AlbumId,
         Title = row.Title,
         Owner = row.Owner,
         ThumbnailUrl = row.ThumbnailUrl,
         HasPhotos = row.HasPhotos
     });
 }
コード例 #4
0
        public void UpdateAlbum(Album album)
        {
            var context = new PhotoAlbumDataContext();
            var albumRow = new AlbumRow(album);

            // attach and update the photo row
            context.AttachTo(PhotoAlbumDataContext.AlbumTable, albumRow, "*");
            context.UpdateObject(albumRow);

            context.SaveChanges();
        }
コード例 #5
0
        public void UpdateAlbumData(string owner, string albumId, string thumbnailUrl)
        {
            var context = new PhotoAlbumDataContext();

            var albumRow = new AlbumRow(new Album() { AlbumId = albumId, Owner = owner });
            var album = context.Albums.Where(a => a.PartitionKey == albumRow.PartitionKey && a.RowKey == albumRow.RowKey && a.ThumbnailUrl == thumbnailUrl)
                .AsTableServiceQuery()
                .FirstOrDefault();

            if (album != null)
            {
                // get the first the photo in the album to update the thumbnail
                var photoRow = new PhotoRow(new Photo { Owner = owner.ToLowerInvariant(), AlbumId = albumId });
                var otherPhoto = context.Photos.Where(p => p.PartitionKey == photoRow.PartitionKey).Take(1).SingleOrDefault();

                // if the album is empty, we set the HasPhotos property to false to hide it from the UI
                if (otherPhoto != null)
                {
                    album.ThumbnailUrl = otherPhoto.ThumbnailUrl;
                }
                else
                {
                    album.ThumbnailUrl = string.Empty;
                    album.HasPhotos = false;
                }

                this.UpdateAlbum(album.ToModel());
            }
        }