//public void Hello(int postId) // передаем id комента //{ // var com = _comment.AllComments(postId); //айди поста // int count = 0; // foreach (var c in com) // { // var likes = _likeService.GetAllLikes(c.Id); // foreach (var item in likes) // { // count += 1; // } // c.polelike = count; // } //} public Comment CreateComment(CreateCommentViewModel model, int ID, string login) { Comment comment = new Comment { CommentText = model.CommentText, LoginUser = login,//_user.GetUserDB(_userManager.GetUserId(User)).UserName, PublicationID = ID, Publication = _publicationService.GetPostDB(ID) }; _comment.AddCommentDB(comment); return(comment); }
public async Task <IActionResult> Comment([FromForm] CreateCommentViewModel comment) { CreateCommentViewModel com = comment; Comment save = com.Create(); ApplicationUser user = await _userManager.GetUserAsync(User); save.ApplicationUser = user; Course course = _context.Courses.Include(x => x.Comments).FirstOrDefault(x => x.ID == com.CourseID); course.Comments.Add(save); _context.SaveChanges(); return(Ok()); }
public async void Throws_Post_With_Given_Id_Not_Exists() { _mockPostRepository.Setup(repo => repo.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(() => null); ICommentService commentService = new CommentService(_mockCommentsRepository.Object, _mockPostRepository.Object); CreateCommentViewModel createCommentViewModel = new CreateCommentViewModel() { Text = COMMENT_TEXT_CONTENT, FromId = Guid.NewGuid(), PostId = Guid.NewGuid() }; await Assert.ThrowsAsync <PostNotExistsException>(async() => await commentService.CreateCommentAsync(createCommentViewModel)); }
public IActionResult CreateComment(int postId) { if (!this.ModelState.IsValid) { return(this.View("Error")); } var viewModel = new CreateCommentViewModel { PostId = postId, }; return(this.View(viewModel)); }
private ActionResult SaveComment(int?id, CreateCommentViewModel formData) { if (!ModelState.IsValid) { return(View()); } TicketComment comment; if (!id.HasValue) { var userId = User.Identity.GetUserId(); var user = DbContext.Users.FirstOrDefault(p => p.Id == userId); var ticket = DbContext.TicketsDatabase.FirstOrDefault(p => p.Id == formData.TicketId); if (ticket == null) { return(View()); } comment = new TicketComment(); comment.Comment = formData.Comment; comment.DateCreated = DateTime.Now; comment.UserId = userId; comment.User = user; comment.Ticket = ticket; comment.TicketId = ticket.Id; ticket.Comments.Add(comment); DbContext.TicketsCommentsDatabase.Add(comment); DbContext.SaveChanges(); } else { var userId = User.Identity.GetUserId(); var user = DbContext.Users.FirstOrDefault(p => p.Id == userId); comment = DbContext.TicketsCommentsDatabase.FirstOrDefault(p => p.Id == id); if (comment == null) { return(RedirectToAction(nameof(TicketsController.Tickets))); } comment.Comment = formData.Comment; comment.DateUpdated = DateTime.Now; var userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); userManager.SendEmail(userId, "Notification", "There is a new Comment In a ticket Belongs to you."); DbContext.SaveChanges(); } return(RedirectToAction(nameof(TicketsController.Tickets))); }
public async Task <IActionResult> CreateComment([FromBody] CreateCommentViewModel model) { _context.Comments.Add(new Models.Comment() { Id = Guid.NewGuid().ToString(), UserId = model.UserId, PostId = model.PostId, Text = model.Text, Date = DateTime.Now }); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <GrainOperationResult> CreateComment(CreateCommentViewModel model, string feedItemId) { try { await _repository.CreateComment(model, feedItemId, GrainUserId); return(new GrainOperationResult { Successful = true, Message = "Operation executed successfully." }); } catch (Exception ex) { return(ex.ResultFromException()); } }
public async Task <IActionResult> EditComment(CreateCommentViewModel model, int id) { if (ModelState.IsValid) { Comment comment = _comment.GetCommentDB(id); if (comment != null) { comment.CommentText = model.CommentText; _comment.UpdateComment(comment); return(RedirectToAction("AllComments")); } } return(View(model)); }
public async Task <IActionResult> EditComment(int id) { Comment comment = _comment.GetCommentDB(id); if (comment == null) { return(NotFound()); } CreateCommentViewModel model = new CreateCommentViewModel { CommentText = comment.CommentText }; return(View(model)); }
public ActionResult CreateComment(CreateCommentViewModel model) { if (ModelState.IsValid) { Comment comment = new Comment() { AppUserId = CurrentSession.User.Id, BlogId = model.BlogId, Text = model.Text.Trim() }; int res = _commentManager.Insert(comment); } return(RedirectToAction("BlogPost", "Home", new { @Blog = model.BlogId })); }
public async Task <IActionResult> AddComment(CreateCommentViewModel model) { if (!this.ModelState.IsValid) { return(RedirectToAction(nameof(Details), routeValues: new { Id = model.PostId })); } var result = await this._blogService.AddComment(model.PostId, model.Author, model.Message); if (!result.Success) { return(RedirectToAction(nameof(Details), model.PostId)); } return(RedirectToAction(actionName: nameof(Details), routeValues: new { id = model.PostId })); }
public async Task <ActionResult> CreateComment(CreateCommentViewModel model) { if (ModelState.IsValid) { var comment = new ApplicationComment { UserId = User.Identity.GetUserId(), Comment = model.Comment, ArticleId = model.ArticleId, }; db.ApplicationComments.Add(comment); await db.SaveChangesAsync(); } return(RedirectToAction("Details", "Article", new { id = model.ArticleId })); }
public IActionResult CreateComment(int id, CreateCommentViewModel vm) { if (ModelState.IsValid) { Comment newComment = vm.Comment; newComment.UserId = _userManager.GetUserId(User); newComment.WrittenDate = DateTime.Now; newComment.productId = id; newComment.UserName = _userManager.GetUserName(User); newComment.numThumbsUp = 0; newComment.numThumbsDown = 0; vm.Product = _productService.GetById(id); _commentService.Create(newComment); } return(RedirectToAction("Details", "Product", new { id = vm.Product.Id, vm })); }
public async Task <IViewComponentResult> InvokeAsync( int postId, string viewName = "") { var model = new CreateCommentViewModel { PostId = postId }; if (viewName.IsNotNullOrEmpty()) { return(await Task.FromResult( View(viewName, model) )); } return(await Task.FromResult(View(model))); }
public void AddComment(CreateCommentViewModel comment) { var recipe = _repositoryRecipe.All().Where(r => r.Id == comment.RecipeId).FirstOrDefault(); if (recipe != null) { var com = new Comment { Content = comment.Content, Recipe = recipe, Date = comment.Date }; recipe.Comments.Add(com); } _repositoryRecipe.SafeChanges(); }
public async Task <IActionResult> Create([FromBody] CreateCommentViewModel model) { var user = HttpContext.User.Claims.FirstOrDefault(c => c.Type.Equals(ClaimsIdentity.DefaultNameClaimType)); var userEmail = user?.Value; var userId = (await _userService.GetByEmail(userEmail)).Id; var commentDto = new CommentDto() { Id = Guid.NewGuid(), NewsId = model.NewsId, Text = model.CommentText, CreateDate = DateTime.Now, UserId = userId }; await _commentService.AddComment(commentDto); return(Ok()); }
public IActionResult CreateComment(int toothId, [FromBody] CreateCommentViewModel createComment) { if (toothId != createComment.ToothId) { return(BadRequest()); } if (!_toothService.Exist(toothId)) { return(NotFound()); } var commentDTO = CommentMapper.CreateCommentVMToDTO(createComment); _commentService.Create(commentDTO); return(Ok(ModelState)); }
public ActionResult AddNewCommentForGame(CreateCommentViewModel model) { if (!ModelState.IsValid) { return(PartialView(model)); } GameDto game = _gameService.GetGameByKey(model.GameKey); if (game.Deleted && !User.IsInRole("Moderator")) { throw new GameDeletedException(); } _commentService.Create(User.Identity.Name, model.Body, model.ParentCommentId, game.Id, model.IsQuote); return(PartialView("CommentAdded")); }
public ActionResult Send(CreateCommentViewModel comment) { if (!User.IsInRole("user")) { throw new Exception("User is not authorized"); } bool commentIsEmpty = comment.Text == null || comment.Text.Equals(string.Empty); Mapper.Initialize(cfg => cfg.CreateMap <CreateCommentViewModel, CommentViewModelBLL>() .ForMember("Date", opt => opt.MapFrom(c => DateTime.Now)) .ForMember("CustomerId", opt => opt.MapFrom(c => User.Identity.GetUserId <int>())) .ForMember("Rating", opt => opt.MapFrom(c => c.Rating.ToCharArray().Where(r => r == '★').Count())) ); CommentViewModelBLL commentDto = Mapper.Map <CreateCommentViewModel, CommentViewModelBLL>(comment); if (ModelState.IsValid) { OperationDetails operationDetails = _commentService.Create(commentDto); _unitOfWork.Save(); if (!operationDetails.Succedeed) { ModelState.AddModelError(operationDetails.Property, operationDetails.Message); } var user = _userService.FindById(comment.PerformerId); if (user.CommentsBll != null) { user.Rating = (int)Math.Round((float)(user.CommentsBll.Select(c => c.Rating).Sum() / user.CommentsBll.Count)); } operationDetails = _userService.Update(user); _unitOfWork.Save(); if (!operationDetails.Succedeed) { ModelState.AddModelError(operationDetails.Property, operationDetails.Message); } } else { throw new Exception("Model is not valid"); } return(RedirectToAction("Details", "Performers", new { id = comment.PerformerId, emptyComment = commentIsEmpty })); }
private ActionResult SaveComment(int?id, CreateCommentViewModel formData) { if (!ModelState.IsValid) { return(View()); } Comment comment; if (!id.HasValue) { var userId = User.Identity.GetUserId(); var user = DbContext.Users.FirstOrDefault(p => p.Id == userId); var post = DbContext.PostDatabase.FirstOrDefault(p => p.PostId == formData.PostId); if (post == null) { return(View()); } comment = new Comment(); comment.Body = formData.Body; comment.AuthorId = userId; comment.UserId = userId; comment.User = user; DbContext.CommentDatabase.Add(comment); post.Comments.Add(comment); } else { comment = DbContext.CommentDatabase.FirstOrDefault(p => p.CommentId == id); if (comment == null) { return(RedirectToAction(nameof(HomeController.Index), "Home")); } comment.Body = formData.Body; comment.ReasonOfUpdating = formData.ReasonOfUpdating; comment.DateUpdated = DateTime.Now; } DbContext.SaveChanges(); return(RedirectToAction(nameof(HomeController.Index), "Home")); }
public async Task <ResponseModel <GenericModel> > ReplyGuide(CreateCommentViewModel viewModel) { Guid userId = JWTHelper.SeriallzeUserId(_httpContext); var responseModel = new ResponseModel <GenericModel>(); if (Guid.TryParse(viewModel.GuideId, out Guid guideId) && userId != Guid.Empty) { Guid commentId = await _commentManger.CreateComment(userId, guideId, viewModel.Content); await _commentReviewManager.CreateCommentReview(commentId); responseModel.Code = StateCode.Sucess; responseModel.Data = new GenericModel { IsSucess = true }; } return(responseModel); }
public IHttpActionResult Post(CreateCommentViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var comment = new CommentTransport { Content = model.Content, UserId = model.UserId, ExecutorId = model.ExecutorId }; //var comment = Mapper.Map<CreateCommentViewModel, CommentTransport>(model); CommentManager.CreateComment(comment); return(Ok()); }
/// <summary> /// Create new comment /// </summary> /// <param name="viewModel">comment data</param> /// <returns></returns> public async Task <Comment> CreateCommentAsync(CreateCommentViewModel viewModel) { Guard.Against.Null(viewModel, nameof(viewModel)); Guard.Against.GuidEmpty(viewModel.FromId, nameof(viewModel.FromId)); Guard.Against.GuidEmpty(viewModel.PostId, nameof(viewModel.PostId)); Guard.Against.NullOrEmpty(viewModel.Text, nameof(viewModel.Text)); //check post exists var post = await _postRepository.GetByIdAsync(viewModel.PostId); Guard.Against.PostNotExists(post, viewModel.PostId); //create post based on commentDto var comment = new Comment(viewModel.FromId, viewModel.PostId, new Content(viewModel.Text)); await _commentRepository.AddAsync(comment); return(await _commentRepository.GetByIdAsync(comment.Id)); }
public async Task <IActionResult> Comment(CreateCommentViewModel model) { model.CheckArgumentIsNull(nameof(model)); var post = await _postService.GetResultByIdAsync(model.PostId); post.CheckReferenceIsNull(nameof(post)); var commentData = model.Adapt <CreateCommentDto>(); var commentId = await _commentService.CreateAsync(commentData); return(RedirectToAction(nameof(Detail), new { id = post.Id, postType = post.PostTypeSlug, slug = post.Slug, lang = post.LangKey, commented = true })); }
public IActionResult Reply(CreateCommentViewModel replyComment) { if (!ModelState.IsValid) { return(View(nameof(Reply), replyComment)); } var game = _gameService.Get(replyComment.GameKey); if (game.IsDeleted) { return(RedirectToAction("NotFound", "Game")); } var comment = _mapper.Map <Comment>(replyComment); _commentService.AnswerComment(comment, replyComment.GameKey); return(RedirectToAction("GetDetails", "Game", new { gameKey = replyComment.GameKey })); }
public void ShouldReturnOKIfValidModelAndValidSave() { //Arrange CreateCommentViewModel mockComment = new CreateCommentViewModel(); mockComment.Comment = "hello"; mockComment.UserName = "******"; mockComment.MovieId = new Guid(); var successResult = new Result(ResultType.Success); var moqUserService = new Mock <ICommentsService>(); moqUserService.Setup(x => x.SaveComment(mockComment.MovieId, mockComment.UserName, mockComment.Comment)).Returns(successResult); var sut = new CommentsController(moqUserService.Object); //Act & Assert sut .WithCallTo(c => c.SaveComment(mockComment)) .ShouldGiveHttpStatus(HttpStatusCode.OK); }
public ActionResult AddComment(int id, [FromBody] CreateCommentViewModel createComment) { _logger.LogInformation("Call AddComment method with id {id}", id); var article = _articleManager.GetArticleById(id); if (article == null) { throw new EntityNotFoundException(typeof(Article), id); } var comment = MapCreateCommentToComment(createComment); comment.Date = DateTime.Now; comment.ArticleID = id; _commentManager.AddComment(comment); return(Ok()); }
public ActionResult EditComment(int?id) { if (!id.HasValue) { return(RedirectToAction(nameof(TicketsController.Tickets))); } string userId = User.Identity.GetUserId(); var comment = DbContext.TicketsCommentsDatabase.FirstOrDefault(p => p.Id == id); if (comment == null) { return(RedirectToAction(nameof(TicketsController.Tickets))); } var model = new CreateCommentViewModel(); model.Comment = comment.Comment; model.DateUpdated = comment.DateUpdated; return(View(model)); }
public ActionResult Create(CreateCommentViewModel commentViewModel) { var newComment = new Comment { Id = commentViewModel.Id, Name = commentViewModel.Name, Content = commentViewModel.Content, DateCreated = DateTime.Now, DateEdited = DateTime.Now, EntryId = commentViewModel.EntryId, }; if (User.Identity.IsAuthenticated) { var user = _db.Users.Find(User.Identity.GetUserId()); if (user == null) { return(new HttpUnauthorizedResult()); } newComment.Owner = user; newComment.OwnerId = user.Id; newComment.Name = user.UserName; } if (!User.Identity.IsAuthenticated && _db.Users.Select(u => u.UserName).Contains(commentViewModel.Name)) { ModelState.AddModelError("NameAlreadyTaken", Strings.NameAlreadyTaken); } if (ModelState.IsValid) { _db.Blog_Comments.Add(newComment); _db.SaveChanges(); return(RedirectToAction("Details", "Entry", new { Id = commentViewModel.EntryId })); } return(View("Create", commentViewModel)); }
public ActionResult Create(int id, CreateCommentViewModel model) { if (!ModelState.IsValid) { return(View()); } var post = Context.Posts.First(p => p.Id == id); var comment = new Comment(); comment.Body = model.Body; comment.DateCreated = DateTime.Now; comment.UserId = User.Identity.GetUserId(); comment.PostId = id; Context.Comments.Add(comment); Context.SaveChanges(); return(RedirectToAction(nameof(PostController.ViewPost), new { slug = post.Slug })); }
public ActionResult Create(CreateCommentViewModel model) { if (this.ModelState.IsValid) { if (!this.User.Identity.IsAuthenticated) { this.RedirectToAction("Register", "Account"); } try { var userId = this.User.Identity.GetUserId(); var newComment = this.Mapper.Map<Comment>(model); this.commentsService.Create(newComment, userId); } catch(Exception e) { } } return this.Redirect(this.Request.UrlReferrer.AbsolutePath); }
public ActionResult CreateComment(CreateCommentViewModel model) { if (model != null && ModelState.IsValid) { model.Content = this.sanitizeService.Sanitize(model.Content); model.CreatedOn = DateTime.UtcNow; var newComment = AutoMapper.Mapper.Map<Comment>(model); newComment.Animal = this.animals.GetById(newComment.AnimalId).FirstOrDefault(); newComment.UserId = User.Identity.GetUserId(); newComment.User = this.users.GetById(User.Identity.GetUserId()).FirstOrDefault(); this.comments.AddNew(newComment); var result = newComment.Animal.Comments; return this.PartialView("_Comments", result); } throw new HttpException(400, "Invalid Comment"); }
public ActionResult Version(int id, CreateCommentViewModel comment) { var version = this.Data.Versions.GetById(id); if (this.IsThesisStudentOrTeacher(version.ThesisId)) { if (ModelState.IsValid) { var userId = this.User.Identity.GetUserId(); var newComment = Mapper.Map<Comment>(comment); newComment.UserId = userId; newComment.VersionId = id; this.Data.Comments.Add(newComment); this.Data.SaveChanges(); var logger = this.loggerCreator.Create(this.Data); var log = new ThesisLog { ThesisId = version.ThesisId, UserId = userId, LogType = LogType.AddedComment, ForwardUrl = string.Format(GlobalPatternConstants.FORWARD_URL_WITH_ID, "Thesis", "Version", id) }; logger.Log(log); CreateNotification(version.ThesisId, userId, log.ForwardUrl, GlobalPatternConstants.NOTIFICATION_COMMENTED); return RedirectToAction("Version", "Thesis", new { id = id }); } return View(comment); } return RedirectToAction("Index", "Storage"); }