Exemple #1
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Artist = await _context.Artist
                     .AsNoTracking()
                     .FirstOrDefaultAsync(m => m.ID == id);

            if (Artist == null)
            {
                return(NotFound());
            }
            try
            {
                _context.Artist.Remove(Artist);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.)
                return(RedirectToAction("./Delete",
                                        new { id, saveChangesError = true }));
            }
        }
Exemple #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Artist).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ArtistExists(Artist.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }