public async Task <IActionResult> PostComment([FromBody] AddCommentVM comment) { string userId = User.Claims.First(c => c.Type == "UserID").Value; var result = await _commentService.InsertComment(comment, userId); return(Ok(result));//return new comment mapped to view model }
public async Task <IActionResult> Add(AddCommentVM addCommentVM) { if (!ModelState.IsValid) { return(Redirect("/Expense/Detail/" + addCommentVM.ExpenseId)); } var user = await _userManager.FindByNameAsync(User.Identity.Name); _commentService.AddComment(addCommentVM, user); return(Redirect($"/Expense/Detail/{ addCommentVM.ExpenseId}")); }
/// <summary> /// Creates a comment from the comments view model /// </summary> /// <param name="commentToAdd"></param> /// <returns></returns> public static Comments MapCommentVMToComment(AddCommentVM commentToAdd) { Comments comment = new Comments { Post = commentToAdd.Post, CommentTime = commentToAdd.CommentTime, Comment = commentToAdd.Comment, UserFullName = commentToAdd.UserFullName, UserImage = commentToAdd.ImagePath }; return(comment); }
public async Task <CommentVM> InsertComment(AddCommentVM VM, string userId) { var comment = _mapper.Map <Comment>(VM); comment.UserID = userId; var result = Validate(comment); if (result.Succeeded) { return(_mapper.Map <CommentVM>(await _repository.InsertAsync(comment))); } else { throw new MemeSiteException(HttpStatusCode.BadRequest, "Validation failed", result); } }
public async Task <IActionResult> AddComment(AddCommentVM vm) { if (ModelState.IsValid) { string currentUserId = await OnGetSesstion(); var comment = new ArticleComment { ArticleId = vm.ArticleId, Comment = vm.Comment, CreateTime = DateTime.Now, Status = "active", OriginalId = 0, UserId = currentUserId }; _context.ArticleComment.Add(comment); _context.SaveChanges(); comment.OriginalId = comment.Id; _context.SaveChanges(); return(Json(new { success = true })); } return(Json(new { success = false })); }