Ejemplo n.º 1
0
        public ActionResult UpdateComment(NewComment c)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false }));
            }

            var userId = User.Identity.GetUserId();

            using (var db = new ZapContext())
            {
                var comment = db.Comments.FirstOrDefault(cmt => cmt.CommentId == c.CommentId);
                if (comment == null)
                {
                    return(Json(new { success = false, message = "Comment not found." }));
                }
                if (comment.UserId.AppId != userId)
                {
                    return(Json(new { success = false, message = "User does not have rights to edit comment." }));
                }
                comment.Text            = SanitizeCommentXSS(c.CommentContent.Replace("<p><br></p>", ""));
                comment.TimeStampEdited = DateTime.UtcNow;
                db.SaveChanges();
            }

            return(Json(new
            {
                HTMLString = "",
                c.PostId,
                success = true,
            }));
        }
Ejemplo n.º 2
0
 public void OnGet()
 {
     LoadModel();
     NewComment = new NewComment {
         PostId = Id, Content = ""
     };
 }
Ejemplo n.º 3
0
        public static void AddNewCommentsDiv(this IBacicInterface intFace, IHTMLDiv newCommentDiv, IHTMLDiv commentsDiv)
        {
            RefreshComments(intFace, commentsDiv);
            var newcommentContainer = new NewComment().AttachTo(newCommentDiv);

            newcommentContainer.Submit.onclick += async delegate
            {
                if (newcommentContainer.name.value != "")
                {
                    if (newcommentContainer.email.value != "")
                    {
                        if (newcommentContainer.commentarea.value != "")
                        {
                            await intFace.InsertNewComment(Native.document.location.hash, newcommentContainer.name.value,
                                newcommentContainer.email.value, newcommentContainer.commentarea.value);

                            intFace.RefreshComments(commentsDiv);

                            newcommentContainer.email.value = "";
                            newcommentContainer.name.value = "";
                            newcommentContainer.commentarea.value = "";
                        }
                    }
                }
            };
        }
Ejemplo n.º 4
0
        public async Task Add(NewComment comment)
        {
            comment.UserId = _currentUser.Id;
            await _db.Comments.Add(comment);

            await _db.SaveChanges();
        }
Ejemplo n.º 5
0
        public ActionResult UpdateComment(NewComment c)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new{ Success = false }));
            }

            var userId = User.Identity.GetUserId();

            using (var db = new ZapContext())
            {
                var comment = db.Comments.FirstOrDefault(cmt => cmt.CommentId == c.CommentId);
                if (comment == null)
                {
                    return(Json(new { Success = false }));
                }
                if (comment.UserId.AppId != userId)
                {
                    return(Json(new { Success = false }));
                }
                comment.Text = c.CommentContent;
                db.SaveChanges();
            }

            return(this.Json(new
            {
                HTMLString = "",
                c.PostId,
                Success = true,
            }));
        }
        public IActionResult AddComment([FromForm] NewComment cData)
        {
            var     user        = _um.GetUserAsync(HttpContext.User).Result;
            Comment newResponse = new Comment
            {
                Body       = cData.Body,
                UserId     = user.Id,
                Popularity = 0,
            };

            _service.CreateComment(newResponse, cData.ResponseId);
            var origQ        = _service.GetQuestionById(cData.QuestionId);
            var qResponses   = _service.GetRelatedResponses(origQ.Id);
            var viewQuestion = new QuestionForView
            {
                Id         = origQ.Id,
                Title      = origQ.Title,
                Body       = origQ.Body,
                UserId     = origQ.UserId,
                Popularity = origQ.Popularity,
                Responses  = qResponses
            };

            return(View("Details", viewQuestion));
        }
