コード例 #1
0
        public void Comment_ShouldCallPostServiceGetById()
        {
            // Arrange
            var categoryServiceMock = new Mock <ICategoryService>();
            var postServiceMock     = new Mock <IPostService>();
            var voteServiceMock     = new Mock <IVoteService>();
            var commentServiceMock  = new Mock <ICommentService>();
            var userManagerMock     = new Mock <IApplicationUserManager>();
            var mapperMock          = new Mock <IMapper>();

            var controller = new PostsController(
                categoryServiceMock.Object,
                postServiceMock.Object,
                voteServiceMock.Object,
                commentServiceMock.Object,
                userManagerMock.Object,
                mapperMock.Object);
            var model = new CommentAddViewModel();

            // Act
            var result = controller.Comment(model);

            // Assert
            postServiceMock.Verify(x => x.GetById(It.IsAny <Guid>(), It.IsAny <bool>()), Times.Once);
        }
コード例 #2
0
        public ActionResult AddComment(CommentAddViewModel commentAddViewModel)
        {
            if (!commentAddViewModel.Validate().IsValid)
            {
                return(this.Issue404());
            }

            // Normalize the Line Breaks
            commentAddViewModel.CommentText = commentAddViewModel.CommentText.Replace("\n", Environment.NewLine);

            switch (commentAddViewModel.CommentType)
            {
            case CommentType.Recipe:
                RecipeComment recipeComment;

                using (var unitOfWork = this.UnitOfWorkFactory.NewUnitOfWork())
                {
                    recipeComment             = new RecipeComment();
                    recipeComment.CommentText = commentAddViewModel.CommentText;
                    recipeComment.RecipeId    = commentAddViewModel.GenericId;
                    this.RecipeService.AddRecipeComment(recipeComment);
                    unitOfWork.Commit();
                }

                // Queue Comment Notification
                this.NotificationService.QueueNotification(NotificationType.RecipeComment, recipeComment);
                break;

            case CommentType.Session:
                BrewSessionComment brewSessionComment;

                using (var unitOfWork = this.UnitOfWorkFactory.NewUnitOfWork())
                {
                    brewSessionComment               = new BrewSessionComment();
                    brewSessionComment.CommentText   = commentAddViewModel.CommentText;
                    brewSessionComment.BrewSessionId = commentAddViewModel.GenericId;
                    this.RecipeService.AddBrewSessionComment(brewSessionComment);
                    unitOfWork.Commit();
                }

                // Queue Comment Notification
                this.NotificationService.QueueNotification(NotificationType.BrewSessionComment, brewSessionComment);
                break;

            default:
                return(this.Issue404());
            }

            var commentViewModel = new CommentViewModel();

            commentViewModel.CommentText   = commentAddViewModel.CommentText;
            commentViewModel.UserId        = this.ActiveUser.UserId;
            commentViewModel.UserName      = this.ActiveUser.Username;
            commentViewModel.UserAvatarUrl = UserAvatar.GetAvatar(59, this.ActiveUser.EmailAddress);
            commentViewModel.DateCreated   = DateTime.Now;

            return(View("_Comment", commentViewModel));
        }
コード例 #3
0
        public ActionResult Add(int irregularityId, CommentAddViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                string userId = User.Identity.GetUserId();
                this.comments.Add(model.Content, irregularityId, userId);
                return(this.Redirect(this.Request.UrlReferrer.ToString()));
            }

            return(this.Redirect(this.Request.UrlReferrer.ToString()));
        }
コード例 #4
0
        public ActionResult AddComment(CommentAddViewModel vm)
        {
            var comment = Mapper.Map <CommentAddViewModel, Comment>(vm);

            comment.UserId = User.Identity.GetUserId();

            db.Comments.Add(comment);

            db.SaveChanges();

            return(Json(new { Success = true }));
        }
コード例 #5
0
        public async Task <IActionResult> Index()
        {
            var appUser = await _userManager.FindByNameAsync(User.Identity.Name);

            var userId = appUser.Id;

            TempData["userId"] = userId;
            var model = new CommentAddViewModel();

            model.Books = GetAppUserBookSelectListItems();
            return(View(model));
        }
