public void SetUp()
 {
     Repository.Add(new Comment
     {
         Message          = "FirstComment",
         DateTimeCreation = DateTime.Today
     });
 }
Exemple #2
0
 public ActionResult AppUserArticleComment([Bind(Prefix = "Item1")] Article item, [Bind(Prefix = "Item4")] Comment item2)
 {
     if (Session["member"] != null)
     {
         item2.AppUserID = (Session["member"] as AppUser).ID;
     }
     else if (Session["admin"] != null)
     {
         item2.AppUserID = (Session["admin"] as AppUser).ID;
     }
     item2.ArticleID = item.ID;
     comment_repo.Add(item2);
     return(RedirectToAction("DetailsArticle", new { category = Url.FriendlyURLTitle(item.Category.CategoryName), Title = Url.FriendlyURLTitle(item.Title), id = item.ID, catID = item.CategoryID }));
 }
Exemple #3
0
 public ActionResult AddComment(string content, string userId, string ariticleId, string comment_temp)
 {
    
     CommentRepository cr = new CommentRepository();
     UserRepository ur = new UserRepository();
     string result = "";
     if (comment_temp != "null")
     {
         string[] array = comment_temp.Split('#');
         int id = Int32.Parse(array[0]);
         string firstUserId = array[1];
         Comment c = cr.FindByID(id);
         User u = ur.FindByID(userId);
         User firstUser = ur.FindByID(firstUserId);
         c.Isleaf = 1;
         cr.Update(c);
         Comment comment = new Comment();
         comment.UserId = userId;
         comment.AriticleId = ariticleId;
         comment.Content = content;
         comment.NickName = u.NickName;
         comment.FirstNickName = firstUser.NickName;
         comment.Pid = id;
         comment.Isleaf = 0;
         comment.CommentTime = DateTime.Now;
         cr.Add(comment);
         result = "";
         result = JsonConvert.SerializeObject(comment);
     }
     else {
         User u = ur.FindByID(userId);
         Comment comment = new Comment();
         comment.UserId = userId;
         comment.Content = content;
         comment.CommentTime = DateTime.Now;
         comment.AriticleId = ariticleId;
         comment.Pid = 0;
         comment.Isleaf = 0;
         comment.Level = 1;
         comment.NickName = u.NickName;
         comment.FirstNickName = null;
         cr.Add(comment);
         result = "";
         result = JsonConvert.SerializeObject(comment);
         ;
     }
     return Content(result);
 }
        public ActionResult Create(Comment comment)
        {
            if (ModelState.IsValid)
            {
                comment.IPAddress = Request.UserHostAddress;
                comment.Date      = DateTime.Now;
                comment.UserId    = User.Identity.GetUserId();

                try
                {
                    _commentRepo.Add(comment);
                    _commentRepo.SaveChanges();

                    TempData["Message"] = "Komentarz został dodany!";
                    return(RedirectToAction("Details", "Service", new { id = comment.ServiceId }));
                }
                catch (Exception)
                {
                    TempData["Error"] = "Wystąpił błąd podczas zapisywania!";
                    return(RedirectToAction("Details", "Service", new { id = comment.ServiceId }));
                }
            }

            TempData["Error"] = "Uzupełnij poprawnie formularz!";
            return(View(comment));
        }
        public ActionResult Create(int id, FormCollection collection)
        {
            // Utworzenie komentarza
            Comment comment = new Comment();

            if (ModelState.IsValid)
            {
                // Uaktualnienie danych komentarza
                if (TryUpdateModel(comment))
                {
                    // Uzupełnienie danych komentarza o datę dodania, adres IP, ID użytkownika dodającego komentarz oraz ID firmy
                    comment.Date      = DateTime.Now;
                    comment.IPAddress = Request.UserHostAddress;
                    comment.UserId    = WebSecurity.CurrentUserId;
                    comment.ServiceId = id;

                    // Dodanie komentarza i zapisanie zmian w bazie danych
                    _commentRepo.Add(comment);
                    _commentRepo.SaveChanges();

                    return(RedirectToAction("Details", "Company", new { id = comment.ServiceId }));
                }
            }

            TempData["Error"] = "Wystąpił błąd podczas dodawania komentarza!";
            return(View());
        }
