public async Task <IActionResult> CreateComment(string userName, string Text, string itemId) { User User = await _userManager.FindByNameAsync(userName); Item item = _itemContext.Items.Where(o => o.Id == itemId).SingleOrDefault(); item.nComments++; Comment comment = new Comment { UserName = User.UserName, ItemId = itemId, Text = Text, Id = Guid.NewGuid().ToString(), Type = "Comment" }; _commentContext.Add(comment); User.nComments++; await _userManager.UpdateAsync(User); await _itemContext.SaveChangesAsync(); await _commentContext.SaveChangesAsync(); return(RedirectToAction("Item", "Item", new { itemId = itemId })); }
public void Post([FromBody] Comment value) { // _context.Comments.Comment.commentBillId = _context.Add(value); _context.SaveChanges(); }
public int CreateComment(Comment comment) { context.Add(comment); int max_id = context.comments.Max(c => c.id); var new_comment = context.comments.SingleOrDefault(c => c.id == max_id); context.SaveChanges(); return(new_comment.id); }
public async Task<IActionResult> PostComment(string Text) { Comment comment = new Comment(); comment.Text = Text; var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } comment.UserID = user.Email; if (ModelState.IsValid) { _context.Add(comment); await _context.SaveChangesAsync(); return RedirectToAction(nameof(Index)); } return View(comment); }
public ActionResult AddComment(Comment comment) { if (!ModelState.IsValid) { // handleSubmit handles validation, but I put this in here anyway return(RedirectToAction(nameof(Index))); } _context.Add(comment); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("Id,UserID,Text")] Comment comment) { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } comment.UserID = user.Email; if (ModelState.IsValid) { _context.Add(comment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(comment)); }
public async Task <IActionResult> Post(int id) { Like like = new Like(); var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } like.UserID = user.Email; like.CommentID = _context.Comments.Find(id); if (ModelState.IsValid) { _context.Add(like); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(like)); }