Ejemplo n.º 7
0
        public IActionResult Comment([FromBody] NewComment newComment)
        {
            //创建新评论
            var comment = new Comment {
            };

            comment.c_id       = (Cservice.GetCommentNum() + 1).ToString();
            comment.u_id       = newComment.UserID;
            comment.m_id       = newComment.MovieID;
            comment.rating     = newComment.MovieRating;
            comment.review     = newComment.MovieReview;
            comment.total_like = 0;

            context.Comment.Add(comment);
            context.SaveChanges();

            //更新评论者偏好
            var tagList = Mservice.GetTagByMovie(newComment.MovieID);

            foreach (var temp in tagList)
            {
                var UserPrefer = context.UserPrefer.FirstOrDefault(up => up.u_id == comment.u_id && up.tag_name == temp.TagName);
                if (UserPrefer != null)
                {
                    //偏好更新
                    UserPrefer.fit += comment.rating;

                    context.UserPrefer.Attach(UserPrefer);
                    context.SaveChanges();
                }
                else
                {
                    //首次获得偏好值
                    var newUserPrefer = new UserPrefer
                    {
                        u_id     = comment.u_id,
                        tag_name = temp.TagName,
                        fit      = comment.rating
                    };

                    context.UserPrefer.Add(newUserPrefer);
                    context.SaveChanges();
                }
            }

            //更新全局信息
            var totalinfo = context.TotalInfo.Find("pumpkinmovies");

            totalinfo.c_num += 1;
            context.TotalInfo.Attach(totalinfo);
            context.SaveChanges();

            return(Ok(new
            {
                Success = true,
                Comment = comment,
                msg = "Operation Done"
            }));
        }
Ejemplo n.º 8
0
		public static Comment New(NewComment comment)
		{
			return new Comment
			{
				Author = comment.Name,
				Email = comment.Email,
				Body = comment.Body
			};
		}
Ejemplo n.º 9
0
        public void AddComment(NewComment comment)
        {
            var postData = new List <KeyValuePair <string, string> >();

            postData.Add(new KeyValuePair <string, string>("text", comment.Comment));
            var         query    = $"cards/{comment.CardId}/actions/comments?key={this._config.AppKey}&token={this._config.UserToken}";
            HttpContent content  = new FormUrlEncodedContent(postData);
            var         response = this._client.PostAsync(query, content);
        }
Ejemplo n.º 10
0
        // Returns a list of posts made a list of authors.
        public static List <Post> GetPosts(int ViewerId, List <int> Authors)
        {
            snaptergramEntities db = new snaptergramEntities();

            List <posts> AllPosts = new List <posts>();

            using (db)
            {
                var data = from u in db.posts select u;
                AllPosts = data.ToList();
            }

            List <posts> FollowedPosts = new List <posts>();

            // Selects all posts based on author id.
            foreach (posts P in AllPosts)
            {
                if (Authors.Contains(P.userId))
                {
                    FollowedPosts.Add(P);
                }
            }

            // List of converted objects.
            List <Post> AllPostsConverted = new List <Post>();

            foreach (posts P in FollowedPosts)
            {
                // Convert each post to a complex model post.
                Post Converted = new Post();

                // Post and date do not need to be converted.
                Converted.PostImage = P.image;
                Converted.PostDate  = P.postDate;

                // Author Conversion.
                Converted.PostAuthor = Users.GetAuthor(P.userId, ViewerId, P.postId);

                // Likes Conversion.
                Converted.PostLikes = new Like(ViewerId, P.postId, P.likes, Likes.HasLiked(ViewerId, P.postId));

                // Comments Conversion.
                Converted.Comments = Comments.GetPostComments(ViewerId, P.postId);

                // Add a reply comments object.
                NewComment NewCom = new NewComment();
                NewCom.UserId = ViewerId;
                NewCom.PostId = P.postId;
                Converted.PostCommentReply = NewCom;

                // Add the converted object to the list.
                AllPostsConverted.Add(Converted);
            }

            return(AllPostsConverted);
        }
        public async Task Handle_Success()
        {
            var request = new NewComment(validEventId, "The answer is 42!");

            var useCaseResult = await interactor.Handle(request, CancellationToken.None);

            useCaseResult.Should().NotBeNull();
            useCaseResult.IsSuccessful.Should().BeTrue();
            useCaseResult.Errors.Should().BeEmpty();
        }