Exemple #6
0
        public void SetUp()
        {
            InfrastructureTestsSeed.SeedAll(Context);

            Result  result  = Context.Results.FirstOrDefault();
            Student student = Context.Students.FirstOrDefault();
            User    user    = Context.Users.FirstOrDefault();

            Repository.Add(new Comment
            {
                AssessmentId     = result.AssessmentId,
                StudentId        = result.StudentId,
                UserId           = user.Id,
                Message          = "FirstComment",
                DateTimeCreation = DateTime.Today
            });
        }
        public JsonResult AddComment(VM_Comment vm)
        {
            vm.IPAddress = Request.UserHostAddress;
            vm.Datetime  = DateTime.Now;
            var res = repo.Add(vm);

            return(Json(res, JsonRequestBehavior.AllowGet));
        }
        public IActionResult Post(Comment comment)
        {
            var currentUser = GetCurrentUser();

            comment.UserId = currentUser.Id;

            _commentRepo.Add(comment);
            return(CreatedAtAction("Get", new { id = comment.Id }, comment));
        }
Exemple #9
0
        public IActionResult Comment(Comment comment)
        {
            var currentUserProfile = GetCurrentUserProfile();

            comment.UserProfileId  = currentUserProfile.Id;
            comment.CreateDateTime = DateTime.Now;
            _commentRepository.Add(comment);
            return(CreatedAtAction("Get", new { id = comment.Id }, comment));
        }
        public IActionResult Add([FromQuery] string textarea, string input)
        {
            var userId  = _userRepository.GetUserByLogin(Request.Cookies["userLogin"]).Id;
            var login   = _userRepository.GetUserById(userId).Login;
            var comment = _repository.Add(userId, Guid.Parse(input), textarea) ?? throw new ArgumentException();

            comment.UserLogin = login;
            return(Json(comment));
        }
Exemple #11
0
        public void FindCommentTest()
        {
            //arrange
            var userModel = new UserModel()
            {
                Name        = "Pepa Hnátek",
                LastLogged  = DateTime.Today,
                MailAddress = "*****@*****.**"
            };
            var userRepository = new UserRepository(dbContextFactory, mapper);

            userModel = userRepository.Add(userModel);

            var teamModel = new TeamModel
            {
                Description = "Tym resici ics",
                Name        = "Borci"
            };
            var teamRepository = new TeamRepository(dbContextFactory, mapper);

            teamModel = teamRepository.Add(teamModel);
            teamRepository.AddUserToTeam(teamModel.Id, userModel.Id);

            var postModel = new PostModel
            {
                Title       = "Hlava",
                Author      = userModel,
                Text        = "Ztratil jsem hlavu!",
                TimeCreated = DateTime.Now,
                Team        = teamModel
            };
            var postRepository = new PostRepository(dbContextFactory, mapper);

            postModel = postRepository.Add(postModel);

            var comment1 = new CommentModel
            {
                Author      = userModel,
                ParentPost  = postModel,
                Text        = "Hledej, dìlej!!",
                TimeCreated = DateTime.Now
            };
            var commentRepository = new CommentRepository(dbContextFactory, mapper);

            commentRepository.Add(comment1);
            //act
            var commentsShouldBeFound    = commentRepository.FindByText("dìlej", teamModel);
            var commentsShouldNotBeFound = commentRepository.FindByText("alohomora", teamModel);

            //assert
            Assert.NotEmpty(commentsShouldBeFound);
            Assert.Empty(commentsShouldNotBeFound);

            teamRepository.Remove(teamModel.Id); //should remove also the post and comment
            userRepository.Remove(userModel.Id);
            Assert.Null(postRepository.getById(postModel.Id));
        }
        public void AddReturnsId()
        {
            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            var response = repository.Add(new Comment());

            Assert.IsNotNull(response);
            Assert.AreEqual(response.Id, 1);
        }
