public async Task <IActionResult> Edit(int id, [Bind("CommentId,Comment,ThisDateTime,ArticleId,Rating")] ArticleComment articleComment) { if (id != articleComment.CommentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(articleComment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ArticleCommentExists(articleComment.CommentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(articleComment)); }
public ArticleCommentDto CreateComment(ArticleCommentDto articleCommentDto) { ArticleComment articleComment = _mapper.Map <ArticleComment>(articleCommentDto); _articleCommentRepository.Create(articleComment); return(articleCommentDto); }
public ActionResult Create(AnnouncementCommentViewModel commentViewModel) { if (ModelState.IsValid) { var comment = new ArticleComment() { Id = commentViewModel.CommentId, ArticleId = commentViewModel.AnnouncementId, Comment = commentViewModel.Comment, CreatedAt = DateTime.Now, UserId = WebSecurity.CurrentUserId }; try { _articleCommentRepository.Save(comment); } catch (DataException) { TempData["error"] = ProjectConfiguration.Get.DataErrorMessage; } return(RedirectToAction("Details", "Article", new { Id = comment.ArticleId })); } TempData["Comment"] = commentViewModel.Comment; return(RedirectToAction("Details", "Article", new { Id = commentViewModel.AnnouncementId })); }
async Task OnPostComment() { ArticleComment item = new ArticleComment(); item.ArticleId = articleId; item.Content = comment; item.Name = user.Identity.Name; item.CreateBy = UserManager.GetUserId(user); item.CreateDate = DateTime.Now; item.Email = UserManager.GetUserName(user); item.Active = true; try { await Repository.ArticleComment.ArticleCommentPostComment(item); await InitData(); comment = ""; StateHasChanged(); toastService.ShowToast(ToastLevel.Success, "Bạn dã gửi bình luận thành công", "Thành công"); } catch (Exception ex) { toastService.ShowToast(ToastLevel.Error, "Có lỗi trong quá trình gửi bình luận", "Thất bại"); } }
public JsonResult ReportComment(int id_c, string text_reason) { ArticleComment comment = db.ArticleComment.Find(id_c); if (comment == null) { return(Json("Error")); } comment.Reported = true; comment.Reported_reason = text_reason; comment.Reported_ip = (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? Request.ServerVariables["REMOTE_ADDR"]).Split(',')[0].Trim(); Notification n = new Notification() { Date = DateTime.Now, Type = Notification_type.comment, Name = "Zgłoszono komentarz", Url = Url.Action("") }; n = db.Notifications.Add(n); foreach (var item in db.Users.Where(p => p.UserType == Models.UserType.Admin || p.UserType == UserType.Mod).ToList()) { item.User_Notification.Add(n); } db.SaveChanges(); return(Json("Reported")); }
private void InitializeFields() { this.firstCookingHubUser = new CookingHubUser { Id = "1", FullName = "Stamat Stamatov", UserName = "******", Gender = Gender.Male, }; this.firstCategory = new Category { Name = "Vegetables", Description = "Test category description", }; this.firstArticle = new Article { Id = 1, Title = "Test article title", Description = "Test article description", ImagePath = "https://someimageurl.com", CategoryId = 1, UserId = "1", }; this.firstArticleComment = new ArticleComment { ArticleId = this.firstArticle.Id, Content = "Nice article.", UserId = this.firstCookingHubUser.Id, }; }
public ArticleCommentViewModel(ArticleComment comment) { Name = comment.Name; Message = comment.Message; Response = comment.Response; DateCreated = comment.DateCreated.ToString(); }
public ActionResult Create(FormCollection collection) { long articleId = long.Parse(collection["ArticleId"]); long? inReplyToArticleCommentId = string.IsNullOrEmpty(collection["InReplyToArticleCommentId"]) ? default(long?) : long.Parse(collection["InReplyToArticleCommentId"]); var article = Context.Articles.Where(a => a.ID == articleId).SingleOrDefault(); if (article == null || article.PublicationDate > DateTime.UtcNow || (article.ExpirationDate.HasValue && article.ExpirationDate < DateTime.UtcNow)) return View("NoSuchComment"); if (article.CommentsFrozen) return View("NoSuchComment"); ArticleComment comment = new ArticleComment { Article = article, ArticleID = articleId, AuthorUser = CurrentUser, // ReSharper disable PossibleInvalidOperationException AuthorUserID = CurrentUserId.Value, // ReSharper restore PossibleInvalidOperationException Body = collection["Body"], CreateDate = DateTime.UtcNow, InReplyToArticleCommentID = (inReplyToArticleCommentId == null || inReplyToArticleCommentId == 0) ? default(long?) : inReplyToArticleCommentId.Value, InReplyTo = (inReplyToArticleCommentId == null || inReplyToArticleCommentId == 0) ? null : Context.ArticleComments.Where(ac => ac.ID == inReplyToArticleCommentId.Value).Single(), Subject = collection["Subject"] }; Context.ArticleComments.AddObject(comment); Context.SaveChanges(); return RedirectToAction("Details", "Article", new { id = articleId }); }
public async Task AddCommentShouldIncreaseCommentCount() { // Arrange var db = this.GetDatabase(); var user = new User { Id = "admin", Email = "*****@*****.**" }; var firstArticle = new Article { Id = 1, Title = "First article", Content = new String('p', 255) }; var articleComment = new ArticleComment { ArticleId = 1, Content = "Asd", Author = user, AuthorId = "admin" }; await db.Articles.AddAsync(firstArticle); await db.Comments.AddAsync(articleComment); await db.SaveChangesAsync(); var articleService = new ArticleService(db); // Act var result = articleService.AddCommentAsync(firstArticle.Id, articleComment.Content, user.Id); // Assert firstArticle .Comments .Count .Should() .Be(2); }
public IActionResult Post([FromBody] ArticleCommentModel model) { try { if (ModelState.IsValid) { var entity = new ArticleComment { CommentText = model.CommentText, ArticleId = model.ArticleId, IsApproved = model.IsApproved }; _articleService.AddArticleComment(entity); return(Ok()); } return(new BadRequestResult()); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <IActionResult> UpdateComment(CommentVM vm) { if (ModelState.IsValid) { string currentUserId = await OnGetSesstion(); var comment = _context.ArticleComment.Where(x => x.Id == vm.Id && x.UserId == currentUserId).SingleOrDefault(); if (comment == null) { return(NotFound()); } comment.Status = "history"; ArticleComment updatedComment = new ArticleComment { OriginalId = comment.Id, ArticleId = comment.ArticleId, Comment = vm.Comment, CreateTime = DateTime.Now, Status = "active", UserId = currentUserId }; _context.ArticleComment.Add(updatedComment); _context.SaveChanges(); return(Json(new { success = true })); } return(Json(new { success = false })); }
public IResult CreateArticleComment(AddArticleCommentDto addArticleCommentDto) { var errorResult = BusinessRules.Run(CheckAuthenticatedUserExist(), IsArticleExist(addArticleCommentDto.ArticleId.Value)); if (errorResult != null) { return(errorResult); } var user = _authService.GetAuthenticatedUser().Result.Data; var article = _uow.Articles.Get(x => x.Id == addArticleCommentDto.ArticleId.Value); var articleComment = new ArticleComment() { UserId = user.Id, ArticleId = addArticleCommentDto.ArticleId.Value, Comment = addArticleCommentDto.Comment }; _uow.ArticleComments.Add(articleComment); _uow.Commit(); return(new SuccessResult(Message.ArticleCommentCreated)); }
public ActionResult ArticleComment() { ArticleComment comment = new ArticleComment { LikeCount = 0, }; comment.Comment = Request["Comment"]; if (String.IsNullOrEmpty(comment.Comment)) { return(RedirectToAction("Index")); } comment.ArticleId = Int32.Parse(Request["ArticleId"]); comment.LastUpdate = DateTime.Now; if (Request.IsAuthenticated) { comment.UserName = User.Identity.Name; } else { comment.UserName = "******"; } db.ArticleComments.Add(comment); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// 获取评论 /// </summary> /// <param name="connection"></param> /// <param name="ID"></param> /// <returns></returns> public static ArticleComment GetByID(SqlConnection connection, int ID) { ArticleComment _ArticleComment = null; var parameters = new[] { new SqlParameter("@ID", ID) }; var sqlcmd = @"SELECT TOP 1 [ID], [PKID], [Category], [Title], [PhoneNum], [UserID], [UserHead], [CommentContent], [CommentTime], [AuditStatus], [AuditTime], [Sort] FROM Marketing.dbo.[tbl_Comment] WITH (NOLOCK) WHERE ID=@ID" ; using (var dt = SqlHelper.ExecuteDataTable(connection, CommandType.Text, sqlcmd, parameters)) { _ArticleComment = dt.Rows.Cast <DataRow>().Select(row => { return(new ArticleComment(row)); }).FirstOrDefault(); } return(_ArticleComment); }
public List <ArticleComment> AllCommentByArticleId(string articleId) { SqlConnection connection = new SqlConnection(dbConnectionString); string query = "SELECT * FROM tbl_comment WHERE article_id = '" + articleId + "' ORDER BY id DESC"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); List <ArticleComment> commentList = new List <ArticleComment>(); while (reader.Read()) { ArticleComment comment = new ArticleComment(); comment.CommentArticleId = reader["id"].ToString(); comment.CommentUserName = reader["user_name"].ToString(); comment.CommentDescription = reader["comment_description"].ToString(); comment.Date = reader["date"].ToString(); commentList.Add(comment); } reader.Close(); connection.Close(); return(commentList); }
public ActionResult Edit(ArticleComment comment) { try { comment.LastUpdate = DateTime.Now; ViewBag.Success = true; if (comment.ID == -1) { ArticleComments.Insert(comment); UserNotifications.Send(UserID, String.Format("ویرایش نظر '{0}'", comment.Subject), "/Admin/ArticleComments/Edit/" + comment.ID, NotificationType.Success); comment = new ArticleComment(); } else { ArticleComments.Update(comment); } } catch (Exception ex) { SetErrors(ex); } return(ClearView(model: comment)); }
public JsonResult Comment(int ida, string CommentName, string CommentText) { ArticleComment comment = new ArticleComment() { Text = CommentText, CreateDate = DateTime.Now, CreateIp = (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? Request.ServerVariables["REMOTE_ADDR"]).Split(',')[0].Trim(), ModDate = DateTime.Now, ModIp = (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? Request.ServerVariables["REMOTE_ADDR"]).Split(',')[0].Trim(), IsShow = true, Reported = false }; Article article = db.Articles.Find(ida); if (Request.IsAuthenticated) { comment.User = db.Users.Single(p => p.Email == User.Identity.Name); comment.Name = null; } else { comment.Name = CommentName; } UpdateModel(comment); article.Comments.Add(db.ArticleComment.Add(comment)); UpdateModel(article); db.SaveChanges(); if (article == null) { return(Json("Error")); } return(Json(comment)); }
public ActionResult ArticleCommentAdd(int articleId, ArticlePostModel model, bool captchaValid) { var article = _articleService.GetArticleById(articleId); if (article == null || !article.AllowComments) { return(HttpNotFound()); } if (_workContext.CurrentUser.IsGuest() && !_catalogSettings.AllowNotRegisteredUsersToLeaveComments) { ModelState.AddModelError("", _localizationService.GetResource("Article.Comments.OnlyRegisteredUsersLeaveComments")); } //validate CAPTCHA if (_captchaSettings.Enabled && _captchaSettings.ShowOnArticleCommentPage && !captchaValid) { ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha")); } if (ModelState.IsValid) { var comment = new ArticleComment() { ArticleId = article.Id, AddTime = DateTime.Now, UserId = _workContext.CurrentUser.Id, IpAddress = _webHelper.GetCurrentIpAddress(), CommentText = model.AddNewComment.CommentText, CommentTitle = model.AddNewComment.CommentTitle, IsApproved = true }; comment.AddEntitySysParam(true, true); _userContentService.InsertUserContent(comment); //update totals _articleService.UpdateCommentTotals(article); //notify a site owner //if (_articleSettings.NotifyAboutNewArticleComments) // _workflowMessageService.SendArticleCommentNotificationMessage(comment, _localizationSettings.DefaultAdminLanguageId); //activity log _userActivityService.InsertActivity("PublicSite.AddArticleComment", _localizationService.GetResource("ActivityLog.PublicSite.AddArticleComment")); //The text boxes should be cleared after a comment has been posted //That' why we reload the page TempData["sm.article.addcomment.result"] = _localizationService.GetResource("Article.Comments.SuccessfullyAdded"); return(RedirectToRoute("Article", new { SeName = article.GetSeName() })); // codehint: sm-delete //return RedirectToRoute("ArticlePost", new { SeName = article.GetSeName(article.LanguageId, ensureTwoPublishedLanguages: false) }); } //If we got this far, something failed, redisplay form _helper.PrepareArticleDetailModel(model, article, true); return(View(model)); }
public ActionResult DeleteConfirmed(int id) { ArticleComment articleComment = db.ArticleComments.Find(id); db.ArticleComments.Remove(articleComment); db.SaveChanges(); return(RedirectToAction("Index")); }
public ArticleCommentModel(RacLib.RacMsg msgs, ArticleComment n) { Id = n.id; Comment = n.comment; IncludedBy = n.userName; Included = msgs.ShowDate(n.date); IncludedById = n.userId; }
public string DeleteArticleCommentConfirmed(int id) { ArticleComment comment = db.ArticleComments.Find(id); db.ArticleComments.Remove(comment); db.SaveChanges(); return(""); }
public void AddArticleComment(ArticleComment articleComment) { if (articleComment == null) { throw new ArgumentNullException("articleComment"); } _repositoryArticleComment.Insert(articleComment); }
public void UpdateArticleComment(ArticleComment articleComment) { if (articleComment == null) { throw new ArgumentNullException("arcticleComment"); } _repositoryArticleComment.Update(articleComment); }
public ActionResult addComment(ArticleComment std) { std.Date = DateTime.Now; db.ArticleComments.Add(std); db.SaveChanges(); string message = "SUCCESS"; return(Json(new { Message = message, JsonRequestBehavior.AllowGet })); }
public ActionResult Edit(ArticleComment comment) { if (ModelState.IsValid) { _repo.Update(comment); return(RedirectToAction("Index", new { articleId = comment.ArticleId })); } return(View(comment)); }
public ArticleCommentViewModel(ArticleComment comment) { this.Id = comment.Id; this.ParentId = comment.ParentId; this.Name = comment.Name; this.Email = comment.Email; this.Message = comment.Message; this.AddedDate = comment.AddedDate != null ? new PersianDateTime(comment.AddedDate.Value).ToString("dddd d MMMM yyyy ساعت hh:mm:ss tt") : "-"; }
public IActionResult Add(ArticleComment articleComment) { var result = _articleCommentService.Add(articleComment); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public ArticleComment Add(ArticleComment comment) { using (var context = new PunchClockDbContext()) { comment.IsDeleted = false; context.ArticleComments.Add(comment); context.SaveChanges(); } return(comment); }
public ActionResult AnswerComment(ArticleComment comment) { var user = _repo.GetCurrentUser(); comment.Name = user != null? $"{user.FirstName} {user.LastName}" : "ادمین"; comment.Email = user != null ? user.Email :"-"; comment.AddedDate = DateTime.Now; _repo.Add(comment); return(RedirectToAction("Index", new { articleId = comment.ArticleId })); }
public void DeleteArticleComment(ArticleComment articlecomment) { if (articlecomment == null) { throw new ArgumentNullException("articlecomment"); } articlecomment.Deleted = true; UpdateArticleComment(articlecomment); }
public async System.Threading.Tasks.Task <ActionResult> AddAsync(long?id, string ccont, long?parentId) { var result = new ResultModel(); if (id == null || id < 0) { result.Code = 1002; result.Message = " id "; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrEmpty(ccont)) { result.Code = 1002; result.Message = " ccont "; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } try { ArticleComment comment = new ArticleComment() { articleId = (long)id, contents = ccont, creatorId = long.Parse((User.Identity as ClaimsIdentity).Claims.FirstOrDefault(m => m.Type == ClaimTypes.Sid).Value), creationTime = DateTime.Now, creatorName = User.Identity.Name, imgUrl = (User.Identity as ClaimsIdentity).Claims.FirstOrDefault(m => m.Type == ClaimTypes.Uri).Value, parentId = parentId ?? 0, status = 2 }; await repository.InsertAsync(comment); var add = await repository.UnitOfWork.CommitAsync(); if (add == 1) { result.Code = 0; result.Message = string.Empty; result.Data = comment; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } else { result.Code = 1003; result.Message = "not found"; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { result.Code = 1001; result.Message = ex.Message; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } }
public ActionResult Load(int id) { Article a = new Article() { Title = "Este é um post no blog!", Description = "Esse é o texto de um artigo para o teste da framework!", id = 1 }; ArticleComment c = new ArticleComment() { id = id, Name = "Callebe", Comment = "Teste de comentário sendo carregado", Article = a }; return View(c); }
public ActionResult New(ArticleComment articleComment) { if (articleComment != null) { articleComment.id = 3; } return View(articleComment); }
public ActionResult Update(int id, ArticleComment articleComment) { if (articleComment != null) { articleComment.id = id; } return View(articleComment); }