Пример #1
0
        public void PostSqlRepository_ShouldDeleteIntoDataBase()
        {
            post = repository.Get(1);

            repository.Delete(post);

            foreach (var item in repository.GetAll())
            {
                item.Id.Should().NotBe(post.Id);
            }
        }
Пример #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Post post = repPost.Read().FirstOrDefault(x => x.ID == id);

            repPost.Delete(post);
            return(RedirectToAction("Index"));
        }
Пример #3
0
        private void Remove()
        {
            Console.WriteLine("Please choose post");
            List <Post> posts = _postRepository.GetAll();

            for (int i = 0; i < posts.Count; i++)
            {
                Post post = posts[i];
                Console.WriteLine(@$ " {i + 1}) [Title:-{post.Title}
                    Url: {post.Url}
                    Published Date: {post.PublishDateTime}
                    Author Id: {post.Id}
                    Blog Id: {post.Id}]");
            }
            int  userChoice   = -1;
            bool isUserChoice = int.TryParse(Console.ReadLine(), out userChoice);

            if (isUserChoice)
            {
                Console.WriteLine($"Your choice is {userChoice}");
                _postRepository.Delete(posts[userChoice - 1].Id);
            }
            else
            {
                Console.WriteLine("Invalid Selection");
            }
        }
Пример #4
0
        public ActionResult DeletePost(int id)
        {
            postRepo.Delete(id);

            TempData["msg"] = "Post Deleted!!";
            return(RedirectToAction("CurrentPost"));
        }
Пример #5
0
        public void Delete(int postId)
        {
            var tags = _postTagRepository.GetBy(postId);
            var post = _postRepository.Get()
                       .FirstOrDefault(p => p.Id == postId);

            if (post == null)
            {
                return;
            }

            foreach (var tag in tags)
            {
                _postTagRepository.Delete(tag);
            }

            var postModel = new PostModel
            {
                Id      = post.Id,
                Deleted = true
            };

            _elasticService.IndexData(postModel); // Delete the document in ES
            _postRepository.Delete(post);
        }
        public ActionResult DeletePost(int id)
        {
            PostRepository postRepo = new PostRepository();

            postRepo.Delete(id);
            return(RedirectToAction("Posts", "Admin"));
        }
Пример #7
0
        protected void imgExcluiPost_Command(object sender, CommandEventArgs e)
        {
            post Post;

            if (Session["Aviso"] == null)
            {
                Post = PR.GetOne(int.Parse(e.CommandArgument.ToString()));
                Session["PostAberto"] = Post;
                Show("Deseja REALMENTE excluir a postagem?");
            }
            else if ((bool)Session["Aviso"] == true)
            {
                Post = (post)Session["PostAberto"];
                if (Post.id_usuario == UsuarioAtual.id_usuario)
                {
                    List <comentario> listacomentario = CR.GetAllById(Post.id_post);
                    if (listacomentario.Count > 0)
                    {
                        for (int i = 0; i < listacomentario.Count; i++)
                        {
                            CR.Delete(listacomentario[i].id_comentario);
                        }
                    }
                    PR.Delete(Post.id_post);
                    CriaTimeline();
                }
                Session.Remove("Aviso");
                Session.Remove("PostAberto");
            }
            else
            {
                Session.Remove("Aviso");
                Session.Remove("PostAberto");
            }
        }
        public ActionResult Delete(int id)
        {
            _postRepository.Delete(id);

            TempData["Message"] = "Your post was successfully deleted.";

            return(RedirectToAction("Index"));
        }
