public async Task <IActionResult> PutComment(int?id, Comment comment) { if (id != comment.Id) { return(BadRequest()); } _context.Entry(comment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CommentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutTopic(long id, Topic topic) { if (id != topic.Id) { return(BadRequest()); } _context.Entry(topic).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TopicExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("Id,Content")] Comment comment) { if (ModelState.IsValid) { _context.Add(comment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(comment)); }
public async Task <IActionResult> Create(Comment comment) { db.Comments.Add(comment); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([Bind("Content")] Comments comment) { var itemId = TempData["itemId"] as string; if (ModelState.IsValid) { DateTime today = DateTime.Now; var user = await userManager.GetUserAsync(User); comment.Id = user.Id + today.ToString(); comment.Author = user.Id; comment.ItemId = itemId; _context.Add(comment); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Items", new { id = itemId })); } return(View(comment)); }
public async Task <IEnumerable <IComment> > AddComment(IComment comment) { try { await db.Comments.AddAsync((Comment)comment); await db.SaveChangesAsync(); return(await CommentsAsync()); } catch (Exception ex) { logger.LogError(ex); throw ex; } }
public Task Save() { return(_appDbContext.SaveChangesAsync()); }