Ejemplo n.º 1
0
 public static Task IndexAlbumAsync(
     MediaAlbum album)
 {
     return IndexItemAsync(
         new MessageIndexEntry
         {
             ItemId = "album-" + album.MediaAlbumId,
             Title = album.Title,
             Content = album.Description,
             MediaAlbumId = album.MediaAlbumId
         });
 }
Ejemplo n.º 2
0
        private static async Task<MediaAlbum> EnsureTimelinePhotoAlbumExistsAsync(
            ApplicationDbContext dbContext,
            UserInfo userEntity)
        {
            if (!userEntity.TimelineImagesMediaAlbumId.HasValue)
            {
                var timelineAlbum = new MediaAlbum
                {
                    User = userEntity,
                    Title = "Timeline Photos",
                    Description = "Photos posted to my timeline"
                };
                userEntity.TimelineImagesAlbum = timelineAlbum;
                dbContext.MediaAlbums.Add(timelineAlbum);

                await dbContext.SaveChangesAsync();

                return timelineAlbum;
            }

            if (userEntity.TimelineImagesAlbum == null)
            {
                await dbContext.Entry(userEntity).Reference(u => u.TimelineImagesAlbum).LoadAsync();
            }

            return userEntity.TimelineImagesAlbum;
        }
Ejemplo n.º 3
0
        public static async Task AddMediaToAlbumAsync(
            ApplicationDbContext dbContext,
            MediaAlbum albumEntity,
            UserMedia mediaEntity,
            AddImageToAlbum createRequest)
        {
            albumEntity.UserMedias.Add(mediaEntity);
            mediaEntity.MediaAlbum = albumEntity;
            if (mediaEntity.State == UserMediaState.UploadedButUnused)
            {
                mediaEntity.State = UserMediaState.InUse;
            }

            mediaEntity.Title = createRequest.Title;
            if (!string.IsNullOrWhiteSpace(createRequest.Description))
            {
                mediaEntity.Description = await TextOperations.CreateTextAsync(
                    dbContext, createRequest.Description);
            }

            await dbContext.SaveChangesAsync();
            await SearchOperations.IndexMediaAsync(new[] { mediaEntity });

            if (mediaEntity.Description != null)
            {
                await UserOperations.NotifyMentionsAsync(
                    dbContext, "Album Entry", mediaEntity.UserId, mediaEntity.Description);
            }
        }
Ejemplo n.º 4
0
        public static async Task<AlbumSummary> CreateAlbumAsync(
            ApplicationDbContext dbContext,
            UserInfo user,
            AlbumDefinition createRequest)
        {
            var entity = new MediaAlbum
            {
                User = user,
                Title = createRequest.Title,
                Description = createRequest.Description
            };
            dbContext.MediaAlbums.Add(entity);
            await dbContext.SaveChangesAsync();
            await SearchOperations.IndexAlbumAsync(entity);

            return new AlbumSummary
            {
                Id = entity.MediaAlbumId,
                UserId = user.UserInfoId,
                Title = entity.Title,
                Description = entity.Description,
                SampleMediaUrls = new string[0]
            };
        }
Ejemplo n.º 5
0
        public static async Task<HttpStatusCode> SetAvatarImage(
            ApplicationDbContext dbContext,
            UserInfo user,
            SetImage request)
        {
            UserMedia media = await dbContext.UserMedias
                .SingleOrDefaultAsync(um => um.UserMediaId == request.MediaId);
            if (media == null)
            {
                return HttpStatusCode.BadRequest;
            }

            if (!media.MediaAlbumId.HasValue)
            {

                if (user.AvatarsMediaAlbumId.HasValue)
                {
                    media.MediaAlbumId = user.AvatarsMediaAlbumId;
                }
                else
                {
                    var avatarsAlbum = new MediaAlbum
                    {
                        User = user,
                        Title = "Avatar Images",
                        Description = "Images used as my avatar"
                    };
                    user.AvatarsAlbum = avatarsAlbum;
                    media.MediaAlbum = avatarsAlbum;
                }
            }

            user.Avatar = media;
            await dbContext.SaveChangesAsync();

            return HttpStatusCode.OK;
        }