コード例 #6
0
        public async Task <IActionResult> AddComment(CommentAddViewModel commentAddViewModel)
        {
            if (!ModelState.IsValid || !commentAddViewModel.Email.EmailValidation())
            {
                return(Json(new JsonResultModel <CommentAddViewModel>(false, "Model is not valid.")));
            }
            var model  = commentAddViewModel.Adapt <Comment>();
            var result = await _commentService.Create(model);

            if (!result.Success || result.Data == null)
            {
                return(Json(new JsonResultModel <CommentAddViewModel>(false, "Model is not valid.")));
            }
            return(Json(new JsonResultModel <CommentAddViewModel>(true, "Model is valid.")));
        }
コード例 #7
0
        private async Task CheckPathAndAddComment(CommentAddViewModel commentModel, string path)
        {
            if (path == "cars")
            {
                var CarComment = new Comment
                {
                    Message   = commentModel.Description,
                    CreatorId = commentModel.UserId,
                };
                await this.db.Comments.AddAsync(CarComment);

                await this.db.SaveChangesAsync();

                await this.db.CarComments.AddAsync(new CarComments { CommentId = CarComment.Id, CarId = commentModel.Id });

                await this.db.SaveChangesAsync();
            }
            else if (path == "blogs")
            {
                var BlogComment = new Comment
                {
                    Message   = commentModel.Description,
                    CreatorId = commentModel.UserId,
                };
                await this.db.Comments.AddAsync(BlogComment);

                await this.db.SaveChangesAsync();

                await this.db.BlogComments.AddAsync(new BlogComments { CommentId = BlogComment.Id, BlogId = commentModel.Id });

                await this.db.SaveChangesAsync();
            }
            else
            {
                var ProductComment = new Comment
                {
                    Message   = commentModel.Description,
                    CreatorId = commentModel.UserId,
                };
                await this.db.Comments.AddAsync(ProductComment);

                await this.db.SaveChangesAsync();

                await this.db.ProductComments.AddAsync(new ProductsComments { CommentId = ProductComment.Id, ProductId = commentModel.Id });

                await this.db.SaveChangesAsync();
            }
        }
コード例 #8
0
        public ActionResult Comment(CommentAddViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(View(model));
            }

            var post = this.postService.GetById(model.PostId)
                       .FirstOrDefault();

            if (post == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var userId = this.User.Identity.GetUserId();

            this.commentService.AddCommentToPost(model.PostId, userId, model.Content);

            return(RedirectToAction("Post", new { id = model.PostId }));
        }
コード例 #9
0
        public async Task <IActionResult> AddComment(CommentAddViewModel commentAddViewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var commentAddDto = _mapper.Map <CommentAddBookDto>(commentAddViewModel);
                    var result        = await _bookCommentService.AddComment(commentAddDto);

                    if (result.ResultStatus == ResultStatus.Success)
                    {
                        return(RedirectToAction("Details", new { Id = commentAddDto.BookId }));
                    }
                }
                catch (Exception exc)
                {
                    return(RedirectToAction("PleaseEditComment"));
                }
            }
            return(View(commentAddViewModel));
        }
コード例 #10
0
        public async Task <IActionResult> Index(CommentAddViewModel model)
        {
            if (ModelState.IsValid)
            {
                var appUser = await _userManager.FindByNameAsync(User.Identity.Name);

                var userId = appUser.Id;
                model.AppUserId = userId;
                Review comment = new Review
                {
                    AppUserId  = model.AppUserId,
                    BookStatus = model.BookStatus,
                    BookId     = model.BookId,
                    HeadLine   = model.HeadLine,
                    ReviewText = model.ReviewText,
                    Rating     = model.Rating,
                    CreatedOn  = DateTime.Now,
                    ReviewLike = model.ReviewLike,
                };
                _commentService.Add(comment);
            }

            return(RedirectToAction("Index", "Comment"));
        }
