public static EditCommentDTO CommentEditViewModel_To_EditCommentDTO(CommentEditViewModel commentEditViewModel) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <CommentEditViewModel, EditCommentDTO>()).CreateMapper(); EditCommentDTO editCommentDTO = mapper.Map <CommentEditViewModel, EditCommentDTO>(commentEditViewModel); return(editCommentDTO); }
public async Task <IActionResult> Edit(int id, [Bind("CommentId,Title,EmployeeNumber,Date,Post,SubmittedBy,Category")] CommentEditViewModel commentEditViewModel) { if (id != commentEditViewModel.CommentId) { return(NotFound()); } if (ModelState.IsValid) { try { commentEditViewModel.SubmittedBy = User.FindFirstValue(ClaimTypes.Name); var comment = _mapper.Map <Comment>(commentEditViewModel); await _commentRepository.Update(comment); } catch (DbUpdateConcurrencyException) { if (!CommentExists(commentEditViewModel.CommentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["EmployeeNumber"] = new SelectList(await _employeeRepository.GetAll(), "EmployeeNumber", "EmployeeNumber", commentEditViewModel.EmployeeNumber); return(View(commentEditViewModel)); }
public async Task <IActionResult> EditCommentAsync(CommentEditViewModel commentEditViewModel) { if (!this.ModelState.IsValid) { return(RedirectToAction("BookDetails", "Book", new { id = commentEditViewModel.BookId })); } var comment = await this.commentRepository.GetByIdAsync(commentEditViewModel.CommentId); if (comment == null) { return(RedirectToAction("BookDetails", "Book", new { id = commentEditViewModel.BookId })); } var isAdmin = this.User.IsInRole("Admin"); var currentLoggedUser = await this.applicationUserRepository.GetByExpressionAsync(u => u.Id == comment.UserId); var isOwner = currentLoggedUser.Id == comment.UserId; if (!isAdmin && !isOwner) { return(RedirectToAction("Index", "Home")); } comment.Content = commentEditViewModel.Content; await this.commentUpdateService.UpdateAsync(comment); return(RedirectToAction("BookDetails", "Book", new { id = commentEditViewModel.BookId })); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var database = new ApplicationDbContext()) { var comment = database.Comments.FirstOrDefault(c => c.Id == id); if (comment == null) { return(HttpNotFound()); } if (!IsAuthorizedToEdit(comment)) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } var model = new CommentEditViewModel(); model.Content = comment.Content; model.TargetName = comment.Target.UserName; return(View(model)); } }
public string editComment(CommentEditViewModel commentEditViewModel) { commentEditViewModel.modified = DateTime.Now; EditCommentDTO editCommentDTO = MapperModule.CommentEditViewModel_To_EditCommentDTO(commentEditViewModel); commentService.EditComment(editCommentDTO); return(JsonConvert.SerializeObject(new { id = commentEditViewModel.id, content = commentEditViewModel.content, modified = commentEditViewModel.modified })); }
public ActionResult Edit(CommentEditViewModel editedComment) { if (ModelState.IsValid) { this.commentServices.ModifyComment(editedComment); return(RedirectToAction("Index")); } return(View(editedComment)); }
/// <summary> /// Adds the comment. /// </summary> /// <param name="comment">The comment.</param> /// <returns></returns> public CommentDisplayViewModel AddComment(CommentEditViewModel comment) { var entry = this.unitOfWork.Entries.GetById(comment.EntryID); if (entry == null) { return(null); } var commentID = Guid.NewGuid(); var homePage = !string.IsNullOrWhiteSpace(comment.Website) ? comment.Website.Replace("http://", "") : string.Empty; Person owner = null; if (!string.IsNullOrWhiteSpace(comment.Email)) { var emailHash = GetMd5Hash(comment.Email); owner = this.unitOfWork.People.GetByEmailHash(emailHash); } // if no email is provided, or the user with the email is not yet in the table if (owner == null) { // create a new person for this comment owner = new Person { DisplayName = comment.DisplayName, EmailHash = string.Empty, HomePage = homePage }; } var isEntryOwner = owner == entry.Author; var c = new Comment() { CommentId = commentID, Content = comment.Content, CreationDate = DateTimeOffset.UtcNow, Owner = owner, IsEntryOwner = isEntryOwner }; entry.Comments.Add(c); entry.TotalComments++; this.unitOfWork.Commit(); var commentVO = new CommentDisplayViewModel(); commentVO.Content = c.Content; commentVO.DisplayName = c.Owner.DisplayName; commentVO.EmailHash = c.Owner.EmailHash; commentVO.UtcTimeString = c.CreationDate.UtcDateTime.ToString("MM/dd/yyyy HH:mm"); commentVO.IsBlogOwner = c.IsEntryOwner; commentVO.Website = c.Owner.HomePage; return(commentVO); }
public async Task <IActionResult> CreateAsync(int id, CommentEditViewModel evm) { Question question = questionRepo.GetQuestionById(id); IdentityUser user = await userManager.GetUserAsync(HttpContext.User); Comment comment = new Comment(question, evm.Comment, user.UserName); question.Comments.Add(comment); commentRepo.SaveChanges(); return(RedirectToAction("Index", "Question", new { id = question.PostId })); }
public CommentDetailsViewModel ModifyComment(CommentEditViewModel editedComment) { Comment comment = this.GetCommentById(editedComment.Id); comment.Content = editedComment.Content; this.Data.Comments.Update(Mapper.Map <Comment>(comment)); this.Data.SaveChanges(); return(Mapper.Map <CommentDetailsViewModel> (comment)); }
public IActionResult Edit(int id, CommentEditViewModel input) { var comment = _commentData.Get(id); if (comment != null && ModelState.IsValid) { comment.Text = input.Text; _commentData.Commit(); return(RedirectToAction("Details", new { id = comment.Id })); } return(View(comment)); }
public virtual PartialViewResult EditView(Guid id, string updateElementId) { var comment = _commentsService.Get(id); var model = new CommentEditViewModel { Id = id, Text = comment.Text, UpdateElementId = updateElementId }; return(PartialView(EditViewPath, model)); }
public async Task Edit(CommentEditViewModel viewModel) { var comment = await _comment .Include(a => a.Creator) .FirstAsync(a => a.Id == viewModel.Id); viewModel.Creator = comment.Creator; viewModel.Post = comment.Post; _mappingEngine.Map(viewModel, comment); await _unitOfWork.SaveChangesAsync(); }
public async Task <ActionResult> Edit(CommentEditViewModel viewModel) { if (ModelState.IsValid) { viewModel.ModifierId = long.Parse(User.Identity.GetUserId()); await _commentService.Edit(viewModel); return(RedirectToAction("Index")); } ViewBag.Message = "ثبت انجام نشد."; return(View(viewModel)); }
// GET: Administration/Comments/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CommentEditViewModel comment = this.commentServices.CreatEditViewModelFromCommentId(id); if (comment == null) { return(HttpNotFound("Comment not found")); } return(View(comment)); }
public async Task <IActionResult> Edit(CommentEditViewModel input) { if (!ModelState.IsValid) { return(RedirectToAction("Details", "Assignments", new { id = input.AssignmentId })); } input.ModifiedOn = DateTime.UtcNow; var comment = input.To <CommentEditDto>(); await this.commentsService.EditAsync(comment); return(RedirectToAction("Details", "Assignments", new { id = input.AssignmentId })); }
public IActionResult Edit(string value) { CommentEditViewModel model = JsonConvert.DeserializeObject <CommentEditViewModel>(value); if (model.Id == 0) { commentsService.Insert(model); } else { commentsService.Update(model); } return(RedirectToAction("Details", "UserJobOffers", new { id = model.JobOfferId })); }
public ActionResult AddComment(int issueId) { var person = personFacade.GetPeople(new PersonFilter { Email = User.Identity.Name }).First(); var commentEditViewModel = new CommentEditViewModel() { Comment = new CommentDTO() { OwnerName = person.Name, IssueId = issueId, CreationTime = DateTime.Now, OwnerId = person.Id }, }; return(View(commentEditViewModel)); }
public IActionResult Create(CommentEditViewModel model) { if (ModelState.IsValid) { var comment = new Comment { Text = model.Text }; _commentData.Add(comment); _commentData.Commit(); return(RedirectToAction("Details", new { id = comment.Id })); } return(View()); }
public async Task <IHttpActionResult> EditComment([FromUri] int postId, [FromBody] CommentEditViewModel newComment) { DTOPost post = await _uow.PostService.GetPostByPosId(postId); if (post == null) { return(NotFound()); } if (post.IsBlocked) { return(BadRequest("This post blocked")); } var userId = User.Identity.GetUserId(); if (userId == null) { return(this.Unauthorized()); } if (newComment.CommentBody.Length < 1) { return(this.BadRequest("Please write comment.")); } var comment = await _uow.CommentService.GetCommentByComId(newComment.Id); if (comment == null) { return(NotFound()); } if (comment.UserInfoId != Int32.Parse(userId)) { return(BadRequest("It is not your comment")); } comment.CommentBody = newComment.CommentBody; comment.UserInfo = null; comment.Post = null; await _uow.CommentService.EditComment(comment); return(Ok("Comment edited")); }
public async Task <CommentListViewModel> Edit(CommentEditViewModel model, string userId) { Comments comment = await unitOfWork.CommentsRepository.GetAll() .FirstOrDefaultAsync(c => c.CommentId == model.CommentId) ?? throw new ArgumentException("Коментарът, който искате да редактирате не съществува!");; if (!await IsAdminOrOwner(userId, comment)) { throw new NotAuthorizedUserException("Коментарър, който искате да редактирате не е създаден от вас!"); } Mapper.Map(model, comment); unitOfWork.CommentsRepository.Edit(comment); unitOfWork.Save(); return(Mapper.Map <CommentListViewModel>(comment)); }
public IActionResult Comment(int id) { var post = _postData.Get(id); if (post == null) { return(RedirectToAction("Details", new { id = post.Id })); } var cvm = new CommentEditViewModel() { Post = post, Commenter = _userManager.GetUserAsync(User).Result, Content = "" }; return(View(cvm)); }
public IActionResult Edit(CommentEditViewModel model) { Comment target = this.comments.GetById(model.Id); if (target.AuthorId != userManager.GetUserId(User)) { return(Forbid("You do not have permission to edit this comment")); } if (!ModelState.IsValid) { return(BadRequest("Invalid post data")); } this.comments.Edit(model.Id, model.NewContent); return(Ok()); }
public ActionResult Edit(CommentEditViewModel vm, int ResId, int id) { var comment = db.Comments.Find(vm.ID); var CreatedDate = comment.DateTime; if (ModelState.IsValid) { comment.Message = vm.Message; comment.UserId = User.Identity.GetUserId(); comment.UserName = HttpContext.User.Identity.Name; comment.DateTimeEdit = System.DateTime.Now; comment.DateTime = CreatedDate; comment.ResourceID = ResId; db.SaveChanges(); return(RedirectToAction("Details", "Resources", new { id = ResId })); } return(View()); }
public async Task <IActionResult> EditCommentAsync(string commentId) { if (commentId == null) { return(RedirectToAction("Index", "Home")); } var comment = await this.commentRepository.GetByIdAsync(commentId); var commentEditModel = new CommentEditViewModel { BookId = comment.BookId, CommentId = comment.CommentId, Content = comment.Content }; return(View("CommentEditView", commentEditModel)); }
public async Task <IActionResult> EditCommentAsync(CommentEditViewModel commentEditViewModel) { if (commentEditViewModel == null) { return(RedirectToAction("Index", "Home")); } if (commentEditViewModel.Content != null) { var comment = await this.commentRepository.GetByIdAsync(commentEditViewModel.CommentId); comment.Content = commentEditViewModel.Content; await this.commentUpdateService.UpdateAsync(comment); } return(RedirectToAction("BookDetails", "Book", new { id = commentEditViewModel.BookId })); }
public IActionResult Delete(int?id) { if (!id.HasValue) { return(RedirectToAction("List", "UserJobOffers")); } CommentEditViewModel model = commentsService.GetById(id.Value); if (model == null) { return(RedirectToAction("List", "UserJobOffers")); } commentsService.Delete(model.Id); return(RedirectToAction("Details", "UserJobOffers", new { id = model.JobOfferId })); }
public ActionResult Edit([Bind(Include = "CommentGuid,SpotGuid,Title,Text")] CommentEditViewModel commentEditViewModel) { if (ModelState.IsValid) { Comment comment = db.Comments.Find(commentEditViewModel.CommentGuid); comment.SpotGuid = commentEditViewModel.SpotGuid; comment.Title = commentEditViewModel.Title; comment.Text = commentEditViewModel.Text; comment.DateModified = DateTime.Now; comment.UserModifiedID = Auxiliaries.GetUserId(User); db.Entry(comment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.SpotGuid = new SelectList(db.Spots, "SpotGuid", "SpotName", commentEditViewModel.SpotGuid); return(View(commentEditViewModel)); }
/// <summary> /// Verifies if the comment is spam or not. /// </summary> /// <param name="comment">The comment.</param> /// <returns> /// <c>true</c> if the comment is spam, else <c>false</c> /// </returns> public async Task <bool> VerifySpamAsync(CommentEditViewModel comment, string ipAddress, string userAgent) { var akismetComment = this.akismet.CreateComment(); akismetComment.CommentAuthor = comment.DisplayName; akismetComment.CommentAuthorEmail = comment.Email; akismetComment.CommentAuthorUrl = comment.Website; akismetComment.CommentContent = comment.Content; akismetComment.CommentType = Akismet.Net.CommentTypes.Comment; akismetComment.Permalink = comment.Permalink; akismetComment.Referrer = string.Empty; akismetComment.UserAgent = userAgent; akismetComment.UserIp = ipAddress; var commentResult = await this.akismet.CheckCommentAsync(akismetComment); return(commentResult == CommentCheck.Ham); }
public async Task <Response> AddAsync([FromBody] CommentEditViewModel comment) { if (comment is null) { return(new FailedResponse((int)HttpStatusCode.Created)); } if (string.IsNullOrWhiteSpace(comment.Author)) { return(new FailedResponse((int)HttpStatusCode.BadRequest, "Please enter your name")); } if (string.IsNullOrWhiteSpace(comment.Email)) { return(new FailedResponse((int)HttpStatusCode.BadRequest, "Please enter your email")); } if (string.IsNullOrWhiteSpace(comment.Comment)) { return(new FailedResponse((int)HttpStatusCode.BadRequest, "Please enter your comment")); } if (!comment.Email.IsValidEmail()) { return(new FailedResponse((int)HttpStatusCode.BadRequest, "Please enter a valid email address")); } var commentRequest = commonFactory.Mapper.Map <CommentRequest>(comment); commentRequest.IpAddress = commonFactory.HttpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(); var userClaim = HttpContext.Session.Get <UserClaim>(SessionHelper.SessionLogin); if (userClaim != null) { commentRequest.UserAgent = userClaim.UserName; } await repositoryFactory.Comment.AddAsync(commentRequest).ConfigureAwait(false); return(new SuccessResponse()); }
public IActionResult Comment(int id, CommentEditViewModel comment) { var user = _userManager.GetUserAsync(User).Result; var post = _postData.Get(id); if (ModelState.IsValid) { var newComment = new Comment() { Post = post, Content = comment.Content, Commenter = user }; newComment = _commentData.Add(newComment); _commentData.Commit(); return(RedirectToAction("Details", new { id = post.Id })); } return(RedirectToAction("Index")); }