public async Task <ActionResult <CommentPostModel> > PostCommentPostModel([Bind("Id, IdentityUser,PostModelId,Comment")] CommentPostModel commentPostModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { _unitOfWork.BeginTransaction(); await _commentPostServices.CreateAsync(commentPostModel); await _unitOfWork.CommitAsync(); } catch (ModelValidationExceptions e) { ModelState.AddModelError(e.PropertyName, e.Message); return(BadRequest(ModelState)); } return(base.Ok()); }
public async Task <IActionResult> CreateComment(string comment, int idPost) { try { var userId = await GetUserIdentityAsync(); var commentPostModel = new CommentPostModel { Comment = comment, PostModelId = idPost, IdentityUser = userId, DataDoComment = DateTime.Now }; await _commentPostServices.CreateAsync(commentPostModel); return(RedirectToAction("Index", "Home")); } catch { return(RedirectToAction("Index", "Home")); } }