public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } Paper = await _context.Papers.FirstOrDefaultAsync(m => m.ID == id); if (Paper == null) { return(NotFound()); } var authorizationResult = await _authorizationService .AuthorizeAsync(User, Paper, PaperOperations.Delete); if (authorizationResult.Succeeded) { return(Page()); } else if (User.Identity.IsAuthenticated) { return(new ForbidResult()); } else { return(new ChallengeResult()); } }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Paper = await _context.Papers.FindAsync(id); if (Paper == null) { return(NotFound()); } var authorizationResult = await _authorizationService .AuthorizeAsync(User, Paper, PaperOperations.Delete); if (authorizationResult.Succeeded) { _context.Papers.Remove(Paper); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } else if (User.Identity.IsAuthenticated) { return(new ForbidResult()); } else { return(new ChallengeResult()); } }
// 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()); } var paper = new Models.Paper { Author = await _userManager.GetUserAsync(User), NeedsCompilation = true, Title = Input.Title, Content = Input.Content, UnderSubmission = Input.UnderSubmission }; _context.Papers.Add(paper); await _context.SaveChangesAsync(); TempData["StatusMessage"] = $"Successfully created paper {paper.ID}"; return(RedirectToPage("./Index")); }