// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } // _context.PubWork.Add(PubWork); // await _context.SaveChangesAsync(); // return RedirectToPage("./Index"); var emptyPubWork = new PubWork(); if (await TryUpdateModelAsync <PubWork>( emptyPubWork, "PubWork", // Prefix for form value. s => s.PubWorkKeyID, s => s.PubWorkName, s => s.PubWorkYear, s => s.AuthorID, s => s.PublicationID, s => s.PubWorkNotes, s => s.PubWorkAbstract, s => s.PubWorkKeywords, s => s.PubWorkKeyPhrases)) { _context.PubWork.Add(emptyPubWork); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } // Select DepartmentID if TryUpdateModelAsync fails. PopulatePublicationsDropDownList(_context, emptyPubWork.PublicationID); PopulateAuthorsDropDownList(_context, emptyPubWork.AuthorID); return(Page()); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } PubWork = await _context.PubWork.FirstOrDefaultAsync(m => m.PubWorkKeyID == id); if (PubWork == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } PubWork = await _context.PubWork.FindAsync(id); if (PubWork != null) { _context.PubWork.Remove(PubWork); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } // PubWork = await _context.PubWork.FirstOrDefaultAsync(m => m.PubWorkKeyID == id); PubWork = await _context.PubWork .Include(s => s.Publication) .Include(e => e.Author) .AsNoTracking() .FirstOrDefaultAsync(m => m.PubWorkKeyID == id); if (PubWork == null) { return(NotFound()); } return(Page()); }