// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } try { _bookmarksManager.Update(Bookmark.Id, Bookmark); SuccessMessage = "Bookmark was stored."; } catch (DbUpdateConcurrencyException) { if (!_bookmarksManager.Exists(Bookmark.Id)) { return(NotFound()); } else { throw; } } catch { ErrorMessage = "Bookmark was not stored."; } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } var storedBookmark = _bookmarksManager.Read(Bookmark.Id).Result; var currentUserId = Guid.Parse(User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value); if (storedBookmark.OwnerId != currentUserId) { ErrorMessage = "You are not allowed to edit this bookmark."; return(RedirectToPage("/Index")); } try { Bookmark.OwnerId = currentUserId; _bookmarksManager.Update(Bookmark.Id, Bookmark); SuccessMessage = "Bookmark was stored."; } catch (DbUpdateConcurrencyException) { if (!_bookmarksManager.Exists(Bookmark.Id)) { return(NotFound()); } else { throw; } } catch { ErrorMessage = "Bookmark was not stored."; } return(RedirectToPage("./Index")); }