public async Task <IActionResult> Edit(int id, [Bind("SpreadCommentId,Comment")] SpreadComment spreadComment) { var user = await GetCurrentUserAsync(); spreadComment.UserId = user.Id; spreadComment.SpreadId = _context.SpreadComment.AsNoTracking().Where(sc => sc.UserId == user.Id && sc.SpreadCommentId == id).SingleOrDefault().SpreadId; if (id != spreadComment.SpreadCommentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(spreadComment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SpreadCommentExists(spreadComment.SpreadCommentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("GetUserSpreadComments", new { id = spreadComment.SpreadId })); } return(View(spreadComment)); }
public async Task <IActionResult> Create(int id, [Bind("SpreadCommentId,Comment")] SpreadComment spreadComment) { var user = await GetCurrentUserAsync(); spreadComment.SpreadId = id; spreadComment.UserId = user.Id; if (ModelState.IsValid) { _context.Add(spreadComment); await _context.SaveChangesAsync(); return(RedirectToAction("GetUserSpreadComments", new { id = id })); } return(View(spreadComment)); }