public async Task <HttpResponseMessage> PostCommenting(CommentingVm commentingVm) { var client = _request.SendAccessToken().Result; HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(commentingVm), Encoding.UTF8, "application/json"); var response = await client.PostAsync("/api/Commenting", httpContent); return(response.EnsureSuccessStatusCode()); }
public async Task <ActionResult> PostCommenting(CommentingVm commentingVm) { var comment = new Comment(); comment.Star = commentingVm.star; comment.Date = commentingVm.date; comment.Content = commentingVm.content; comment.ProductID = commentingVm.productId; comment.UserName = commentingVm.userName; _applicationDbContext.Comments.Add(comment); await _applicationDbContext.SaveChangesAsync(); return(StatusCode(200)); }
public async Task <ActionResult> PostCommenting(IFormCollection f, int productId) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction(actionName: "SignIn", controllerName: "Account")); } var CommentingVm = new CommentingVm(); CommentingVm.star = Convert.ToInt32(f["rating"]); CommentingVm.date = DateTime.Today; CommentingVm.content = f["content"]; CommentingVm.productId = Convert.ToInt32(productId); CommentingVm.userName = @User.Identity.Name; await _commentingClient.PostCommenting(CommentingVm); string referer = Request.Headers["Referer"].ToString(); return(Redirect(referer)); }