Ejemplo n.º 1
0
        public static async Task <HttpStatusCode> ChangeAlbumAsync(
            ApplicationDbContext dbContext,
            UserInfo user,
            int albumId,
            AlbumDefinition modifyRequest)
        {
            MediaAlbum entity = await dbContext.MediaAlbums.SingleOrDefaultAsync(
                a => a.MediaAlbumId == albumId);

            if (entity == null)
            {
                return(HttpStatusCode.NotFound);
            }

            if (entity.UserId != user.UserInfoId)
            {
                return(HttpStatusCode.Forbidden);
            }

            entity.Title       = modifyRequest.Title;
            entity.Description = modifyRequest.Description;

            await dbContext.SaveChangesAsync();

            await SearchOperations.IndexAlbumAsync(entity);

            return(HttpStatusCode.OK);
        }
Ejemplo n.º 2
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]
            });
        }