Пример #1
0
 public CommentItemComponentModel(PersonView loginPerson, CommentView commentView, DbFactory dbFactory, bool isLike)
 {
     LoginPerson    = loginPerson;
     CommentView    = commentView;
     this.dbFactory = dbFactory;
     this.IsLike    = isLike;
 }
Пример #2
0
        public async Task <bool> SendCommentConfirmation(CommentView result)
        {
            var subject = $"[ Nowy komentarz ] Od {result.Name}";
            var html    = await _renderService.ToHtmlStringAsync("CommentInfo", result);

            return(await SendEmail(result.Email, subject, html));
        }
Пример #3
0
        public async Task <PartialViewResult> SaveComment([FromForm] Comment comment)
        {
            using (var cn = _data.GetConnection())
            {
                comment.OrganizationId = _data.CurrentOrg.Id;
                await comment.SaveHtmlAsync(_data, cn);

                bool inserted = (comment.Id == 0);
                if (await _data.TrySaveAsync(comment) && inserted)
                {
                    await AddFreshdeskNoteAsync(comment, cn);
                }

                var vm = new CommentView();
                vm.LocalTime      = _data.CurrentUser.LocalTime;
                vm.ObjectId       = comment.ObjectId;
                vm.ObjectType     = comment.ObjectType;
                vm.CommentBoxOpen = comment.CommentBoxOpen;
                vm.Comments       = await new Comments()
                {
                    OrgId = _data.CurrentOrg.Id, ObjectType = comment.ObjectType, ObjectIds = new int[] { comment.ObjectId }
                }.ExecuteAsync(cn);
                return(PartialView("/Pages/Dashboard/Items/_Comments.cshtml", vm));
            }
        }
Пример #4
0
        public ActionResult Comment(Post model)
        {
            ApplicationDbContext context  = new ApplicationDbContext();
            List <Post>          listpost = context.Posts.ToList();
            Post post = listpost.Find(m => m.PostId.Equals(model.PostId));
            List <CommentView>    CommentViews = new List <CommentView>();
            List <Comment>        listcomment  = context.Comments.Include(c => c.ApplicationUser).ToList();
            IEnumerable <Comment> comments     = listcomment.Where(m => m.PostId.Equals(post.PostId));
            List <Mark>           listmark     = context.Marks.ToList();

            foreach (Comment com in comments)
            {
                CommentView commentView = new CommentView
                {
                    Comment = com
                };
                IEnumerable <Mark> marks = listmark.Where(m => m.CommentId.Equals(com.CommentId));
                int rating = 0;
                foreach (Mark m in marks)
                {
                    rating = rating + m.Value;
                }
                commentView.CommentRating = rating;
                if (com.CommentAddressee != null)
                {
                    List <ApplicationUser> listuser = context.Users.ToList();
                    ApplicationUser        user     = listuser.Find(m => m.Email.Equals(com.CommentAddressee));
                    commentView.Href = user.UserSurname + " " + user.UserFullName + ", ";
                }
                CommentViews.Add(commentView);
            }
            ViewBag.CommentViews = CommentViews;
            ViewBag.PostId       = model.PostId;
            return(PartialView("CommentView", CommentViews));
        }
Пример #5
0
        public virtual ActionResult AddCommentComment(CommentView model, EmbedModel embed)
        {
            if (!IsAjaxRequest)
            {
                return(RedirectToAction(MVC.Idea.Details(model.EntryId, null, null)));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var comment = Service.AddNewCommentToComment(model.EntryId, model.Id, model.CommentText, embed);

                    if (IsJsonRequest)
                    {
                        return(Jsonp(comment));
                    }

                    return(Jsonp(new
                    {
                        Comment = RenderPartialViewToString(MVC.Comments.Views._CommentComment, comment),
                        Subscribe = RenderPartialViewToString(MVC.Shared.Views.Subscribe, comment.Subscribe),
                        SubscribeMain = RenderPartialViewToString(MVC.Shared.Views.Subscribe, comment.SubscribeMain)
                    }));
                }
                catch (Exception ex)
                {
                    return(ProcessError(ex));
                }
            }

            return(Jsonp(false));
        }
