Esempio n. 1
0
        public async Task <IActionResult> CreateAlbum(Guid bandId, [FromBody] AlbumToCreate model)
        {
            if (!await _service.BandExists(bandId))
            {
                return(NotFound());
            }

            var album = await _service.CreateAlbum(bandId, model.Title, model.ReleaseDate, model.Art);

            return(CreatedAtAction(nameof(GetAlbumForBandById), new { bandId, album.Id }, _mapper.Map <Album>(album)));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(Guid bandId, AlbumToCreate album)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _service.CreateAlbum(bandId, album.Title, album.ReleaseDate, album.Art);

                    return(RedirectToAction(nameof(Index), new { bandId }));
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }

            ViewBag.BandId = bandId;
            return(View(album));
        }