예제 #1
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);
            }
        }
예제 #2
0
        public async Task PostImage(int albumId, AddImageToAlbum createRequest)
        {
            MediaAlbum albumEntity = await DbContext.MediaAlbums
                .SingleOrDefaultAsync(a => a.MediaAlbumId == albumId);
            if (albumEntity == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            if (albumEntity.UserId != UserId)
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }


            UserMedia mediaEntity = await DbContext.UserMedias
                .SingleOrDefaultAsync(um => um.UserMediaId == createRequest.MediaId);
            if (mediaEntity == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }
            if (mediaEntity.UserId != UserId)
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden);
            }

            await AlbumOperations.AddMediaToAlbumAsync(DbContext, albumEntity, mediaEntity, createRequest);
        }