コード例 #11
0
        public JsonResult AddComment()
        {
            CommentAddViewModel vm = new CommentAddViewModel();
            string text            = RequestUtils.GetFormText(Request, "text");
            int    contentID       = RequestUtils.GetFormInt(Request, "objectid");

            if (_profileService.CurrentProfile != null && !string.IsNullOrEmpty(text) && contentID > 0)
            {
                {
                    var comment = new Comment
                    {
                        ProfileID    = _profileService.CurrentProfile.ID,
                        Text         = text,
                        CreateDate   = DateTime.Now,
                        ObjectID     = contentID,
                        ObjectType   = "content",
                        ProfileName  = _profileService.CurrentProfile.Name,
                        ProfileImage = _profileService.CurrentProfile.Image
                    };
                    comment.ID = _contentRepository.AddComment(comment);
                    vm.Status  = "success";

                    var content = _contentRepository.GetContent(comment.ObjectID);
                    if (content != null)
                    {
                        vm.CommentCount = content.CommentCount;
                    }
                    //     vm.Comment = comment;
                    // Формирование даты для вывода.
                    //vm.Date = content.CreateDate.ToString("dd MMMM yyyy") + " в " + content.CreateDate.ToString("HH:mm");

                    vm.Comment = new CommentViewModel(comment);
                }
            }
            return(Json(vm));
        }
コード例 #12
0
        public async Task <IActionResult> Post(CommentAddViewModel commentModel, string path)
        {
            await this.commentService.CreateComment(commentModel, path);

            return(Ok("DONE!"));
        }
コード例 #13
0
 public async Task CreateComment(CommentAddViewModel commentModel, string path)
 {
     await CheckPathAndAddComment(commentModel, path);
 }
コード例 #14
0
        public ActionResult AddComment(CommentAddViewModel commentAddViewModel)
        {
            if (!commentAddViewModel.Validate().IsValid)
            {
                return this.Issue404();
            }

            // Normalize the Line Breaks
            commentAddViewModel.CommentText = commentAddViewModel.CommentText.Replace("\n", Environment.NewLine);

            switch (commentAddViewModel.CommentType)
            {
                case CommentType.Recipe:
                    RecipeComment recipeComment;

                    using (var unitOfWork = this.UnitOfWorkFactory.NewUnitOfWork())
                    {
                        recipeComment = new RecipeComment();
                        recipeComment.CommentText = commentAddViewModel.CommentText;
                        recipeComment.RecipeId = commentAddViewModel.GenericId;
                        this.RecipeService.AddRecipeComment(recipeComment);
                        unitOfWork.Commit();
                    }

                    // Queue Comment Notification
                    this.NotificationService.QueueNotification(NotificationType.RecipeComment, recipeComment);
                    break;
                case CommentType.Session:
                    BrewSessionComment brewSessionComment;

                    using (var unitOfWork = this.UnitOfWorkFactory.NewUnitOfWork())
                    {
                        brewSessionComment = new BrewSessionComment();
                        brewSessionComment.CommentText = commentAddViewModel.CommentText;
                        brewSessionComment.BrewSessionId = commentAddViewModel.GenericId;
                        this.RecipeService.AddBrewSessionComment(brewSessionComment);
                        unitOfWork.Commit();
                    }

                    // Queue Comment Notification
                    this.NotificationService.QueueNotification(NotificationType.BrewSessionComment, brewSessionComment);
                    break;
                default:
                    return this.Issue404();
            }
            
            var commentViewModel = new CommentViewModel();
            commentViewModel.CommentText = commentAddViewModel.CommentText;
            commentViewModel.UserId = this.ActiveUser.UserId;
            commentViewModel.UserName = this.ActiveUser.Username;
            commentViewModel.UserAvatarUrl = UserAvatar.GetAvatar(59, this.ActiveUser.EmailAddress);
            commentViewModel.DateCreated = DateTime.Now;

            return View("_Comment", commentViewModel);
        }