Пример #9
0
        public IActionResult Delete(string guid)
        {
            if (_post_repo.Delete(guid) == 0)
            {
                throw new HumanException("К сожалению, пост не был удалён. Повторите попытку ещё раз.");
            }

            return(Ok(new { message = "Пост успешно удалён." }));
        }
        public async Task <ActionResult> Delete(int id)
        {
            //  var userPost = await db.UserPosts.FindAsync( id);
            //var userPost = await  Db.UserPosts.Include(p=>p.PostComments).FirstOrDefaultAsync(p=>p.UserPostId==id);

            var userPost = await _repository.GetByClause(p => p.UserPostId == id);

            if (userPost == null)
            {
                return(View("Error"));
            }

            foreach (var comment in userPost.PostComments.ToList())
            {
                try
                {
                    //if (userPost.PostComments.All(c => c.PostCommentId != comment.PostCommentId))
                    // db.PostComments.Remove(comment);
                    // await Db.PostComments.FindAsync(comment.PostCommentId);
                    var commToDelete = await _cRepository.FindById(comment.PostCommentId);

                    if (commToDelete != null)
                    {
                        await _cRepository.Delete(commToDelete);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

            await _repository.Delete(userPost);

            //try
            //{
            //    await Db.SaveChangesAsync();
            //}
            //catch (Exception)
            //{
            //    return View("Error");
            //}

            //Db.UserPosts.Remove(userPost);

            //try
            //{
            //    await Db.SaveChangesAsync();
            //}
            //catch (Exception)
            //{
            //    return View("Error");
            //}

            return(RedirectToAction("Index", "Home"));
        }
Пример #11
0
 public IHttpActionResult Delete(int id)
 {
     // var pr = postrepo.Get(id);
     postrepo.Delete(id);
     //var comm= comRepo.GetCommentByPost(pr.PostId);
     // int i= comm.
     // comRepo.Delete(i.);
     return(StatusCode(HttpStatusCode.NoContent));
 }
        private void Remove()
        {
            Post postToDelete = Choose("Which post would you like to remove?");

            if (postToDelete != null)
            {
                _postRepository.Delete(postToDelete.Id);
            }
        }
        private void Remove()
        {
            Post postToDelete = Choose("Which post would you like to remove? (Enter a number)");

            if (postToDelete != null)
            {
                _postRepository.Delete(postToDelete.Id);
                Console.WriteLine($"{postToDelete.Title} deleted");
            }
        }
Пример #14
0
        private static void DeletePost(string title)
        {
            var postRepository = new PostRepository();
            var post = postRepository.GetPostByTitle(title);

            if (post != null)
            {
                postRepository.Delete(post);
            }
        }
        private void Remove()
        {
            Post postToDelete = Choose("Which author would you like to remove?");

            if (postToDelete != null)
            {
                _postRepository.Delete(postToDelete.Id);
                Console.WriteLine("Post deleted");
            }
        }
Пример #16
0
 public void DeletePost(int id)
 {
     try
     {
         _repository.Delete(id);
     }
     catch (Exception e)
     {
     }
 }
Пример #17
0
        public void DeletePost(string id)
        {
            Post post = _postRepository.GetById(id);

            if (post == null)
            {
                throw new Exception("Post does not exist");
            }

            _postRepository.Delete(id);
        }
        private void Remove()
        {
            Post postToDelete = Choose("Which post would you like to delete?");

            if (postToDelete != null)
            {
                _postRepository.Delete(postToDelete.Id);
                Console.WriteLine("Post has been removed.");
            }
            Console.WriteLine();
        }
Пример #19
0
        public async Task <IHttpActionResult> Delete(int Id)
        {
            try{ log.Info(new MDCSet(this.ControllerContext.RouteData), new InfoException(Id));
                 await _entityRepo.Delete(Id);

                 return(Ok("Registro eliminado exitosamente!")); }
            catch (Exception e)
            {
                log.Error(new MDCSet(this.ControllerContext.RouteData), e);
                return(InternalServerError(e));
            }
        }
 public string Delete(int id)
 {
     try
     {
         _Repo.Delete(id);
         return("Account deleted!");
     }
     catch (Exception e)
     {
         return($"Error Message{e.Message}");
     }
 }
Пример #21
0
 //
 public bool DeletePost(ObjectId postId)
 {
     try
     {
         repository.Delete(postId);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #22
0
 public HttpResponseMessage Delete(int post_id)
 {
     try
     {
         postrepo.Delete(post_id);
         return(Request.CreateResponse(HttpStatusCode.NoContent));
     }
     catch
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Failed to delete post."));
     }
 }
Пример #23
0
        public ActionResult ConfirmDelete(int id)
        {
            if (!AuthorizeUser())
            {
                return(RedirectToAction("Login", "Accounts"));
            }

            var post = postrepo.Get(id);

            postrepo.Delete(id);
            return(RedirectToAction("Index", new { id = post.BlogID }));
        }
Пример #24
0
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         _PostRepository.Delete(id);
         return(Request.CreateResponse(HttpStatusCode.OK, MensagensSucesso.PostExcluido));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }
        public ActionResult Delete(int id, Post post)
        {
            try
            {
                _postRepo.Delete(post);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View("../Post/Delete", post));
            }
        }
        public async void DeletePostTest()
        {
            PostRepository postRepository = new PostRepository(_dataContext);

            var post = await postRepository.GetPostByTitleAsync("Teste Atualizado");

            postRepository.Delete(post);
            await postRepository.SaveChangesAsync();

            var result = await postRepository.GetPostByTitleAsync("Teste Atualizado");

            Assert.Null(result);
        }
Пример #27
0
        public async Task Delete_UserDoesNotOwnPost_DoesNotDeletePost()
        {
            var post = new Post {
                Id = 1
            };

            A.CallTo(() => PostRepository.Read(post.Id)).Returns(post);
            A.CallTo(() => User.Is(post.UserId)).Returns(false);

            await PostService.Delete(post.Id);

            A.CallTo(() => PostRepository.Delete(post)).MustNotHaveHappened();
        }
Пример #28
0
        public async Task Delete_EverythingOk_DeletesPost()
        {
            var post = new Post {
                Id = 1
            };

            A.CallTo(() => PostRepository.Read(post.Id)).Returns(post);
            A.CallTo(() => User.Is(post.UserId)).Returns(true);

            await PostService.Delete(post.Id);

            A.CallTo(() => PostRepository.Delete(post)).MustHaveHappenedOnceExactly();
        }
        public IActionResult Delete(int id)
        {
            var currentUserProfile = GetCurrentUserProfile();
            var post = _postRepository.GetById(id);

            if (currentUserProfile.Id != post.UserProfileId)
            {
                return(Unauthorized());
            }

            _postRepository.Delete(id);
            return(NoContent());
        }
Пример #30
0
 public ActionResult Delete(int id, IFormCollection collection)
 {
     try
     {
         // TODO: Add delete logic here
         _postRepo.Delete(id);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Пример #31
0
        public void User_Can_Delete_Post_With_Comment()
        {
            var postIdWithComment = 2;
            var repo = new PostRepository(_context);

            // Attempt to delete it
            repo.Delete(postIdWithComment);

            // Now attempt to get it
            var result = repo.GetById(postIdWithComment);

            Assert.Null(result);
        }
Пример #32
0
        public void Delete_Existing_RecordDeleted()
        {
            Post post = new Post()
            {
                ID = Guid.NewGuid(),
                PostData = "Data",
                PostDate = DateTime.Now,
                RelationID = this.TestPost2.RelationID
            };

            PostRepository Repository = new PostRepository(helper);
            Repository.Insert(post);
            Repository.Delete(post);

            Assert.AreEqual(null, Repository.GetByID(post.ID));
        }
Пример #33
0
 public ActionResult Delete(Guid id)
 {
     IRepository<Post> repo = new PostRepository();
     repo.Delete(repo.GetById(id));
     return RedirectToAction("Index");
 }
Пример #34
0
        public void Delete_NonExisting_ExceptionThrown()
        {
            Post post = new Post()
            {
                ID = Guid.NewGuid(),
                PostData = "Data",
                PostDate = DateTime.Now,
                RelationID = this.TestPost2.RelationID
            };

            PostRepository Repository = new PostRepository(helper);
            Repository.Delete(post);

            Assert.IsNull(Repository.GetByID(post.ID).ID);
        }
Пример #35
0
 public void Delete_NullEntity_ExceptionThrown()
 {
     PostRepository Repository = new PostRepository(helper);
     Repository.Delete(null);
 }
Пример #36
0
 public void GivenABlogEntry_WhenThenFileIsDeleted_AndTheFileIsNotFound_ThenTheCorrectExceptionIsThrown()
 {
     _fileInfo.Setup(f => f.Delete()).Throws(new IOException());
     var entry = new Post { Title = "title", EntryAddedDate = new DateTime(1990, 1, 1) };
     var repository = new PostRepository(Path, _fileInfoFactory.Object, null);
     Assert.Throws<RepositoryException>(() => repository.Delete(entry));
 }
Пример #37
0
        public void GivenABlogEntry_WhenThenFileIsDeleted_ThenTheCorrectFileIsFound()
        {
            string fileName = string.Format("{0}/{1}-{2}-{3}-{4}-{5}.json", Path, "title", 1990, 1, 1, new DateTime(1990, 1, 1).Ticks);

            var entry = new Post { Title = "title", EntryAddedDate = new DateTime(1990, 1, 1) };
            var repository = new PostRepository(Path, _fileInfoFactory.Object, null);
            repository.Delete(entry);
            _fileInfo.Verify(f => f.Delete(), Times.Once());
        }