public async Task <ActionResult <SubCommentEntity> > PostSubCommentEntity(SubCommentEntity subCommentEntity) { _context.SubComments.Add(subCommentEntity); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSubCommentEntity", new { id = subCommentEntity.Id }, subCommentEntity)); }
private static SubCommentEntity[] SeedDataSubcomments(CommentEntity[] comments, int numberOfSubComments = 5) { List <SubCommentEntity> subcomments = new List <SubCommentEntity>(); foreach (CommentEntity comment in comments) { for (int i = 0; i < numberOfSubComments; i++) { Guid authorId = (i % 2 == 0) ? _defaultBotId : _defaultAdminId; SubCommentEntity subComment = new SubCommentEntity() { Id = Guid.NewGuid(), CommentId = comment.Id, Description = $"This is the {i} sub-comment", PostId = comment.PostId, CreatorId = authorId, CreatedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow }; subcomments.Add(subComment); } } return(subcomments.ToArray()); }
public async Task <IActionResult> PutSubCommentEntity(Guid id, SubCommentEntity subCommentEntity) { if (id != subCommentEntity.Id) { return(BadRequest()); } _context.Entry(subCommentEntity).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SubCommentEntityExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }