Пример #1
0
        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"));
        }
Пример #2
0
        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"));
        }