public virtual ActionResult AddComment(CommentViewModel commentVM) { if (!ModelState.IsValid) { JsonError("Invalid comment has entered"); //return new HttpStatusCodeResult(statusCode: HttpStatusCode.NotAcceptable); } commentVM.AuthorIp = Request.UserHostAddress; _commentService.AddNewComment(commentVM); return(PartialView("_CommentBody", commentVM)); }
public ActionResult NewComment(int gameId, CommentWebModel comment) { if (!ModelState.IsValid) { ViewBag.GameId = gameId; ViewBag.ParentCommentId = comment.ParentCommentId; return(PartialView(comment)); } _commentService.AddNewComment(comment.Body, gameId, comment.ParentCommentId, comment.Name); return(RedirectToAction("Comments", new { gameId })); }
public async Task <ActionResult> PostComment(Comment comment) { var ExistingUser = _userService.GetByEmail(comment.Email); if (ExistingUser.Result == null) { var user = new User(); user.Email = comment.Email; user.UserName = comment.Email; user.FirstName = comment.Name; user.Password = "******"; var response = await _userService.CreateUser(user); if (!response.Succeeded) { return(Ok(new ResponseFormat { Error = true, ErrorMessage = response.ErrorMessage })); } } comment.UserId = _userService.GetByEmail(comment.Email).Id; var Added = _commentService.AddNewComment(comment); if (Added >= 1) { return(Ok(new ResponseFormat { Success = true, Data = null })); } else { return(Ok(new ResponseFormat { Error = true, })); } }
public async Task <IActionResult> AddNewComment(int userId, CreateCommentDto newComment) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } else { if (ModelState.IsValid) { var userName = User.FindFirstValue(ClaimTypes.Name); // var email = User.FindFirst(ClaimTypes.Email).Value; newComment.AuthorName = userName; var result = _mapper.Map <Comment>(newComment); // result.AuthorEmail = email; await _commentService.AddNewComment(result); await _uow.SaveChangesAsync(); return(Ok(result)); } return(BadRequest()); } }
public async Task <IActionResult> AddComment(Comment newComment) { return(Ok(await _commentService.AddNewComment(newComment))); }