public void AddComment_Should_Success() { var user = new BookCreatorUser { UserName = "******", Name = "Georgi Goshkov" }; userManager.CreateAsync(user).GetAwaiter(); this.Context.SaveChanges(); var commentInput = new CommentInputModel { BookId = "1", CommentAuthor = user.UserName, CommentedOn = DateTime.UtcNow, Message = "asd" }; this.commentService.AddComment(commentInput); var result = this.Context.Comments.First(); result.Should().NotBeNull() .And.Subject.As <Comment>() .Message.Should().Be(commentInput.Message); }
public async Task <IActionResult> Edit(string id, CommentInputModel commentInput) { var existsComment = this.commentsService .Exists(x => x.Id == id); if (!existsComment) { return(this.NotFound()); } if (!this.ModelState.IsValid) { var comment = new CommentEditModel() { Id = id, CommentInput = commentInput, }; return(this.View(comment)); } await this.commentsService.EditAsync(id, commentInput); this.TempData[GlobalConstants.MessageKey] = $"Successfully edited comment!"; return(this.RedirectToAction("Details", "Posts", new { area = "Forum", id = commentInput.PostId })); }
public ActionResult Create(CommentInputModel comment) { if (!this.ModelState.IsValid) { return this.PartialView(comment); } var newComment = this.comments.Create(this.sanitizer.Sanitize(comment.Content)); if (this.User.Identity.IsAuthenticated) { newComment.PostedById = this.User.Identity.GetUserId(); } newComment.CreatedOn = DateTime.UtcNow; // string id = this.Url.RequestContext.RouteData.Values["Id"].ToString(); // var recipe = this.recipes.GetById(id); // newComment.RecipeId = recipe.Id; this.comments.Add(newComment); var resultComment = this.Mapper.Map<CommentInputModel>(newComment); return this.PartialView(resultComment); }
public ActionResult AddComment(int id) { var comment = new CommentInputModel(); comment.EventId = id; return(View(comment)); }
public async Task <IActionResult> Edit(int?commentId, int employeeId) { var comment = await _commentService.GetByIdAsync(commentId); if (comment == null) { var inputModel = new CommentInputModel { EmployeeId = employeeId }; return(View(inputModel)); } else { var inputModel = new CommentInputModel { Id = comment.Id, EmployeeId = employeeId, Author = comment.Author, CommentContent = comment.CommentContent }; return(View(inputModel)); } }
public async Task <IActionResult> Edit(CommentInputModel model) { if (!ModelState.IsValid) { return(View(model)); } var comment = await _commentService.GetByIdAsync(model.Id); if (comment == null) { comment = new Comment { Author = model.Author, CommentContent = model.CommentContent, EmployeeId = model.EmployeeId, CreatedDateTime = DateTime.Now, IsActive = true }; } else { comment.Author = model.Author; comment.CommentContent = model.CommentContent; comment.EmployeeId = model.EmployeeId; comment.LastUpdatedDateTime = DateTime.Now; } await _commentService.SaveChangesAsync(comment); return(Redirect($"/Comment/Index?employeeId={model.EmployeeId}")); }
public async Task CreateCommentAddsCorrectly() { // Arrange var commentsList = this.GetComments(); var expectedComments = commentsList.Count() + 1; var discussionList = this.GetDiscussions(); var discussionId = discussionList.FirstOrDefault().Id; var commentsRepoMock = this.GetCommentMock(commentsList).Object; var discussionRepoMock = this.GetDiscussionMock(discussionList).Object; var commentService = new DiscussionsService(discussionRepoMock, commentsRepoMock, this.commentVoteRepo, this.mediaRepo); var inputModel = new CommentInputModel() { Content = "Hell yeah123", DiscussionId = discussionId, }; // Act await commentService.CreateComment(inputModel.Content, "", inputModel.DiscussionId); // Assert Assert.Equal(expectedComments, commentsRepoMock.AllAsNoTracking().Count()); Assert.Contains(commentsRepoMock.AllAsNoTracking().Where(x => x.DiscussionId == discussionId).ToList(), x => x.Content == inputModel.Content); }
public long Comment(CommentInputModel model) { if (model == null) { throw new ArgumentNullException("model"); } var blogFound = _dbContext.Blogs.Any(b => b.Id == model.BlogId); if (!blogFound) { throw new BlogNotFoundException(string.Format("博客Id {0}找不到", model.BlogId)); } var comment = new CommentEntity { BlogId = model.BlogId, Content = model.Content, Created = DateTime.Now }; _dbContext.Comments.Add(comment); _dbContext.SaveChanges(); return(comment.Id); }
public void CreateComment(CommentInputModel inputModel) { var comment = Mapper.Map <Comment>(inputModel); this.commentsRepository.AddAsync(comment).GetAwaiter().GetResult(); this.commentsRepository.SaveChangesAsync().GetAwaiter().GetResult(); }
public ActionResult Submit(CommentInputModel model) { if (!ModelState.IsValid) { return(ViewParentPage()); } var list = CurrentPage.GetChild("Comments") as CommentList; if (list == null) { list = Engine.Resolve <ContentActivator>().CreateInstance <CommentList>(CurrentPage); list.Title = "Comments"; list.Name = "Comments"; list.ZoneName = Zones.Content; if (CurrentItem.Parent == CurrentPage && CurrentItem.ZoneName == Zones.Content) { Engine.Resolve <ITreeSorter>().MoveTo(list, NodePosition.Before, CurrentItem); } Engine.Persister.Save(list); } Comment comment = Engine.Resolve <ContentActivator>().CreateInstance <Comment>(list); comment.Title = Server.HtmlEncode(model.Title); comment.AuthorName = Server.HtmlEncode(model.Name); comment.Email = Server.HtmlEncode(model.Email); comment.AuthorUrl = Server.HtmlEncode(model.Url); comment.Text = Server.HtmlEncode(model.Text); comment.ZoneName = "Comments"; Engine.Persister.Save(comment); return(Redirect(CurrentPage.Url)); }
protected override void Given() { _commentInputModel = new CommentInputModel { Uri = "test" }; }
public ActionResult DeleteComment(int id) { var currentUserId = this.User.Identity.GetUserId(); var isAdmin = this.IsAdmin(); var comment = new CommentInputModel(); var commentToDelete = this.db.Comments.Where(e => e.Id == id).SingleOrDefault(); if (commentToDelete != null) { var isOwner = (commentToDelete != null && commentToDelete.AuthorId != null && commentToDelete.AuthorId == currentUserId); if (isAdmin || isOwner) { comment.Text = commentToDelete.Text; comment.EventId = commentToDelete.EventId; comment.Id = commentToDelete.Id; if (commentToDelete.Author != null) { comment.Author = commentToDelete.Author.FullNme; } } else { this.AddNotification("Cannot delete event #" + id, NotificationType.ERROR); return(this.RedirectToAction("My")); } } return(View(comment)); }
public ActionResult PostComment(CommentInputModel comment) { if (ModelState.IsValid) { var newComment = new Comment() { ArticleId = comment.ArticleId, AuthorId = this.User.Identity.GetUserId(), AuthorName = this.User.Identity.GetUserName(), Content = this.Sanitizer.Sanitize(comment.Content) }; this.Data.Comments.Add(newComment); this.Data.SaveChanges(); var newCommentModel = new CommentViewModel() { Content = this.Sanitizer.Sanitize(comment.Content), AuthorName = this.User.Identity.GetUserName(), CreatedOn = newComment.CreatedOn }; return(this.PartialView("_CommentPartial", newCommentModel)); } return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, ModelState.Values.First().ToString())); }
public async Task GetAllByIssueIdShouldReturnCorrectComments() { this.institutionsList.Add(new Institution { UserId = "testUser", Name = "Test Name" }); var inputModel = new CommentInputModel { Content = "Test Content", IssueId = 1, UserId = "testUser", }; await this.commentsService.CreateAsync(inputModel); inputModel.IssueId = 2; await this.commentsService.CreateAsync(inputModel); inputModel.IssueId = 1; await this.commentsService.CreateAsync(inputModel); foreach (var comment in this.commentsList) { comment.User = new ApplicationUser(); comment.CreatedOn = DateTime.Today; } var comments = this.commentsService.GetAllByIssueId(1, 1); Assert.True(comments.Count() == 2); }
public ActionResult AddComment(CommentInputModel model) { if (!ModelState.IsValid) { return(this.View()); } var comment = new Comment { Content = model.Content, TripId = model.TripId, CreatorId = this.User.Identity.GetUserId() }; var trip = this.trips.GetById(comment.TripId) .FirstOrDefault(); if (trip == null) { throw new Exception("Not Existing Trip!"); } trip.Comments.Add(comment); this.trips.Update(trip); return(this.RedirectToAction("Details", "Trip", new { id = model.TripId })); }
public async Task CreateCommentSuccessfully(string email, string password, int postId, string body) { var token = await this.Login(email, password); this.client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token); var post = new CommentInputModel { PostId = postId, Text = body }; var json = new StringContent( JsonConvert.SerializeObject(post), Encoding.UTF8, "application/json"); var response = await this.client.PostAsync(CommentCreateEndpoint, json); response.EnsureSuccessStatusCode(); var content = JsonConvert.DeserializeObject <CreateEditReturnMessage <CommentViewModel> >(await response.Content.ReadAsStringAsync()); Assert.Equal(StatusCodes.Status200OK, content.Status); Assert.Equal("Comment created successfully!", content.Message); Assert.Equal(body, content.Data.Text); Assert.Equal(email.Split("@")[0], content.Data.Author); }
public ActionResult Create(CommentInputModel comment) { if (!this.ModelState.IsValid) { return(this.PartialView(comment)); } var newComment = this.comments.Create(this.sanitizer.Sanitize(comment.Content)); if (this.User.Identity.IsAuthenticated) { newComment.PostedById = this.User.Identity.GetUserId(); } newComment.CreatedOn = DateTime.UtcNow; // string id = this.Url.RequestContext.RouteData.Values["Id"].ToString(); // var recipe = this.recipes.GetById(id); // newComment.RecipeId = recipe.Id; this.comments.Add(newComment); var resultComment = this.Mapper.Map <CommentInputModel>(newComment); return(this.PartialView(resultComment)); }
public IActionResult Comment(string id) { var model = new CommentInputModel { PostId = id }; return(this.View(model)); }
public async Task <IActionResult> Comment([FromBody] CommentInputModel model) { var user = await this.userManager.GetUserAsync(this.User); await this.commentService.AddComment(user.Id, int.Parse(model.Id), model.Comment); return(this.Ok()); }
public async Task CreateCommentAsync(CommentInputModel inputModel) { var comment = mapper.Map <Comment>(inputModel); await this.dbContext.Comments.AddAsync(comment); await this.dbContext.SaveChangesAsync(); }
// GET: Blog/Edit/5 public ActionResult Comment(int blogId) { var model = new CommentInputModel { BlogId = blogId }; return(View(model)); }
public async Task <ActionResult <bool> > CreateComment(CommentInputModel input) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); await this.commentsService.CreateCommentAsync(input, userId); return(true); }
public async Task CreateCommentShouldWork() { // Arrange var mockUserManager = this.GetMockUserManager(); var mockCommentsService = new Mock <ICommentsService>(); var mockPostsService = new Mock <IPostsService>(); mockCommentsService .Setup(mc => mc.AddAsync("content", new ApplicationUser(), new Post())) .Returns(Task.FromResult(0)); mockCommentsService .Setup(mc => mc.GetAll()) .Returns(this.GetAll <Comment>()); mockPostsService .Setup(mp => mp.GetAll()) .Returns(this.GetAll <Post>()); var claims = new List <Claim>() { new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", "5247d66a-84ff-4987-abb5-53b1c2e747c2"), new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", "*****@*****.**"), new Claim("AspNet.Identity.SecurityStamp", "E7B2QZV5M4OIRM3ZFIVXFVGR3YULFGO7"), new Claim("http://schemas.microsoft.com/ws/2008/06/identity/claims/role", "Admin"), new Claim("amr", "pwd"), }; var claimsIdentity = new ClaimsIdentity(claims); var principal = new ClaimsPrincipal(claimsIdentity); Thread.CurrentPrincipal = principal; mockUserManager.Setup(mu => mu.GetUserAsync(principal)) .Returns(Task.FromResult(new ApplicationUser() { UserName = "******", Image = new Image() { Url = "testUrl" } })); var controller = new CommentsController(mockUserManager.Object, mockCommentsService.Object, mockPostsService.Object); // Act var input = new CommentInputModel() { Content = "content", PostId = 0 }; var result = await controller.Create(input); // Assert var type = Assert.IsAssignableFrom <ActionResult <CommentResponseModel> >(result); Assert.Equal("MyName", result.Value.Username); Assert.Equal("content", result.Value.Content); }
public IActionResult Comment(CommentInputModel model) { if (this.ModelState.IsValid) { this.commentsService.CreateComment(model.Content, this.User.Identity.Name); } return(this.RedirectToAction(nameof(All))); }
public async Task <int> AddLocationCommentAsync(CommentInputModel inputModel) { Comment commentToAdd = mapper.Map <Comment>(inputModel); commentToAdd.AddedOn = DateTime.UtcNow; dbContext.Comments.Add(commentToAdd); return(await dbContext.SaveChangesAsync()); }
public async Task <IActionResult> Post(CommentInputModel inputModel, int postId) { var userId = this.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value; var currnetUser = await this.userManager.FindByIdAsync(userId); var res = await this.commentService.CreateAsync <CommentOutputModel>(inputModel.Text, currnetUser.Id, postId); return(this.Ok(res)); }
public ActionResult Comment(CommentInputModel model) { if (ModelState.IsValid) { _blogService.Comment(model); return(RedirectToAction("Index")); } return(View(model)); }
public IActionResult AddComment(CommentInputModel inputComment) { var currentUser = _userManager.GetUserId(HttpContext.User); _bookService.AddComment(inputComment, currentUser); int x = inputComment.BookId; return(RedirectToAction("Details", "Book", new{ id = x })); }
public void AddComment(int id, CommentInputModel comment) { //adds data into new comment var newComment = new Comment { BookId = id, Comments = comment.Comment, Rating = comment.Rating }; _bookRepo.AddComment(newComment); }
public async Task <IActionResult> Create(CommentInputModel commentInputModel) { if (!this.ModelState.IsValid) { return(this.Redirect("/")); } await this.commentService.CreateAsync(commentInputModel); return(this.RedirectToAction("GetDetails", "Announcements", new { id = commentInputModel.AnnouncementId })); }
public ActionResult AddComment(int id, CommentInputModel model) { if (!this.ModelState.IsValid) { return this.RedirectToAction("Details", new { id = id }); } this.forumService.PostComment(model.Content, id, this.UserId); return this.RedirectToAction("Details", new { id = id }); }
public async Task <ActionResult> Create(CommentInputModel input) { if (!this.ModelState.IsValid) { return(this.StatusCode(304)); } await this.commentService.Add(input.Username, input.ProductId, input.Content); return(this.StatusCode(201)); }
public ActionResult Add(SportSystem.Models.Match match, CommentInputModel commentInput) { var comment = Mapper.Map<Comment>(commentInput); comment.AuthorId = this.UserProfille.Id; comment.MatchId = match.Id; comment.CreatedOn = DateTime.Now; this.Data.Comments.Add(comment); this.Data.SaveChanges(); return this.RedirectToAction("Details", "Matches", new { id = match.Id }); }
public void ShoudMapPostNewCommentToForumPostWithCorrectData() { const int ForumPostId = 12; const string CommentContent = "Test comment for posing"; var model = new CommentInputModel() { Content = CommentContent }; this.routeCollection.ShouldMap($"/Public/Forum/AddComment/{ ForumPostId }") .WithFormUrlBody($"Content={ CommentContent }") .To<ForumController>(c => c.AddComment(ForumPostId, model)); }
public ActionResult AddComment(CommentInputModel model) { if (ModelState.IsValid) { var newComment = new Comment { Content = this.sanitizer.Sanitize(model.Content), CreatedOn = DateTime.UtcNow, AuthorId = this.User.Identity.GetUserId() }; this.comments.Add(newComment); } return this.PartialView("_AllCommentsPartialView", this.GetComments()); }
public ActionResult AddComment(CommentInputModel model) { if (model != null && this.ModelState.IsValid ) { model.UserId = this.User.Identity.GetUserId(); var comment = Mapper.Map<Comment>(model); comment.DataTime = DateTime.Now; this.Data.Comments.Add(comment); this.Data.SaveChanges(); var commentDt = this.Data.Comments.All() .Where(x => x.Id == comment.Id) .Project().To<CommentsViewModel>().FirstOrDefault(); return this.PartialView("DisplayTemplates/CommentsViewModel", commentDt); } return this.Json("Error"); }
public ActionResult Comments_Update([DataSourceRequest]DataSourceRequest request, CommentInputModel comment) { if (ModelState.IsValid) { var entity = this.comments.AllWithDeleted().Where(x => x.Id == comment.Id).FirstOrDefault(); entity.Text = comment.Text; this.comments.SaveChanges(); } var commentToDisplay = this.comments.AllWithDeleted() .To<CommentViewModel>() .FirstOrDefault(x => x.Id == comment.Id); return Json(new[] { commentToDisplay }.ToDataSourceResult(request, ModelState)); }
public ActionResult Create(CommentInputModel model) { if (!ModelState.IsValid) { return this.View(); } var comment = new Comment { Content = model.Content, TripId = model.TripId, CreatorId = this.User.Identity.GetUserId() }; this.commentService.Create(comment); return this.RedirectToAction("Details", "Trip", new { id = model.TripId }); }
public ActionResult AddComment(CommentInputModel model) { if (model != null && this.ModelState.IsValid) { var comment = Mapper.Map<Comment>(model); comment.UserId = this.User.Identity.GetUserId(); comment.CreatedOn = DateTime.Now; this.Data.Comments.Add(comment); this.Data.SaveChanges(); var commentViewModel = this.Data.Comments .All() .Where(x => x.Id == comment.Id) .Project() .To<CommentViewModel>() .FirstOrDefault(); return this.PartialView("DisplayTemplates/CommentViewModel", commentViewModel); } return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Invalid comment!"); }
public ActionResult Create(CommentInputModel model, int id) { var comment = new Comment() { Text = model.Text, Author = this.UserProfile, CreatedOn = DateTime.Now, PictureId = id, IsDeleted = false }; this.Data.Comments.Add(comment); this.Data.SaveChanges(); return this.PartialView("DisplayTemplates/CommentViewModel", new CommentViewModel { Author = comment.Author, Id = comment.Id, PictureId = comment.PictureId, Text = comment.Text }); }
public ActionResult Add(CommentInputModel comment) { if (this.User == null || !this.User.Identity.IsAuthenticated) { this.Response.StatusCode = 401; return this.Content("Unauthorized"); } if (comment == null || !this.ModelState.IsValid) { this.Response.StatusCode = 400; return this.Content("Bad request."); } var newComment = this.commentsService.Add(comment.Content, comment.PostId, this.User.Identity.GetUserId()); if (newComment == null) { this.Response.StatusCode = 400; return this.Content("Bad request."); } return this.PartialView("_SingleCommentPartial", this.Mapper.Map<CommentViewModel>(newComment)); }
public ActionResult AddComment(CommentInputModel model) { if (model != null && this.ModelState.IsValid) { model.AuthorId = this.User.Identity.GetUserId(); model.CreationDateTime = DateTime.Now; model.SnippetId = Int16.Parse(RouteData.Values["id"].ToString()); var comment = Mapper.Map<Comment>(model); this.Data.Comments.Add(comment); this.Data.SaveChanges(); var commentDb = this.Data.Comments .All() .Where(c => c.Id == comment.Id) .Project() .To<CommentShortViewModel>() .FirstOrDefault(); return this.PartialView("DisplayTemplates/CommentShortViewModel", commentDb); } return this.Json("Error"); }
public ActionResult Create() { var model = new CommentInputModel(); return this.PartialView("Partial/_Create", model); }
public ActionResult AddComment(CommentInputModel model) { if (!ModelState.IsValid) { return this.View(); } var comment = new Comment { Content = model.Content, TripId = model.TripId, CreatorId = this.User.Identity.GetUserId() }; var trip = this.trips.GetById(comment.TripId) .FirstOrDefault(); if (trip == null) { throw new Exception("Not Existing Trip!"); } trip.Comments.Add(comment); this.trips.Update(trip); return this.RedirectToAction("Details", "Trip", new { id = model.TripId }); }