Пример #6
0
        public IActionResult DisplayFullBlogPost(int id)
        {
            var blogPost = new FullBlogPost();

            blogPost.commentView = new List <CommentView>();

            var post = (from b in _DataContext.BlogPosts where b.BlogPostId == id select b).FirstOrDefault();

            blogPost.blog = post;

            var user = (from u in _DataContext.Users where post.UserId == u.UserId select u).FirstOrDefault();

            blogPost.user = user;

            var comments = (from item in _DataContext.Comments where item.BlogPostId == id select item).ToList();

            foreach (Comment com in comments)
            {
                CommentView c = new CommentView();
                c.comment = com;
                var author = (from u in _DataContext.Users where u.UserId == com.UserId select u).FirstOrDefault();
                c.authorName  = author.FirstName + " " + author.LastName;
                c.authorEmail = author.EmailAddress;
                blogPost.commentView.Add(c);
            }

            return(View(blogPost));
        }
Пример #7
0
        public CommentView ToView(CommentModel model)
        {
            if (model is null)
            {
                return(null);
            }
            CommentView _view = new CommentView();

            _view.Id          = model.Id;
            _view.ProjectId   = model.ProjectId;
            _view.CourseId    = model.CourseId;
            _view.CreatedDate = model.CreatedDate.Value;
            _view.CreatedBy   = model.CreatedBy;
            _view.UpdatedBy   = model.UpdatedBy;
            _view.UpdatedDate = model.UpdatedDate;
            _view.Title       = model.Title;
            _view.Content     = model.Content;
            _view.CountViews  = model.CountViews;
            _view.Files       = _manager.GetFiles(model.Id).ToList();
            _view.ArticleId   = model.ArticleId;
            if (model.ArticleId.HasValue)
            {
                _view.Article = _manager.GetByIdAsync(model.ArticleId.Value).Result;
            }

            return(_view);
        }
Пример #8
0
        public void CloseForData_ViewNotCorrespondingToRemovedCalculationItem_ReturnsFalse()
        {
            // Setup
            var calculation = mocks.Stub <ICalculation>();

            calculation.Stub(s => s.Comments).Return(new Comment());
            var viewDataCalculation = mocks.Stub <ICalculation>();

            viewDataCalculation.Stub(s => s.Comments).Return(new Comment());
            var deletedCalculationContext = mocks.StrictMock <ICalculationContext <ICalculationBase, ICalculatableFailureMechanism> >();

            deletedCalculationContext.Expect(c => c.WrappedData).Return(calculation);

            mocks.ReplayAll();

            using (var view = new CommentView
            {
                Data = viewDataCalculation.Comments
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, deletedCalculationContext);

                // Assert
                Assert.IsFalse(closeForData);
            }

            mocks.VerifyAll();
        }
Пример #9
0
        public List <TaskViewModel> AddComment(CommentView NewComment)
        {
            string UserId = User.Identity.GetUserId(); // get current logged in user
            IEnumerable <TaskViewModel> TaskViews = TaskService.AddComment(NewComment, UserId);

            return(TaskViews.ToList());
        }
Пример #10
0
        public void CloseForData_ViewDataIsFailureMechanismCommentOfDeletedAssessmentSection_ReturnTrue(Func <SpecificFailureMechanism, Comment> getCommentFunc)
        {
            // Setup
            var failureMechanism = new SpecificFailureMechanism();

            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(s => s.GetFailureMechanisms()).Return(Enumerable.Empty <IFailureMechanism>());
            assessmentSection.Stub(s => s.SpecificFailureMechanisms).Return(new ObservableList <SpecificFailureMechanism>
            {
                failureMechanism
            });
            assessmentSection.Stub(s => s.Comments).Return(new Comment());
            mocks.ReplayAll();

            using (var view = new CommentView
            {
                Data = getCommentFunc(failureMechanism)
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, assessmentSection);

                // Assert
                Assert.IsTrue(closeForData);
            }

            mocks.VerifyAll();
        }
Пример #11
0
        public void CloseForData_ViewDataIsCommentButNotOfDeletedFailureMechanismContext_ReturnFalse()
        {
            // Setup
            var unaffectedComment = new Comment();

            var failureMechanism = mocks.Stub <IFailureMechanism>();

            failureMechanism.Stub(fm => fm.InAssemblyInputComments).Return(new Comment());
            failureMechanism.Stub(fm => fm.InAssemblyOutputComments).Return(new Comment());
            failureMechanism.Stub(fm => fm.NotInAssemblyComments).Return(new Comment());
            var failureMechanismContext = mocks.Stub <IFailureMechanismContext <IFailureMechanism> >();

            failureMechanismContext.Expect(c => c.WrappedData).Return(failureMechanism);
            mocks.ReplayAll();

            using (var view = new CommentView
            {
                Data = unaffectedComment
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, failureMechanismContext);

                // Assert
                Assert.IsFalse(closeForData);
            }

            mocks.VerifyAll();
        }
Пример #12
0
        public void CloseForData_ViewDataIsCommentButNotOfDeletedFailureMechanism_ReturnFalse()
        {
            // Setup
            var viewDataComment = new Comment();

            var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>();

            failureMechanism.Stub(fm => fm.Calculations).Return(Enumerable.Empty <ICalculation>());
            failureMechanism.Stub(fm => fm.InAssemblyInputComments).Return(new Comment());
            failureMechanism.Stub(fm => fm.InAssemblyOutputComments).Return(new Comment());
            failureMechanism.Stub(fm => fm.NotInAssemblyComments).Return(new Comment());
            failureMechanism.Stub(fm => fm.CalculationsInputComments).Return(new Comment());

            mocks.ReplayAll();

            using (var view = new CommentView
            {
                Data = viewDataComment
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, failureMechanism);

                // Assert
                Assert.IsFalse(closeForData);
            }

            mocks.VerifyAll();
        }
Пример #13
0
        public void CloseForData_ViewDataIsFailureMechanismCommentButNotOfDeletedAssessmentSection_ReturnFalse()
        {
            // Setup
            var viewDataComment = mocks.Stub <IFailureMechanism>();

            viewDataComment.Stub(s => s.InAssemblyInputComments).Return(new Comment());

            var deletedAssessmentSection = mocks.Stub <IAssessmentSection>();

            deletedAssessmentSection.Stub(s => s.GetFailureMechanisms()).Return(Enumerable.Empty <IFailureMechanism>());
            deletedAssessmentSection.Stub(s => s.SpecificFailureMechanisms).Return(new ObservableList <SpecificFailureMechanism>
            {
                new SpecificFailureMechanism()
            });
            deletedAssessmentSection.Stub(s => s.Comments).Return(new Comment());
            mocks.ReplayAll();

            using (var view = new CommentView
            {
                Data = viewDataComment.InAssemblyInputComments
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, deletedAssessmentSection);

                // Assert
                Assert.IsFalse(closeForData);
            }

            mocks.VerifyAll();
        }
Пример #14
0
        public void CloseForData_ViewDataIsFailureMechanismNotInAssemblyCommentOfDeletedAssessmentSection_ReturnTrue()
        {
            // Setup
            var comment = new Comment();

            var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>();

            failureMechanism.Stub(fm => fm.Calculations).Return(Enumerable.Empty <ICalculation>());
            failureMechanism.Stub(fm => fm.InAssemblyInputComments).Return(new Comment());
            failureMechanism.Stub(fm => fm.InAssemblyOutputComments).Return(new Comment());
            failureMechanism.Stub(fm => fm.NotInAssemblyComments).Return(comment);

            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(s => s.GetFailureMechanisms()).Return(new[]
            {
                failureMechanism
            });
            assessmentSection.Stub(s => s.Comments).Return(new Comment());
            mocks.ReplayAll();

            using (var view = new CommentView
            {
                Data = comment
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, assessmentSection);

                // Assert
                Assert.IsTrue(closeForData);
            }

            mocks.VerifyAll();
        }
