Exemplo n.º 1
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));
        }