public ActionResult Update(AlbumInputModel album)
        {
            if (!HttpContext.CheckAccess(
                    ChinookResources.AlbumActions.Edit,
                    ChinookResources.Album,
                    album.AlbumID.ToString()))
            {
                return(this.AccessDenied());
            }

            _musicRepository.SaveAlbum(album.GetAlbum());

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        // GET: api/music/album&&artistName=Passion Pit
        public IHttpActionResult Get([FromUri] AlbumInputModel inputModel)
        {
            if (inputModel == null)
            {
                return(BadRequest());
            }

            if (inputModel.id != 0)
            {
                return(Get(inputModel.id));
            }

            var result = albumService.GetAlbum(inputModel);

            return(Ok <IEnumerable <AlbumModel> >(result));
        }
Beispiel #3
0
        public async Task <IActionResult> CreateAlbum(AlbumInputModel inputModel)
        {
            ApplicationUser user = await this.userManager.GetUserAsync(this.User);

            inputModel.UserId = user.Id;
            try
            {
                await this.albumService.CreateAsync(inputModel);
            }
            catch (Exception e)
            {
                this.TempData["AlbumExist"] = e.Message;
            }

            return(this.RedirectToAction("All", "Albums"));
        }
        public async Task CreateAsync(AlbumInputModel albumInputModel)
        {
            if (this.albumRepository.All().Where(a => a.UserId == albumInputModel.UserId && a.Name == albumInputModel.Name).Any())
            {
                throw new ArgumentException("There is already existing album with this name");
            }

            Album album = new Album
            {
                Name   = albumInputModel.Name,
                UserId = albumInputModel.UserId,
            };

            await this.albumRepository.AddAsync(album);

            await this.albumRepository.SaveChangesAsync();
        }
Beispiel #5
0
        public IEnumerable <AlbumModel> GetAlbum(AlbumInputModel inputModel)
        {
            List <AlbumModel> result = new List <AlbumModel>();

            IEnumerable <Album> albums = null;

            if (inputModel.artistName.IsNotNullOrEmpty())
            {
                return(GetAlbum(inputModel.artistName).ToList());
            }
            else
            {
                albums = repository.GetAlbum();
            }

            if (!albums.IsNotNullOrEmpty())
            {
                return(null);
            }

            Mapper.CreateMap <Album, AlbumModel>();
            foreach (var album in albums)
            {
                var albumModel = Mapper.Map <AlbumModel>(album);
                var albumSongs = repository.GetSong(album.Id);

                if (!albumSongs.IsNotNullOrEmpty())
                {
                    result.Add(albumModel);
                    continue;
                }

                Mapper.CreateMap <Song, SongModel>();
                List <SongModel> songs = new List <SongModel>();
                foreach (var albumSong in albumSongs)
                {
                    var song = Mapper.Map <SongModel>(albumSong);
                    songs.Add(song);
                }
                albumModel.Songs = songs;
                result.Add(albumModel);
            }

            return(result);
        }