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.TableDtl { public class TableDtlEditModel : PageModel { private readonly CertAuth.Data.CertAuthContext _context; private readonly Models.TableDtlDA TDCtrlr; public TableDtlEditModel(CertAuth.Data.CertAuthContext context) { _context = context; TDCtrlr = new Models.TableDtlDA(); } [BindProperty] public CertAuth.Domain.TableDtl TableDtl { get; set; } [BindProperty(Name = "editDtlID", SupportsGet = true)] public int editDtlID { get; set; } [BindProperty(Name = "TableDesc", SupportsGet = true)] public string TableDesc { get; set; } [BindProperty(Name = "TableCode", SupportsGet = true)] public string TableCode { get; set; } [BindProperty(Name = "TableCode1", SupportsGet = true)] public string TableCode1 { get; set; } public SelectList slStatus { get; set; } public async Task OnGetAsync(int? id) { if (id == null) { //return NotFound(); } if (id == null && editDtlID != 0) { id = editDtlID; } TableCode1 = TableCode; TableDtl = await _context.TableDtl.FirstOrDefaultAsync(m => m.Id == id); if (TableDtl != null) { TableCode = TableDtl.TableCode; //return NotFound(); } LoadLists(); return Page(); } // 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(); } TableDtl.TimeStamp = DateTime.Now; _context.Attach(TableDtl).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TableDtlExists(TableDtl.Id)) { return NotFound(); } else { throw; } } return RedirectToPage("./TableDtlList", new { Tcode = TableCode }); } private bool TableDtlExists(int id) { return _context.TableDtl.Any(e => e.Id == id); } private void LoadLists() { slStatus = new SelectList(TDCtrlr.GetSlctItms("Status", "A", true, ""), "Value", "Text"); } } }