Beispiel #1
0
        public PollCommentViewModel(int?parentCommentId, IPollComment pollComment, Func <int, string, Task> submitCommentCallback, bool isNested)
        {
            if (pollComment == null)
            {
                throw new ArgumentNullException("pollComment");
            }
            if (submitCommentCallback == null)
            {
                throw new ArgumentNullException("submitCommentCallback");
            }

            this.ParentCommentId       = parentCommentId;
            this.PollComment           = pollComment;
            this.SubmitCommentCallback = submitCommentCallback;

            this.IsNested = isNested;

            this.ChildComments = new ObservableCollection <PollCommentViewModel>();
            if (pollComment.Comments != null)
            {
                foreach (var comment in pollComment.Comments)
                {
                    this.ChildComments.Add(new PollCommentViewModel(comment.PollCommentID, comment, submitCommentCallback, true));
                }
            }
        }
Beispiel #2
0
		public PollCommentViewModel(int? parentCommentId, IPollComment pollComment, Func<int, string, Task> submitCommentCallback, bool isNested)
		{
			if (pollComment == null)
			{
				throw new ArgumentNullException("pollComment");
			}
			if (submitCommentCallback == null)
			{
				throw new ArgumentNullException("submitCommentCallback");
			}

			this.ParentCommentId = parentCommentId;
			this.PollComment = pollComment;
			this.SubmitCommentCallback = submitCommentCallback;

			this.IsNested = isNested;

			this.ChildComments = new ObservableCollection<PollCommentViewModel>();
			if (pollComment.Comments != null)
			{
				foreach (var comment in pollComment.Comments)
				{
					this.ChildComments.Add(new PollCommentViewModel(comment.PollCommentID, comment, submitCommentCallback, true));
				}
			}
		}
Beispiel #3
0
        public HttpResponseMessage Put([FromBody] PollResultComment input)
        {
            IPollComment comment = null;

            try
            {
                var userID      = MyVoteAuthentication.GetCurrentUserID();
                var pollResults = PollResultsFactory.Fetch(new PollResultsCriteria(userID.Value, input.PollID));

                comment             = PollCommentFactory.CreateChild(input.UserID, input.UserName);
                comment.CommentText = input.CommentText;

                if (input.ParentCommentID.HasValue)
                {
                    var parentComment = pollResults.PollComments.Comments.Single(c => c.PollCommentID == input.ParentCommentID);
                    parentComment.Comments.Add(comment);
                }
                else
                {
                    pollResults.PollComments.Comments.Add(comment);
                }

                var newResults       = pollResults.Save() as IPollResults;
                var targetCollection = input.ParentCommentID.HasValue
                                        ? newResults.PollComments.Comments.Single(c => c.PollCommentID == input.ParentCommentID).Comments
                                        : newResults.PollComments.Comments;

                return(this.Request.CreateResponse(
                           HttpStatusCode.OK,
                           new { PollCommentID = targetCollection.Max(c => c.PollCommentID).Value }));
            }
            catch (Csla.Rules.ValidationException ex)
            {
                var brokenRules = comment.GetBrokenRules().ToString();
                throw new HttpResponseException(
                          new HttpResponseMessage
                {
                    StatusCode     = HttpStatusCode.BadRequest,
                    ReasonPhrase   = ex.Message.Replace(Environment.NewLine, " "),
                    Content        = new StringContent(brokenRules),
                    RequestMessage = Request
                });
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(
                          new HttpResponseMessage
                {
                    StatusCode     = HttpStatusCode.BadRequest,
                    ReasonPhrase   = ex.Message.Replace(Environment.NewLine, " "),
                    Content        = new StringContent(ex.ToString()),
                    RequestMessage = Request
                });
            }
        }
		private PollResultComment MapPollComments(int pollID, IPollComment pollComment, int? parentCommentID)
		{
			return new PollResultComment
			{
				PollID = pollID,
				ParentCommentID = parentCommentID,
				PollCommentID = pollComment.PollCommentID.Value,
				UserName = pollComment.UserName,
				CommentDate = pollComment.CommentDate,
				CommentText = pollComment.CommentText,
				Comments = pollComment.Comments.Select(c => MapPollComments(pollID, c, pollComment.PollCommentID)).ToList()
			};
		}
 private PollResultComment MapPollComments(int pollID, IPollComment pollComment, int?parentCommentID)
 {
     return(new PollResultComment
     {
         PollID = pollID,
         ParentCommentID = parentCommentID,
         PollCommentID = pollComment.PollCommentID.Value,
         UserName = pollComment.UserName,
         CommentDate = pollComment.CommentDate,
         CommentText = pollComment.CommentText,
         Comments = pollComment.Comments.Select(c => MapPollComments(pollID, c, pollComment.PollCommentID)).ToList()
     });
 }
Beispiel #6
0
        private Mock <IPollComment> BuildMockPollComment(RandomObjectGenerator generator, IPollComment childComment)
        {
            var commentID   = generator.Generate <int>();
            var commentDate = generator.Generate <DateTime>();
            var commentText = generator.Generate <string>();
            var userName    = generator.Generate <string>();

            var pollCommentList = new List <IPollComment>();

            if (childComment != null)
            {
                pollCommentList.Add(childComment);
            }

            var pollCommentCollection = new Mock <IPollCommentCollection>(MockBehavior.Strict);

            pollCommentCollection.Setup(_ => _.GetEnumerator()).Returns(pollCommentList.GetEnumerator());

            var pollComment = new Mock <IPollComment>(MockBehavior.Strict);

            pollComment.SetupGet(_ => _.PollCommentID).Returns(commentID);
            pollComment.SetupGet(_ => _.CommentDate).Returns(commentDate);
            pollComment.SetupGet(_ => _.Comments).Returns(pollCommentCollection.Object);
            pollComment.SetupGet(_ => _.CommentText).Returns(commentText);
            pollComment.SetupGet(_ => _.UserName).Returns(userName);

            return(pollComment);
        }
		private Mock<IPollComment> BuildMockPollComment(RandomObjectGenerator generator, IPollComment childComment)
		{
			var commentID = generator.Generate<int>();
			var commentDate = generator.Generate<DateTime>();
			var commentText = generator.Generate<string>();
			var userName = generator.Generate<string>();

			var pollCommentList = new List<IPollComment>();
			if (childComment != null)
				pollCommentList.Add(childComment);

			var pollCommentCollection = new Mock<IPollCommentCollection>(MockBehavior.Strict);
			pollCommentCollection.Setup(_ => _.GetEnumerator()).Returns(pollCommentList.GetEnumerator());

			var pollComment = new Mock<IPollComment>(MockBehavior.Strict);
			pollComment.SetupGet(_ => _.PollCommentID).Returns(commentID);
			pollComment.SetupGet(_ => _.CommentDate).Returns(commentDate);
			pollComment.SetupGet(_ => _.Comments).Returns(pollCommentCollection.Object);
			pollComment.SetupGet(_ => _.CommentText).Returns(commentText);
			pollComment.SetupGet(_ => _.UserName).Returns(userName);

			return pollComment;
		}