public async Task <JsonResult> Delete(int id) { string currentUserId = HttpContext.User.GetUserId(); Dictionary <string, object> response = new Dictionary <string, object>(); ApplicationUser user = await ControllerHelpers.GetCurrentUserAsync(_userManager, _dataAccess, currentUserId); if (user.EvernoteCredentials == null) { response["error"] = "You must authenticate with Evernote"; return(Json(response)); } IEvernoteService evernoteService = new EvernoteServiceSDK1(user.EvernoteCredentials); Bookmark bookmark = _dataAccess.GetBookmarkById(id); if (bookmark == null) { response["error"] = "Unable to delete bookmark: no such bookmark"; return(Json(response)); } if (bookmark.UserId != currentUserId) { response["error"] = "Unable to delete bookmark: user not authorised"; return(Json(response)); } _dataAccess.DeleteBookmark(bookmark); return(Json(response)); }
public async Task <IActionResult> DeleteBookmark(int id) { string currentUserId = HttpContext.User.GetUserId(); ApplicationUser user = await ControllerHelpers.GetCurrentUserAsync(_userManager, _dataAccess, currentUserId); if (user.EvernoteCredentials == null) { return(View("MustAuthoriseEvernote")); } // checks Bookmark bookmark = _dataAccess.GetBookmarkById(id); if (bookmark == null) { return(View("BookmarkNotFoundError")); } if (bookmark.UserId != currentUserId) { return(HttpBadRequest()); } // delete bookmark _dataAccess.DeleteBookmark(bookmark); return(RedirectToAction("RecentlyRead")); }