Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, EditArtistFormModel artist)
        {
            if (id != artist.Id)
            {
                return(NotFound());
            }

            var editedArtist = _service.Edit(id, artist.Name, artist.Genre);

            if (!editedArtist)
            {
                return(BadRequest());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _service.Edit(artist.Id, artist.Name, artist.Genre);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ArtistExists(artist.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                if (!User.IsAdmin())
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(RedirectToAction("Index", "Admin", new { area = "Home" }));
                }
            }
            return(View(artist));
        }