Пример #15
0
        public ActionResult Send(string message, int novelId)
        {
            int  result = (int)ErrorMessage.失败;
            bool isOpen = SiteSection.Comment.IsOpen;

            if (isOpen && novelId > 0)
            {
                CommentView comment = new CommentView();
                comment             = GetClientLogInfo(comment) as CommentView;
                comment.AuthorId    = 0;
                comment.UserId      = currentUser.UserId;
                comment.UserName    = currentUser.UserName;
                comment.Message     = StringHelper.HtmlEncode(message);
                comment.NovelId     = novelId;
                comment.Status      = (int)Constants.Status.yes;
                comment.Creator     = "";
                comment.UpdateTime  = DateTime.Now;
                comment.AddTime     = DateTime.Now;
                comment.PropsId     = 0;
                comment.PropsCount  = 0;
                comment.SortId      = 0;
                comment.UserType    = 0;
                comment.Title       = "";
                comment.Description = "";

                result = _commentService.Send(comment);
            }

            return(Json(new ComplexResponse <string>(result)));
        }
        // GET: Images/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Image image = db.Images.Find(id);

            if (image == null)
            {
                return(HttpNotFound());
            }
            var comment = (from c in db.Comments
                           where c.ImgId == id
                           select new
            {
                userId = c.UserId,
                text = c.Text
            }
                           ).ToList();
            List <CommentView> commentsView = new List <CommentView>();

            for (int i = 0; i < comment.Count; i++)
            {
                var commentView = new CommentView();
                int userId      = comment[i].userId;
                commentView.Username = (from u in db.Users where u.Id == userId select u.Username).First();
                commentView.Text     = comment[i].text;
                commentsView.Add(commentView);
            }

            ViewBag.Comments = commentsView;
            return(View(image));
        }
Пример #17
0
 public CommentPresenter(CommentModel model, CommentView view)
 {
     this.model     = model;
     this.view      = view;
     view.Presenter = this;
     view.Comment   = model.Comment;
 }
Пример #18
0
        public void CloseForData_ViewDataIsCalculationOfRemovedCalculationGroup_ReturnsTrue()
        {
            // Setup
            var viewDataCalculation = mocks.Stub <ICalculation>();

            viewDataCalculation.Stub(s => s.Comments).Return(new Comment());
            var deletedGroupContext = mocks.StrictMock <ICalculationContext <CalculationGroup, ICalculatableFailureMechanism> >();
            var deletedGroup        = new CalculationGroup
            {
                Children =
                {
                    viewDataCalculation
                }
            };

            deletedGroupContext.Expect(g => g.WrappedData).Return(deletedGroup);

            mocks.ReplayAll();

            using (var view = new CommentView
            {
                Data = viewDataCalculation.Comments
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, deletedGroupContext);

                // Assert
                Assert.IsTrue(closeForData);
            }

            mocks.VerifyAll();
        }
Пример #19
0
        public virtual ActionResult AddComment(CommentView model, EmbedModel embed)
        {
            if (Request.HttpMethod == "GET" || !Request.IsAjaxRequest())
            {
                return(RedirectToAction(MVC.Problem.Index()));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var comment = Service.AddNewComment(model.EntryId, model.CommentText, embed);
                    return(Json(new { Comment = RenderPartialViewToString(MVC.Comments.Views._Comment, comment),
                                      SubscribeMain = RenderPartialViewToString(MVC.Shared.Views.Subscribe, comment.SubscribeMain) }));
                }
                catch (Exception ex)
                {
                    return(ProcessError(ex));
                }
            }

            return(Json(new
            {
                error = (from v in ModelState.Values
                         from e in v.Errors
                         select e.ErrorMessage).Concatenate(";")
            }));
        }