Ejemplo n.º 12
0
        internal void AddComment()
        {
            NewComment comment = new NewComment()
            {
                Title    = _pView.Title,
                Body     = _pView.Body,
                LookupID = _pView.newsID,
            };

            _pModel.AddComment(comment);
        }
Ejemplo n.º 13
0
        public string CreateComment(string issueId, [FromBody] NewComment newComment)
        {
            var newCommentId = myStorage.CreateComment(issueId, newComment);

            if (string.IsNullOrWhiteSpace(newCommentId))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            return(newCommentId);
        }
        public IActionResult MarkApproved(int ID)
        {
            NewComment newComment = repository.NewComments
                                    .FirstOrDefault(o => o.ID == ID);

            if (newComment != null)
            {
                newComment.Approved = true;
                repository.ApproveComment(newComment);
            }
            return(RedirectToAction(nameof(PostComment)));
        }
Ejemplo n.º 15
0
        public bool AddComment(NewComment newComment)
        {
            const string insertCommandString =
                @"INSERT INTO dbo.comments (userId, articleId, text)
                    VALUES (@userId, @articleId, @text);";
            var insertCommand = new SqlCommand(insertCommandString);

            insertCommand.Parameters.AddWithValue("@userId", newComment.UserId);
            insertCommand.Parameters.AddWithValue("@articleId", newComment.ArticleId);
            insertCommand.Parameters.AddWithValue("@text", newComment.Comment);
            return(DbHelper.ExecuteCommand(insertCommand, ConnectionString) > 0);
        }
 public IActionResult PostComment(NewComment newComment)
 {
     if (ModelState.IsValid)
     {
         repository.ApproveComment(newComment);
         return(RedirectToAction(nameof(Completed)));
     }
     else
     {
         return(View(newComment));
     }
 }
