Exemplo n.º 1
0
        public async Task <IActionResult> DeleteConfirmed(long id)
        {
            var post = await _postRepository.FindByIdAsync(id);

            await _postRepository.DeleteAsync(post);

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 2
0
 public async Task <IActionResult> OnPostDelete()
 {
     if (ID != null)
     {
         await _post.DeleteAsync(ID.Value);
     }
     return(RedirectToPage("/Index"));
 }
        public async Task <IActionResult> Delete(int id)
        {
            Post postToDelete = await _postService.GetPostById(id);

            var PostType = postToDelete.PostType;

            try
            {
                await _postService.DeleteAsync(postToDelete);
            }
            catch (DbUpdateConcurrencyException ex)
            {
                Console.WriteLine($"Failed to save to database: {ex.Message}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Failed to save to database: {ex.Message}");
            }
            if (PostType == PostTypes.LOST)
            {
                return(RedirectToAction(nameof(LostPets)));
            }
            return(RedirectToAction(nameof(SeenPets)));
        }