Exemple #13
0
        public void AddCommentTest()
        {
            var userRepository = new UserRepository(dbContextFactory, mapper);
            var teamRepository = new TeamRepository(dbContextFactory, mapper);

            var userModel = new UserModel
            {
                Name        = "Pepa Hnátek",
                LastLogged  = DateTime.Today,
                MailAddress = "*****@*****.**"
            };

            var teamModel = new TeamModel
            {
                Description = "Tym resici ics",
                Name        = "Borci"
            };

            userModel = userRepository.Add(userModel);
            teamModel = teamRepository.Add(teamModel);
            teamRepository.AddUserToTeam(teamModel.Id, userModel.Id);
            userModel = userRepository.GetById(userModel.Id);
            teamModel = teamRepository.GetById(teamModel.Id);

            var postRepository    = new PostRepository(dbContextFactory, mapper);
            var commentRepository = new CommentRepository(dbContextFactory, mapper);
            var postModel         = new PostModel
            {
                Title       = "Hlava",
                Author      = userModel,
                Text        = "Ztratil jsem hlavu!",
                TimeCreated = DateTime.Now,
                Team        = teamModel
            };

            postModel = postRepository.Add(postModel);

            var commentModel = new CommentModel
            {
                Text        = "Tak ji zase najdi.",
                TimeCreated = DateTime.Now,
                Author      = userModel,
                ParentPost  = postModel
            };

            commentModel = commentRepository.Add(commentModel);

            //assert
            Assert.Equal("Tak ji zase najdi.", commentRepository.getById(commentModel.Id).Text);
            Assert.Equal("Tak ji zase najdi.", postRepository.getById(postModel.Id).Comments.First().Text);

            teamRepository.Remove(teamModel.Id); //should remove also the post and comment
            userRepository.Remove(userModel.Id);
            Assert.Null(postRepository.getById(postModel.Id));
            Assert.Null(commentRepository.getById(commentModel.Id));
        }
        public IActionResult Content(IFormCollection form)
        {
            CommentModel model = new CommentModel();

            model.TopicID    = 2;
            model.Content    = Request.Form["content"];
            model.CreateTime = DateTime.Now;
            _commentRepository.Add(model);
            return(View("Index"));
        }
Exemple #15
0
 static public void addComment(Comment comment)
 {
     using (CommentRepository commentrepo = new CommentRepository())
     {
         commentrepo.context.Entry(comment.user).State = EntityState.Unchanged;
         commentrepo.context.Entry(comment.zone).State = EntityState.Unchanged;
         commentrepo.Add(comment);
         commentrepo.Save();
     }
 }
Exemple #16
0
        public IActionResult AddComment(CommentModel comment)
        {
            if (!ModelState.IsValid)
            {
                return(View(comment));
            }

            _commentRepository.Add(comment);
            return(RedirectToAction("Details", "Ticket", comment.TicketId));
        }
        public void YorumEkle(string comment, int User_id, int Org_Id)
        {
            Comment cmt = new Comment();

            cmt.Yorum             = comment;
            cmt.OrganizationYorum = _Orgrep.Find(Org_Id);
            cmt.UserYorum         = _userrep.Find(User_id);
            cmt.YorumTime         = DateTime.Now;
            _comRep.Add(cmt);
        }
Exemple #18
0
        public async Task <ActionResult <CommentResponse> > Create(CommentRequest commentRequest)
        {
            var comment = MapRequestToModel(commentRequest);

            comment = await _commentRepository.Add(comment);

            var commentResponse = MapModelToResponse(comment);

            return(commentResponse);
        }
        public void Add(CommentDTO comment, string username, int id)
        {
            Comment newcomment = new Comment
            {
                ApplicationUserId = username,
                Message           = comment.Message,
                FeedbackId        = id,
            };

            _repo.Add(newcomment);
        }
Exemple #20
0
 public void Add(string description)
 {
     if (!string.IsNullOrEmpty(description))
     {
         _commentRepository.Add(new CommentModel()
         {
             Description = description,
             Date        = System.DateTime.Now
         });
     }
 }
Exemple #21
0
        public async Task TestAddComment()
        {
            var comment = new TblComment();

            comment.Comment = "Soo awesome";

            comment.CommentId = Guid.NewGuid();
            comment.UserId    = Guid.NewGuid();
            comment.CommentId = Guid.NewGuid();
            Assert.True(await repo.Add(comment));
        }
        public string AddComment(int orgId, string Comment)
        {
            Comment com = new Comment();

            com.Comment1     = Comment;
            com.Organization = orgrep.Get(orgId);
            com.CommentDate  = DateTime.Now;
            com.Participant  = partrep.Get(1);
            commentrep.Add(com);

            return(com.Comment1);
        }
        public int Add(Comment model)
        {
            var time = DateTime.Now;

            model.CreateTime = time;
            model.UpdateTime = time;
            model.Enable     = 1;

            var id = _commentRepository.Add(model);

            return(id);
        }
Exemple #24
0
 public CommentDetailModel Save(CommentDetailModel model)
 {
     if (model.Id == Guid.Empty)
     {
         return(repository.Add(model));
     }
     else
     {
         repository.Update(model);
         return(model);
     }
 }
        public void AddComment_AddNull_ThrowsException()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FacilityContext(options);
            ICommentRepository commentRepository = new CommentRepository(context);

            // Act & Assert
            Assert.ThrowsException <ArgumentNullException>(() => commentRepository.Add(null));
        }
