using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; using CertAuth.Data; using CertAuth.Domain; namespace CertAuthAdmin.Pages.TableMstr { public class TableMstrEditModel : PageModel { private readonly CertAuth.Data.CertAuthContext _context; private readonly Models.TableDtlDA TDCtrlr; public TableMstrEditModel(CertAuth.Data.CertAuthContext context) { _context = context; TDCtrlr = new Models.TableDtlDA(); } [BindProperty] public CertAuth.Domain.TableMstr TableMstr { get; set; } [BindProperty(Name = "editID", SupportsGet = true)] public int editID { get; set; } public SelectList slStatus { get; set; } public async Task OnGetAsync(int? id) { //if (id == null) //{ // return NotFound(); //} if (id == null && editID != 0) { id = editID; } TableMstr = await _context.TableMstr.FirstOrDefaultAsync(m => m.Id == id); if (TableMstr != null) { LoadLists(); } return Page(); //if (TableMstr == null) //{ // return NotFound(); //} } // To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task OnPostAsync() { if (!ModelState.IsValid) { LoadLists(); return Page(); } TableMstr.TimeStamp = DateTime.Now; _context.Attach(TableMstr).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TableMstrExists(TableMstr.Id)) { return NotFound(); } else { throw; } } return RedirectToPage("./TableMstrList"); } private bool TableMstrExists(int id) { return _context.TableMstr.Any(e => e.Id == id); } private void LoadLists() { slStatus = new SelectList(TDCtrlr.GetSlctItms("Status", "A", true, ""), "Value", "Text"); } } }