// 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 <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } string name = User.Identity.GetUserName(); if (Word.Submitter != name) { return(Page()); } _context.Attach(Word).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WordExists(Word.Id)) { return(Page()); } else { throw; } } return(LocalRedirect(Url.Content("~/Words/Mypage"))); }
// 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 <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } if (User.Identity.IsAuthenticated) { // GetUserName() によりユーザ名を取得 string name = User.Identity.GetUserName(); Word.Submitter = name; } _context.Word.Add(Word); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { string name = User.Identity.GetUserName(); if (Word.Submitter != name) { return(Page()); } if (id == null) { return(Page()); } Word = await _context.Word.FindAsync(id); if (Word != null) { _context.Word.Remove(Word); await _context.SaveChangesAsync(); } return(LocalRedirect(Url.Content("~/Words/Mypage"))); }