public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Bookmark = _bookmarksManager.Read((int)id).Result; if (Bookmark != null) { try { await _bookmarksManager.Delete((int)id); SuccessMessage = "Bookmark has been removed."; } catch { ErrorMessage = "There was error during bookmark removal."; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Bookmark = _bookmarksManager.Read((int)id).Result; if (Bookmark != null) { var currentUserId = Guid.Parse(User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value); if (Bookmark.OwnerId != currentUserId) { ErrorMessage = "You are not allowed to delete this bookmark."; return(RedirectToPage("/Index")); } try { await _bookmarksManager.Delete((int)id); SuccessMessage = "Bookmark has been removed."; } catch { ErrorMessage = "There was error during bookmark removal."; } } return(RedirectToPage("./Index")); }