Example #1
0
        public async Task <IActionResult> CreateAlbum(CreateAlbumDto albumToCreate)
        {
            int userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            // Check if user exceeded album limit
            if (_limitSettings.Value.MaxAlbums != 0 && await _albumRepo.GetAlbumCount(userId) >= _limitSettings.Value.MaxAlbums)
            {
                return(BadRequest($"You have reached the maximum album limit of {_limitSettings.Value.MaxAlbums.ToString()}"));
            }

            var album = new Album(albumToCreate.IsPublic, userId, albumToCreate.Name);

            _albumRepo.Add(album);

            if (!await _albumRepo.SaveAll())
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = "Failed at saving album" }));
            }

            var albumToReturn = _mapper.Map <AlbumToReturnDto>(album);

            if (album.IsPublic)
            {
                return(CreatedAtRoute("GetAlbum", new { controller = "Album", albumId = album.Id }, albumToReturn));
            }
            return(CreatedAtRoute("GetAlbumPrivate", new { controller = "Album", albumId = album.Id }, albumToReturn));
        }
Example #2
0
        public async Task <AlbumDto> AddAlbumAsync(string username, CreateAlbumDto newAlbum)
        {
            var album = _mapper.Map <Album>(newAlbum);
            await _albumRepository.AddAlbumAsync(username, album);

            return(_mapper.Map <AlbumDto>(album));
        }
Example #3
0
        public void Create_IncreasesCountAndAddsItem()
        {
            // Arrange
            var context       = this.ServiceProvider.GetRequiredService <WmipDbContext>();
            var albumsService = new AlbumsService(context);
            var creationInfo  = new CreateAlbumDto()
            {
                AlbumCoverLink  = "newlink",
                Genre           = "newgenre",
                Name            = "newname",
                ReleaseDate     = DateTime.Now.AddDays(1),
                ReleaseStage    = ReleaseStage.Announced,
                SpotifyLink     = "newSLink",
                SelectedSongIds = new int[] { 1, 2, 3, 4, 5, 6, 7 }
            };

            // Act
            albumsService.Create(creationInfo);

            //Assert
            Assert.Single(context.Albums);
            Assert.Equal(creationInfo.Name, context.Albums.First().Name);
            Assert.Equal(creationInfo.AlbumCoverLink, context.Albums.First().AlbumCoverLink);
            Assert.Equal(creationInfo.Genre, context.Albums.First().Genre);
            Assert.Equal(creationInfo.ReleaseDate, context.Albums.First().ReleaseDate);
            Assert.Equal(creationInfo.ReleaseStage, context.Albums.First().ReleaseStage);
            Assert.Equal(creationInfo.SpotifyLink, context.Albums.First().SpotifyLink);
            Assert.Equal(creationInfo.SelectedSongIds, context.Albums.First().AlbumsSongs.Select(s => s.SongId));
        }
Example #4
0
        public async Task Create(CreateAlbumDto input)
        {
            var @eventHeader = _eventHeaderRepository.Get(input.EventHeaderId);

            var @album = input.MapTo <Album>();

            @album = Album.Create(AbpSession.GetTenantId(), input.Name, input.Url);

            @eventHeader.Albums.Add(@album);

            await CurrentUnitOfWork.SaveChangesAsync();
        }
        public async Task <ActionResult> Post([FromBody] CreateAlbumDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var username = User.FindFirst(c => c.Type == ClaimTypes.Name).Value;

            var album = await _albumService.AddAlbumAsync(username, model);

            return(Created("api/album/" + album.Id, null));
        }
Example #6
0
        public ActionResult <AlbumDto> CreateAlbum(CreateAlbumDto albumDto)
        {
            if (!_repository.IsBandExists(albumDto.BandId))
            {
                return(NotFound());
            }
            var album = _mapper.Map <Album>(albumDto);

            _repository.AddAlbum(album);
            _repository.Save();

            var albumToReturn = _mapper.Map <AlbumDto>(album);

            return(CreatedAtRoute("GetAlbum", new { albumId = albumToReturn.Id }, albumToReturn));
        }
Example #7
0
        public bool Create(CreateAlbumDto creationInfo)
        {
            try
            {
                var album = new Album
                {
                    Name           = creationInfo.Name,
                    Genre          = creationInfo.Genre,
                    ReleaseDate    = creationInfo.ReleaseDate,
                    ReleaseStage   = creationInfo.ReleaseStage,
                    SpotifyLink    = creationInfo.SpotifyLink,
                    AlbumCoverLink = creationInfo.AlbumCoverLink,
                    ArtistId       = creationInfo.ArtistId,
                    ApprovalStatus = ApprovalStatus.Pending
                };

                if (creationInfo.SelectedSongIds != null)
                {
                    foreach (var songId in creationInfo.SelectedSongIds)
                    {
                        var currentAlbumSong = new AlbumSong
                        {
                            SongId = songId,
                        };

                        album.AlbumsSongs.Add(currentAlbumSong);
                    }
                }

                this.context.Albums.Add(album);
                this.context.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }