public void CommentRepozitoryTest()
        {
            var Repository = new CommentRepository(new InMemoryDbContextFactory());

            Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(0));

            var Comment1 = new CommentModel()
            {
                Author     = 1,
                AuthorName = "Milos Hlava",
                Date       = new DateTime(2019, 1, 4),
                Id         = 1,
                Text       = "Testovaci koment"
            };

            var Comment2 = new CommentModel()
            {
                Author     = 2,
                AuthorName = "Jozef Hlava",
                Date       = new DateTime(2019, 1, 5),
                Id         = 2,
                Text       = "Testovaci koment cislo 2"
            };

            Repository.Create(Comment1);
            Repository.Create(Comment2);
            var ReceivedComment1 = Repository.GetById(1);
            var ReceivedComment2 = Repository.GetById(2);

            Assert.Equal(Comment1, ReceivedComment1);
            Assert.Equal(Comment2, ReceivedComment2);

            Comment1.Text = "Updatovany text";
            Repository.Update(Comment1);
            ReceivedComment1 = Repository.GetById(1);

            Assert.Equal(Comment1, ReceivedComment1);

            List <CommentModel> ReceivedAllComments = Repository.GetAll();

            var AllComments = new List <CommentModel>();

            AllComments.Add(Comment1);
            AllComments.Add(Comment2);

            var Comparer = new CollectionComparer <CommentModel>();

            Assert.True(Comparer.Equals(AllComments, ReceivedAllComments));

            Repository.Delete(1);

            Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(1));

            Repository.Delete(2);

            Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(2));
        }
Exemple #2
0
 /// <summary>
 /// 删除一个评论
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="id">一评论的主键</param>
 /// <returns></returns>
 public bool Delete(ref ValidationErrors validationErrors, string id)
 {
     try
     {
         return(repository.Delete(id) == 1);
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
        public async Task <ActionResult> DeleteComment(int id)
        {
            //  var userPost = await db.UserPosts.FindAsync( id);

            var comment = await _cRepository.FindById(id);

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

            await _cRepository.Delete(comment);

            return(RedirectToAction("Index", "Home"));
        }
Exemple #4
0
        /// <summary>
        /// Handles the item command
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void rptComments_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            switch (e.CommandName)
            {
            case "DeleteComment":

                repository.Delete(new Guid(e.CommandArgument.ToString()));
                break;

            case "ApproveComment":

                Comment c = repository.Fetch(new Guid(e.CommandArgument.ToString()));
                if (c != null)
                {
                    c.ModerationStatus = Comment.ModerationApproved;
                    repository.Save(c);
                }

                break;
            }


            if (updateContainerControl != null)
            {
                int commentCount = repository.GetCount(ContentGuid, Comment.ModerationApproved);
                updateContainerControl.UpdateCommentStats(
                    ContentGuid,
                    commentCount);
            }

            WebUtils.SetupRedirect(this, Request.RawUrl);
        }
Exemple #5
0
        public async Task DeleteComment(int commentId)
        {
            var comment = await _commentRepository.GetByIdAsync(commentId);

            _commentRepository.Delete(comment);
            await _unitOfWork.Commit();
        }
        public ActionResult Delete(int id)
        {
            // Pobranie komentarza po identyfikatorze
            var comment = _commentRepo.GetCommentById(id);

            if (comment != null)
            {
                try
                {
                    // Usunięcie komentarza i zapisanie zmian w bazie danych
                    _commentRepo.Delete(comment);
                    _commentRepo.SaveChanges();
                    TempData["Message"] = "Komentarz został usunięty.";
                }
                catch (Exception)
                {
                    TempData["Error"] = "Nie można usunąć tego komentarza.";
                }

                return(RedirectToAction("Details", "Company", new { id = comment.ServiceId }));
            }
            else
            {
                TempData["Error"] = "Nie ma takiego komentarza.";
                return(RedirectToAction("Index", "Company"));
            }
        }
Exemple #7
0
        public async Task DeleteComment()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <MyAlbumDbContext>()
                          .UseInMemoryDatabase(databaseName: "CommentRepository_DeleteComment_MyAlbumDatabase")
                          .Options;

            using (var context = new MyAlbumDbContext(options))
            {
                UnitOfWork        unitOfWork        = new UnitOfWork(context);
                int               seedCommentId     = new Random().Next(1, 100);
                List <Comment>    seedComments      = SeedComments(seedCommentId, context).ToList();
                CommentRepository commentRepository = new CommentRepository(context);
                Comment           deletedComment    = seedComments[0];
                // Assert #1
                Assert.Equal(seedComments.Count(), context.Comments.Count());
                // Act
                commentRepository.Delete(deletedComment);
                await unitOfWork.CompleteAsync();

                // Assert #2
                seedComments.Remove(deletedComment);
                Assert.True(seedComments.SequenceEqual(context.Comments));
            }
        }
Exemple #8
0
        public void Delete(Product product)
        {
            //_repo.UnitOfWork.LazyLoadingEnabled = true;
            //_repo_Comment.UnitOfWork.LazyLoadingEnabled = true;

            try
            {
                List <Comment> Comments = product.Comment.ToList();

                foreach (var item in Comments)
                {
                    _repo_Comment.Delete(item);
                }

                _repo_Comment.UnitOfWork.Commit();

                _repo.Delete(product);
                this.Save();
            }
            finally
            {
                //_repo_Comment.UnitOfWork.LazyLoadingEnabled = false;
                //_repo.UnitOfWork.LazyLoadingEnabled = false;
            }
        }
        public async Task <ActionResult <CommentResponse> > DeleteComment(long id)
        {
            var comment = await _commentRepository.Delete(id);

            var commentResponse = MapModelToResponse(comment);

            return(commentResponse);
        }
Exemple #10
0
        public ActionResult DeleteReply(int id)
        {
            Comment           comment           = new Comment();
            CommentRepository commentRepository = new CommentRepository();

            comment = commentRepository.GetById(id);
            commentRepository.Delete(comment);
            return(RedirectToAction("Articles"));
        }
        public void DeleteByNullValue()
        {
            // Arrange
            CommentRepository commentRepository = new CommentRepository(dbContext);

            // Act
            // Assert
            Assert.ThrowsException <ArgumentNullException>(() => commentRepository.Delete(entityToDelete: null));
        }
        public IActionResult Delete(int id)
        {
            List <Comment> ItemCommentsToDelete = _commentRepository.GetByItemId(id);

            ItemCommentsToDelete.ForEach(ic => _commentRepository.Delete(ic));

            _itemRepository.Delete(id);
            return(NoContent());
        }
        public void DeleteByNullKey_Exception()
        {
            // Arrange
            CommentRepository commentRepository = new CommentRepository(dbContext);
            object            wrongId           = null;

            // Act
            // Assert
            Assert.ThrowsException <ArgumentNullException>(() => commentRepository.Delete(wrongId));
        }
        public void DeleteByWrongKey_Exception()
        {
            // Arrange
            CommentRepository commentRepository = new CommentRepository(dbContext);
            Guid wrongId = default(Guid);

            // Act
            // Assert
            Assert.ThrowsException <InvalidOperationException>(() => commentRepository.Delete(wrongId));
        }
Exemple #15
0
        internal Comment Delete(int id, string email)
        {
            Comment toDelete = Get(id);

            if (toDelete.Author != email || !_repo.Delete(id, email))
            {
                throw new UnauthorizedAccessException("Invalid Access");
            }
            return(toDelete);
        }
 public IHttpActionResult Delete(int cid)
 {
     //Comment comment = commentRepository.Get(cid);
     //if(comment == null)
     //{
     //    return StatusCode(HttpStatusCode.NoContent);
     //}
     commentRepository.Delete(cid);
     return(StatusCode(HttpStatusCode.NoContent));
 }
Exemple #17
0
 public void DeleteComment(int id)
 {
     try
     {
         _repository.Delete(id);
     }
     catch (Exception e)
     {
     }
 }
        public IHttpActionResult DeleteComment(int id, int cid)
        {
            Comment comment = comRepo.GetAll().Where <Comment>(x => x.CommentId == cid && x.PostId == id).FirstOrDefault();

            if (comment == null)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            comRepo.Delete(cid);
            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #19
0
        public void Delete_Void_ReturnNull()
        {
            _comment.Id = _commentRepository.Create(_comment);
            var result = _commentRepository.Get(_comment.Id);

            AreEqualComments(result, _comment);

            _commentRepository.Delete(_comment.Id);
            result = _commentRepository.Get(_comment.Id);
            Assert.IsNull(result);
        }
Exemple #20
0
        public ActionResult DeleteComment(int id)
        {
            List <Comment>    comments          = new List <Comment>();
            CommentRepository commentRepository = new CommentRepository();

            comments = commentRepository.GetAll(filter: c => c.Id == id || c.ParentComment.Id == id);
            foreach (var comment in comments)
            {
                commentRepository.Delete(comment);
            }
            return(RedirectToAction("Articles"));
        }
        public IHttpActionResult DeleteCommentWithId(int cid, int id)
        {
            CommentRepository cr = new CommentRepository();
            Comment           c  = cr.GetById(cid);

            if (c.PostId == id)
            {
                cr.Delete(cid);
                return(StatusCode(HttpStatusCode.NoContent));
            }
            return(StatusCode(HttpStatusCode.NotFound));
        }
        public IHttpActionResult Delete(int id)
        {
            ReplyRepository r       = new ReplyRepository();
            var             replist = con.Replies.Where(x => x.ComID == id).ToList();

            foreach (var x in replist)
            {
                r.Delete(x.ReplyId);
            }
            cr.Delete(id);
            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #23
0
        public void TestEntityDelete()
        {
            var comment = CommentBuilder.New().Build();

            var mockTeste = new Mock <IDeleteDB <Comment> >();

            var commentRepository = new CommentRepository(mockTeste.Object);

            commentRepository.Delete(comment);

            mockTeste.Verify(x => x.DeleteRegister(It.IsAny <Comment>()));
        }
        //
        // GET: /Comment/Delete/5
        public ActionResult Delete(int id, int taskId)
        {
            var commentDB = commentRepository.Search(id);

            if (commentDB.UserId != User.Identity.GetUserId())
            {
                ModelState.AddModelError("", "No rights to delete this comment!");
                return(RedirectToAction("Details", "Task", new { id = taskId }));
            }
            commentRepository.Delete(id);
            return(RedirectToAction("Details", "Task", new { id = taskId }));
        }
        /// <summary>
        /// Delete selected document.
        /// </summary>
        void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Document selectedDocument = documentRepository.GetDocumentByVersion(
                listView1.SelectedItems[0].Text, int.Parse(listView1.SelectedItems[0].SubItems[1].Text));

            bool operationAllowed = false;

            if (selectedDocument.Owner.Equals(loggedEmployee))
            {
                operationAllowed = true;
            }
            else if (selectedDocument.Writers.Contains(loggedEmployee))
            {
                operationAllowed = true;
            }

            if (operationAllowed)
            {
                if (MessageBox.Show("Are you sure you want to delete seleceted document",
                                    "Confirmation dialog", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    foreach (Comment comment in commentRepository.GetCommentsForDocument(selectedDocument))
                    {
                        commentRepository.Delete(comment);
                    }

                    foreach (Employee employee in selectedDocument.Readers)
                    {
                        employee.Reading.Remove(selectedDocument);
                        employeeRepository.Update(employee);
                    }

                    foreach (Employee employee in selectedDocument.Writers)
                    {
                        employee.Reading.Remove(selectedDocument);
                        employeeRepository.Update(employee);
                    }

                    documentContentRepository.Delete(selectedDocument.Content);
                    documentRepository.Delete(selectedDocument);

                    populateLists();
                    updateListView(ownDocuments, readableDocuments, writableDocuments);

                    this.documentToolStripMenuItem.Enabled = false;
                }
            }
            else
            {
                MessageBox.Show("Only user with write permission can delete document.");
            }
        }
        public void DeleteComment_NoExists_NotFail_Test()
        {
            var context = new MyEventsContext();
            var comment = context.Comments.FirstOrDefault();
            int expected = context.Comments.Count();

            ICommentRepository target = new CommentRepository();
            target.Delete(0);

            int actual = context.Comments.Count();

            Assert.AreEqual(expected, actual);
        }
        public async Task <ActionResult <Comment> > DeleteComment(int id)
        {
            var chat = await _repository.Delete(id);

            if (chat != null)
            {
                return(chat);
            }
            else
            {
                return(NotFound());
            }
        }
Exemple #28
0
        public void DeleteComment(string key, long id)
        {
            Comment comment = _repository.Get(id);

            if (comment.Author.Id == CurrentUserId) //TODO: check admin or security rights
            {
                _repository.Delete(comment);
            }
            else
            {
                throw new SecurityException("Unauthorized");
            }
        }
Exemple #29
0
        public ActionResult Delete(int id)
        {
            if (AuthenticationManager.LoggedUser == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            CommentRepository RepoComment = RepositoryFactory.GetCommentRepository();
            Comment           comment     = RepoComment.GetById(id);

            RepoComment.Delete(comment);

            return(RedirectToAction("Index", "CommentManagement", new { ParentTaskId = comment.ParentTaskId }));
        }
        public IActionResult DeleteCommentById(int id)
        {
            Comment comment = (from c in _commentRepository.Get()
                               where c.Id == id
                               select c)
                              .SingleOrDefault();

            if (null != comment)
            {
                _commentRepository.Delete(comment);
                _commentRepository.Save();
            }
            return(Ok());
        }
Exemple #31
0
        public ActionResult DeleteComment(int id)
        {
            if (AuthenticationManager.LoggedUser == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            CommentRepository comrepo = RepositoryFactory.GetCommentRepository();
            Comment           comment = comrepo.GetByID(id);

            comrepo.Delete(comment);

            return(RedirectToAction("TaskDetails", "TaskManagement", new { id = comment.CommenterID }));
        }
        public void DeleteFails()
        {
            dbFactory.Run(db => db.Insert(new Comment { Id = 1, Message = "Test Item" }));

            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            repository.Delete(2);
            dbFactory.Run(db =>
                              {
                                  var response = db.Select<Comment>();

                                  Assert.AreEqual(response.Count, 1);
                                  Assert.AreEqual(response[0].Message, "Test Item");
                              });
        }
 public ActionResult DeleteComment(int id)
 {
     List<Comment> comments = new List<Comment>();
     CommentRepository commentRepository = new CommentRepository();
     comments = commentRepository.GetAll(filter: c => c.Id == id || c.ParentComment.Id == id);
     foreach (var comment in comments)
     {
         commentRepository.Delete(comment);
     }
     return RedirectToAction("Articles");
 }
 public ActionResult DeleteReply(int id)
 {
     Comment comment = new Comment();
     CommentRepository commentRepository = new CommentRepository();
     comment = commentRepository.GetById(id);
     commentRepository.Delete(comment);
     return RedirectToAction("Articles");
 }