wingman007 icon

2018_DotNetProgrammingPartTime_Index.cshtml.cs

wingman007 | PRO | 09/25/18 11:50:05 AM UTC | 0 ⭐ | 780 👁️ | Never ⏰ | []
C# |

1.04 KB

|

None

|

0 👍

/

0 👎

?using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
 
namespace WebApplication1bDeletMe.Pages
{
    public class IndexModel : PageModel
    {
        private readonly AppDbContext _db;
 
        public IList<Customer> Customers { get; set; }
 
        [TempData]
        public string Message { get; set; }
 
        public IndexModel(AppDbContext db) {
            _db = db;
        }
 
        public async Task OnGetAsync()
        {
            Customers = await _db.Customers.AsNoTracking().ToListAsync();
        }
 
        public async Task<ActionResult> OnPostDeleteAsync(int id)
        {
            var customer = await _db.Customers.FindAsync(id);
            if (customer != null)
            {
                _db.Customers.Remove(customer);
                await _db.SaveChangesAsync();
            }
            return RedirectToPage();
        }
    }
}

Comments