Esempio n. 1
0
 public void Add(Comment comment)
 {
     if (comment != null)
     {
         commentsRepository.AddComment(comment);
     }
 }
Esempio n. 2
0
        public ActionResult Create(Comment comment)
        {
            comment.UserId          = User.Identity.GetUserId();
            comment.Created         = DateTime.Now;
            comment.ProjectTask     = projectTasksRepo.GetProjectTaskById(comment.ProjectTaskId);
            comment.ApplicationUser = usersRepo.GetUserById(User.Identity.GetUserId());

            if (!(coursesRepo.IsInCourse(comment.ProjectTask.Project.Course.Id, comment.UserId, User.IsInRole("Administrator"))))
            {
                throw new HttpException((int)HttpStatusCode.Forbidden, "Forbidden!");
            }

            commentsRepo.AddComment(comment);

            if (Request.IsAjaxRequest())
            {
                var commentsHelper = new CommentsHelper();

                var commentsFromProjectTask = commentsRepo.GetCommentsForProjectTaskId(comment.ProjectTaskId);
                var comments = commentsHelper.CommentViewModelsFromComments(commentsFromProjectTask, User.IsInRole("Administrator"), User.Identity.GetUserId()).ToList();
                return(Json(comments, JsonRequestBehavior.AllowGet));
            }

            ViewBag.AllUsers = db.Users.ToList();
            return(View("~/Views/ProjectTasks/Details.cshtml", comment.ProjectTask));
        }
Esempio n. 3
0
        public UserCommentViewModel AddUserComment(string comment, int id, string userWho, string userTo)
        {
            Post   post = _postsRepository.GetPostById(id);
            string time = DateTime.Now.ToString("dd.MM.yyyy HH:mm");
            UserCommentViewModel postComment = FillViewComment(comment, id, userWho, userTo, time);
            Comment userComment = FillPostComment(comment, id, userWho, userTo, time, post);

            _commentsRepository.AddComment(userComment, post);

            return(postComment);
        }
        public async void AddToken_CheckCallOfAddMethodInDbSet()
        {
            var mockDbContext     = new Mock <DatabaseContext>();
            var mockDbSetComments = new Mock <DbSet <Comment> >();

            mockDbSetComments
            .Setup(a => a.Add(new Comment()))
            .Returns(
                () =>
            {
                Assert.True(true);
                return(null);
            });
            mockDbContext.Setup(a => a.Comments).Returns(mockDbSetComments.Object);

            var commentsRepo = new CommentsRepository(mockDbContext.Object);

            await commentsRepo.AddComment(new DomainModels.Comment()
            {
                Author = new DomainModels.User()
            });
        }
 public void AddComment(CommentsModel newComment)
 {
     _commentsRepository.AddComment(newComment);
 }