Пример #20
0
        public void RichTextEditorOnTextChanged_Always_SetsComment()
        {
            // Setup
            var data = new Comment();

            using (var form = new Form())
                using (var view = new CommentView())
                {
                    form.Controls.Add(view);
                    form.Show();

                    // Set data after showing control:
                    view.Data = data;

                    // Precondition
                    Assert.AreEqual(GetValidRtfString(""), data.Body);

                    const string expectedText   = "<Some_text>";
                    string       validRtfString = GetValidRtfString(expectedText);

                    var richTextBoxControl = (RichTextBoxControl) new ControlTester("richTextBoxControl").TheObject;

                    // Call
                    richTextBoxControl.Rtf = validRtfString;

                    // Assert
                    Assert.AreEqual(validRtfString, data.Body);
                }
        }
 public HttpResponseMessage AddComment([FromBody] Comment comment)
 {
     try
     {
         if (postRepository.GetPostByID(comment.postid) != null)
         {
             if (comment != null)
             {
                 commentRepository.InsertComment(comment);
                 commentRepository.Save();
                 var         entity      = commentRepository.GetCommentByID(comment.id);
                 CommentView commentview = new CommentView();
                 commentview = Mapper.Map <Comment, CommentView>(entity);
                 return(Request.CreateResponse(HttpStatusCode.OK, commentview));
             }
             else
             {
                 return(Request.CreateResponse(HttpStatusCode.NotFound, "Not found"));
             }
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, "Not found"));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Пример #22
0
        public async Task <IActionResult> AddComment([FromBody] CommentView result)
        {
            if (!ModelState.IsValid)
            {
                // wysyłamy informacje o błędach
                return(BadRequest(ModelState));
            }

            var settings = await _settingsService.GetBlogSettings();

            var article = await _articleService.Get(result.ArticleId);

            var comment = await _commentService.Create(CommentHelpers.ConvertToModel(result, article));

            if (comment)
            {
                var notification = new NotificationData($"Wpadł Ci nowy komentarz od {result.Name} | {result.Email}");
                _notificationService.Send(notification);

                if (settings.CommentsNotify)
                {
                    _emailService.SendCommentConfirmation(result);
                }

                return(Ok(new { status = "Komentarz zapisany pomyślnie" }));
            }
            else
            {
                return(BadRequest(new { status = "Problem z zapisem komentarza" }));
            }
        }
 public HttpResponseMessage CommentById(Guid postid, Guid id)
 {
     try
     {
         var post = postRepository.GetPostByID(postid);
         if (post != null)
         {
             var entity = commentRepository.GetCommentByID(id);
             if (entity != null)
             {
                 CommentView comment = new CommentView();
                 comment = Mapper.Map <Comment, CommentView>(entity);
                 return(Request.CreateResponse(HttpStatusCode.OK, comment));
             }
             else
             {
                 return(Request.CreateResponse(HttpStatusCode.NotFound, "Not found"));
             }
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, "Not found"));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Пример #24
0
        public async Task <IActionResult> GetCommentView(long commentId)
        {
            CommentModule invMod = new CommentModule();

            CommentView view = await invMod.Comment.Query().GetViewById(commentId);

            return(Ok(view));
        }
Пример #25
0
        public async Task <IActionResult> Create([FromBody] CommentEditModel model)
        {
            CommentView comment = await this.commentService.InsertAsync(model, this.User.GetUserId().Value);

            PersonView person = await this.personService.GetCurrentPersonViewAsync();

            return(ViewComponent(typeof(CommentItemViewComponent), new { pLoginPerson = person, pCommentView = comment }));
        }
Пример #26
0
        public CommentView GetCommentViewFromComment(string objectId, Data.MongoDB.Comment comment, MongoObjectId parentId, EntryTypes type, string relatedVersion = null)
        {
            var hiddenText = Globalization.Resources.Comments.Resource.CommentHidden;
            var model      = new CommentView
            {
                CommentText           = comment.IsHidden ? hiddenText : comment.Text.NewLineToHtml().ActivateLinks() ?? string.Empty,
                CommentDate           = comment.Date,
                AuthorFullName        = comment.UserFullName,
                AuthorObjectId        = comment.UserObjectId,
                ForAgainst            = comment.PositiveOrNegative,
                ProfilePictureThumbId = UserService.GetProfilePictureThumbId(comment.UserObjectId),
                Liking = new Liking()
                {
                    EntryId         = objectId,
                    ParentId        = parentId,
                    CommentId       = comment.Id,
                    Type            = type,
                    LikesCount      = GetLikesCountString(comment.SupportingUserIds.Count),
                    IsLikeVisible   = !comment.IsHidden && CurrentUser.IsAuthenticated && !comment.SupportingUserIds.Contains(CurrentUser.Id) && comment.UserObjectId != CurrentUser.Id,
                    IsUnlikeVisible = !comment.IsHidden && CurrentUser.IsAuthenticated && comment.SupportingUserIds.Contains(CurrentUser.Id) && comment.UserObjectId != CurrentUser.Id
                },
                Id = comment.Id,
                IsCreatedByCurrentUser = CurrentUser.IsAuthenticated && (comment.UserObjectId == CurrentUser.Id || CurrentUser.Role == UserRoles.Admin),
                IsCommentable          = type != EntryTypes.Problem && CurrentUser.IsAuthenticated,
                ParentId       = parentId,
                EntryId        = objectId,
                VersionId      = comment.RelatedVersionId,
                RelatedVersion = relatedVersion,
                EntryType      = type,
                IsHidden       = comment.IsHidden,
                Number         = comment.Number,
                Embed          = comment.Embed != null ? new EmbedModel()
                {
                    Url           = comment.Embed.Url,
                    Author_Name   = comment.Embed.Author_Name,
                    Author_Url    = comment.Embed.Author_Url,
                    Cache_Age     = comment.Embed.Cache_Age,
                    Description   = comment.Embed.Description,
                    Height        = comment.Embed.Height,
                    Html          = comment.Embed.Type != "link" ? comment.Embed.Html : string.Empty,
                    Provider_Name = comment.Embed.Provider_Name,
                    Provider_Url  = comment.Embed.Provider_Url,
                    Thumbnail_Url = comment.Embed.Thumbnail_Url,
                    Title         = comment.Embed.Title,
                    Type          = comment.Embed.Type,
                    Version       = comment.Embed.Version,
                    Width         = comment.Embed.Width
                } : null
            };

            if (CurrentUser.IsAuthenticated && parentId == null)
            {
                model.Subscribe = ActionService.IsSubscribed(comment.Id, CurrentUser.DbId.Value);
            }
            //model.Liking.IsCreatedByCurrentUser = CurrentUser.IsAuthenticated && comment.UserObjectId == CurrentUser.Id;

            return(model);
        }
Пример #27
0
        public async Task <IActionResult> DeleteComment([FromBody] CommentView view)
        {
            CommentModule invMod  = new CommentModule();
            Comment       comment = await invMod.Comment.Query().MapToEntity(view);

            invMod.Comment.DeleteComment(comment).Apply();

            return(Ok(view));
        }
Пример #28
0
        public static CommentModel MergeViewWithModel(CommentModel model, CommentView view)
        {
            model.Content    = view.Content;
            model.Email      = view.Email;
            model.Name       = view.Name;
            model.IsAccepted = view.IsAccepted;

            return(model);
        }
Пример #29
0
 public MainWindow()
 {
     cr       = new ClientRequests();
     commentv = new CommentView();
     filev    = new FilteView();
     clientv  = new ClientView();
     InitializeComponent();
     DataContext = this;
 }
Пример #30
0
        public static CommentModel MergeViewWithModel(CommentModel model, CommentView view)
        {
            model.Content = view.Content;
            model.User    = view.User;
            //model.Email = view.Email;
            //model.Name = view.Name;

            return(model);
        }