示例#1
0
        public async Task <IActionResult> Create(
            Album album,
            [FromServices] IMemoryCache cache,
            CancellationToken requestAborted)
        {
            if (ModelState.IsValid)
            {
                album.Artist = await MusicStoreService.GetArtistAsync(album.ArtistId);

                album.Genre = await MusicStoreService.GetGenreAsync(album.GenreId);

                await MusicStoreService.AddAlbumAsync(album);


                var albumData = new AlbumData
                {
                    Title = album.Title,
                    Url   = Url.Action("Details", "Store", new { id = album.AlbumId })
                };
                if (cache != null)
                {
                    cache.Remove("latestAlbum");
                }

                return(RedirectToAction("Index"));
            }

            var genres = await MusicStoreService.GetGenresAsync();

            var artists = await MusicStoreService.GetAllArtistsAsync();

            ViewBag.GenreId  = new SelectList(genres, "GenreId", "Name", album.GenreId);
            ViewBag.ArtistId = new SelectList(artists, "ArtistId", "Name", album.ArtistId);
            return(View(album));
        }
示例#2
0
 private async Task <Model.Genre> FetchFromStoreAsync()
 {
     if (string.IsNullOrEmpty(_name))
     {
         return(await _storeService.GetGenreAsync(_intId));
     }
     else
     {
         return(await _storeService.GetGenreAsync(_name));
     }
 }