Exemple #26
0
 public ActionResult Create(Comment comment, string userid, int postid)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     user = UserManager.FindById(User.Identity.GetUserId());
     comment.CurrentUserId = userid;
     comment.CurrentPostId = postid;
     repository.Add(comment);
     repository.SaveChanges();
     return(RedirectToAction("List", "NewsFeed"));
 }
Exemple #27
0
        public ActionResult AddComment(Comment model)
        {
            if (ModelState.IsValid)
            {
                model.Post          = _postRepository.FindBy(model.PostId);
                model.CommentedDate = DateTime.Now;
                model.IsActive      = false;
                _commentRepository.Add(model);

                return(Json(true, "_AddComment"));
            }

            return(Json(false, "_AddComment"));
        }
Exemple #28
0
        public ActionResult AddComment(int id, string text)
        {
            Comment dbComment = new Comment();

            dbComment.CreatedOn     = DateTime.Now;
            dbComment.LastUpdatedOn = DateTime.Now;
            dbComment.UserId        = User.Identity.GetUserId();
            dbComment.PostId        = id;
            dbComment.Text          = text;

            _commentRepository.Add(dbComment);
            _context.SaveChanges();
            return(RedirectToAction("Details", "Post", new { id = id }));
        }
Exemple #29
0
        public void ThrowsExceptionWhenANonExistingIdIsProvided()
        {
            var options = new DbContextOptionsBuilder <EvaluationContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using (var memoryContext = new EvaluationContext(options))
            {
                // Act
                ICommentRepository repository = new CommentRepository(memoryContext);
                // Arrange Assert
                Assert.ThrowsException <ArgumentNullException>(() => repository.Add(null));
            }
        }
        public void AddPersists()
        {
            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            repository.Add(new Comment { Message = "Test Item" });

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

                                  Assert.AreEqual(response.Count, 1);
                                  Assert.AreEqual(response[0].Message, "Test Item");
                              });
        }
 public ActionResult Create(Comment comment, int id)
 {
     try
     {
         comment.UserProfileId = GetCurrentUserProfileId();
         comment.PostId        = id;
         _commentRepository.Add(comment);
         return(RedirectToAction("CommentsIndex", new { id = id }));
     }
     catch
     {
         return(View(comment));
     }
 }
Exemple #32
0
        public void CanDeleteCommentsFromPostgre()
        {
            var commentRepository = new CommentRepository(dbConnectionString);
            var articleId         = Guid.NewGuid();
            var commentText       = "Test Text";
            var commentUserName   = "******";

            var secondcommentText     = "Second Test Text";
            var secondcommentUserName = "******";

            commentRepository.Add(new Comment
            {
                Text      = commentText,
                Author    = commentUserName,
                ArticleId = articleId
            });

            commentRepository.Add(new Comment
            {
                Text      = secondcommentText,
                Author    = secondcommentUserName,
                ArticleId = articleId
            });

            List <Comment> comments = commentRepository.GetAll();

            Assert.IsNotEmpty(comments);

            comments.Reverse();
            List <Guid> commentsToDelete = comments.Take(2).Select(x => x.Id).ToList();

            commentRepository.Delete(commentsToDelete);
            Comment comment = commentRepository.Get(commentsToDelete.First()).Value;

            Assert.IsNull(comment);
        }
Exemple #33
0
        public void Add_And_Presist_Changes_Should_Succeed()
        {
            using (BeginTransaction())
            {
                var story = GenerateStoryGraph();
                _database.InsertOnSubmit(story);
                _database.SubmitChanges();

                var comment = CreateNewComment(story, story.User, "some content");
                _commentRepository.Add(comment);
                Assert.Equal(EntityState.Added, comment.EntityState);
                _database.SubmitChanges();
                Assert.Equal(EntityState.Unchanged, comment.EntityState);
            }
        }
        public void AddComment_Added_NotFail_Test()
        {
            var context = new MyEventsContext();
            int sessionId = context.Sessions.FirstOrDefault().SessionId;
            int registeredUserId = context.RegisteredUsers.FirstOrDefault().RegisteredUserId;
            int expected = context.Comments.Count() + 1;

            ICommentRepository target = new CommentRepository();
            Comment comment = new Comment();
            comment.SessionId = sessionId;
            comment.AddedDateTime = DateTime.UtcNow;
            comment.RegisteredUserId = registeredUserId;
            comment.Text = "sample comment";
            target.Add(comment);

            int actual = context.Comments.Count();

            Assert.AreEqual(expected, actual);
        }