Ejemplo n.º 17
0
        public ActionResult Create(Comments comments)
        {
            if (ModelState.IsValid)
            {
                db.Comments.Add(comments);
                db.SaveChanges();

                BackgroundJob.Enqueue(() => NewComment.NotifyNewComment(comments.Id));
                //  RecurringJob.AddOrUpdate(() => NewComment.Send("*****@*****.**", "test", "Test Recuret Task"), Cron.Minutely);
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Maps an instance of GlobalModels.NewComment onto a new instance of
        /// Repository.Models.Comment. Sets Repository.Models.Review.CreationTime
        /// to the current time.
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public static Repository.Models.Comment NewCommentToNewRepoComment(NewComment comment)
        {
            var repoComment = new Repository.Models.Comment();

            repoComment.DiscussionId = comment.Discussionid;
            repoComment.Username     = comment.Username;
            repoComment.CommentText  = comment.Text;
            repoComment.CreationTime = DateTime.Now;
            repoComment.IsSpoiler    = comment.Isspoiler;

            return(repoComment);
        }
Ejemplo n.º 19
0
        public void CreateComment(NewComment newComment)
        {
            DbContext.Comments.Add(new Comment
            {
                CreationDate = DateTime.UtcNow,
                Content      = newComment.Content,
                UserId       = newComment.UserId,
                PostId       = newComment.PostId
            });

            DbContext.SaveChanges();
        }
Ejemplo n.º 20
0
        public void AddCommentTest()
        {
            //arrange
            NewComment comment = new NewComment();

            m_mockArticleRepository.Expects.One.MethodWith(_ => _.AddComment(comment)).WillReturn(true);

            // act
            var isAdded = m_facade.AddComment(comment);

            // assert
            Assert.AreEqual(isAdded, true);
        }
Ejemplo n.º 21
0
 public void Create_Comment_should_add_comment()
 {
     using (var api = NewService())
     {
         var newComment = new NewComment
         {
             Comment = "look at that data quality",
             // This value will depend on the EMS system. It should be a flight record number.
             EntityIdentifier = { 3135409 }
         };
         api.Databases.CreateComment(Monikers.FlightDatabase, Monikers.FlightDataQualityField, newComment);
     }
 }
        public async Task Handle_InvalidEventId()
        {
            var request = new NewComment(
                new Guid("15D08C24-FD8F-43E8-989E-69B98E8257B0"),
                "The answer is 42!");

            var useCaseResult = await interactor.Handle(request, CancellationToken.None);

            useCaseResult.Should().NotBeNull();
            useCaseResult.IsSuccessful.Should().BeFalse();
            useCaseResult.ResultCategory.Should().Be(ResultCategory.NotFound);
            useCaseResult.Errors.Should().HaveCount(1);
        }
        public async Task Handle_ErrorWhileInserting()
        {
            var request = new NewComment(validEventId, "The answer is 42!");

            A.CallTo(() => commentRepository.InsertAsync(A <Comment> ._))
            .Invokes(() => throw new InvalidOperationException());

            var useCaseResult = await interactor.Handle(request, CancellationToken.None);

            useCaseResult.Should().NotBeNull();
            useCaseResult.IsSuccessful.Should().BeFalse();
            useCaseResult.ResultCategory.Should().Be(ResultCategory.GeneralFailure);
            useCaseResult.Errors.Should().HaveCount(1);
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> UpdateProjectComment(int id, [FromBody] NewComment newComment)
        {
            var userId  = GetUserId();
            var project = await _db.Projects
                          .SingleAsync(p => p.OwnerId == userId && p.Id == id);

            if (project == null)
            {
                return(new NotFoundResult());
            }

            project.Comment = newComment.Comment;
            await _db.SaveChangesAsync();

            return(new JsonResult(project));
        }
Ejemplo n.º 25
0
        public string CreateComment(string issueId, NewComment newComment)
        {
            var commentId = Guid.NewGuid().ToString();

            if (this.CurrentIssues.ContainsKey(issueId))
            {
                var comment = new Comment(newComment);
                comment.CommentId = commentId;
                comment.TimeStamp = DateTime.UtcNow;
                this.CurrentIssues[issueId].Comments.Add(comment);

                return(commentId);
            }

            return(null);
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> UpdateExperimentComment(int id, [FromBody] NewComment n)
        {
            var userId = GetUserId();
            var exper  = await _db.Experiments.FindAsync(id);

            if (exper == null || exper.OwnerId != userId)
            {
                return(NotFound());
            }

            exper.Comment = n.Comment;
            _db.Experiments.Update(exper);
            await _db.SaveChangesAsync();

            return(new JsonResult(exper));
        }
Ejemplo n.º 27
0
        public async Task AddNewComment(AddNewCommentViewModel input)
        {
            var newComment = new NewComment
            {
                PhotographyAddictedUserId = input.PhotographyAddictedUserId,
                // PhotographyAddictedUser = input.PhotographyAddictedUser,
                NewId = input.NewId,
                //Theme = input.Theme,
                UserOpinion  = input.UserOpinion,
                CreationDate = DateTime.UtcNow,
            };

            await newCommentDbSet.AddAsync(newComment);

            await newCommentDbSet.SaveChangesAsync();
        }
Ejemplo n.º 28
0
        public async Task <ActionResult> CreateComment([FromBody] NewComment comment)
        {
            if (!ModelState.IsValid)
            {
                Console.WriteLine("ForumController.CreateComment() was called with invalid body data.");
                return(StatusCode(400));
            }

            if (await _forumLogic.CreateComment(comment))
            {
                return(StatusCode(201));
            }
            else
            {
                return(StatusCode(400));
            }
        }
Ejemplo n.º 29
0
        public async Task <IHttpActionResult> PostComment([FromUri] string id, [FromBody] NewComment newComment)
        {
            if (newComment == null || !ModelState.IsValid)
            {
                return(ApiBadRequestFromModelState());
            }

            var decodedId = id.FromEncodedId();

            var post = await _dbContext.Posts.FirstOrDefaultAsync(p => p.Id == decodedId);

            if (post == null || post.DeletedAt != null)
            {
                return(NotFound());
            }
            if (post.IsArchived)
            {
                return(ApiBadRequest(ApiResources.PostArchived));
            }

            var comment = new Comment
            {
                UserId = User.Id,
                PostId = decodedId,
                Text   = newComment.Text
            };

            _dbContext.Comment.Add(comment);

            if (await _dbContext.SaveChangesAsync() == 0)
            {
                return(InternalServerError());
            }

            // auto-upvote comment
            _dbContext.CommentVotes.Add(new CommentVote
            {
                CommentId = comment.Id,
                UserId    = User.Id,
                IpAddress = ClientIpAddress,
                IsUp      = true
            });
            await _dbContext.SaveChangesAsync();

            return(CreatedData(comment.Id.ToEncodedId()));
        }
Ejemplo n.º 30
0
        public IActionResult AddComment([FromBody] NewComment model)
        {
            var report = model.Adapt <ReportComment>();

            report.CreatedDate = DateTime.Now;
            DbContext.Comments.Add(report);
            DbContext.SaveChanges();
            var result = report.Adapt <ReportCommentDTO>();

            result.Likes = new List <LikeDTO>();
            result.User  = DbContext.Users.Where(u => u.Id == model.UserId).ProjectToType <ReportUser>().FirstOrDefault();

            return(new JsonResult(
                       result,
                       new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented
            }));
        }
Ejemplo n.º 31
0
 public void PopulateStopMovePopup(string commentValue, string targetRouteNumber, string targetStopNumber = null, string sourceRouteNumber = null, string sourceStopNumber = null, string deliveryDateTimeValue = null)
 {
     //If you specified a source route number then populate the source route and stop
     if (sourceRouteNumber != null)
     {
         FromRouteNumber.SelectByText(sourceRouteNumber, "From Route Number");
         FromStopNumber.SelectByText(sourceStopNumber, "From Stop Number");
     }
     ToNewRouteNumber.SelectByText(targetRouteNumber, "New Route Number");
     NewComment.EnterText(commentValue, "Move Stop Comment");
     ToNewStopNumber.EnterText(targetStopNumber, "NEW STOP NUMBER");
     ToNewStopNumber.SendKeys(Keys.Tab); //Using tab to fire blur event b/c otherwise js never fires to allow user to click save.
     //If you specified a delivery date/time then use it. Otherwise leave the default value.
     if (deliveryDateTimeValue != null)
     {
         NewDeliveryDateTime.EnterText(deliveryDateTimeValue, "New Delivery Date Time");
     }
     Debug.WriteLine($"Attempting to move Route {FromRouteNumber.GetSelectedOptionText()} Stop {FromStopNumber.GetSelectedOptionText()} to Route {targetRouteNumber} Stop {targetStopNumber} with a new Delivery Date of {NewDeliveryDateTime.GetText()}");
 }
Ejemplo n.º 32
0
        /// <inheritdoc/>
        protected override async Task <object> CallGitHubApi(DialogContext dc, Octokit.GitHubClient gitHubClient, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (Owner != null && Name != null && Number != null && NewComment != null)
            {
                var ownerValue      = Owner.GetValue(dc.State);
                var nameValue       = Name.GetValue(dc.State);
                var numberValue     = Number.GetValue(dc.State);
                var newCommentValue = NewComment.GetValue(dc.State);
                return(await gitHubClient.Issue.Comment.Create(ownerValue, nameValue, (Int32)numberValue, newCommentValue).ConfigureAwait(false));
            }
            if (RepositoryId != null && Number != null && NewComment != null)
            {
                var repositoryIdValue = RepositoryId.GetValue(dc.State);
                var numberValue       = Number.GetValue(dc.State);
                var newCommentValue   = NewComment.GetValue(dc.State);
                return(await gitHubClient.Issue.Comment.Create((Int64)repositoryIdValue, (Int32)numberValue, newCommentValue).ConfigureAwait(false));
            }

            throw new ArgumentNullException("Required [number,newComment] arguments missing for GitHubClient.Issue.Comment.Create");
        }
Ejemplo n.º 33
0
		static public void Show (Browser browser)
		{
			if (NewCommentBox == null)
				NewCommentBox = new NewComment (browser);
			NewCommentBox.newcomment.Show ();
		}
Ejemplo n.º 34
0
                //
		// Called on the Window delete icon clicked
		//
		void OnDelete (object sender, DeleteEventArgs a)
		{
                        NewCommentBox = null;
		}