first level comments are OK

This commit is contained in:
Paul Schneider
2024-12-15 13:53:30 +00:00
parent 486e14e10b
commit d4d02b967d
3 changed files with 9 additions and 61 deletions

View File

@ -21,14 +21,6 @@ namespace Yavsc.Controllers
_context = context; _context = context;
} }
// GET: api/CommentsApi
[HttpGet]
public IEnumerable<Comment> GetComment()
{
return _context.Comment;
}
// GET: api/CommentsApi/5
[HttpGet("{id}", Name = "GetComment")] [HttpGet("{id}", Name = "GetComment")]
public async Task<IActionResult> GetComment([FromRoute] long id) public async Task<IActionResult> GetComment([FromRoute] long id)
{ {
@ -46,45 +38,8 @@ namespace Yavsc.Controllers
return Ok(comment); return Ok(comment);
} }
// PUT: api/CommentsApi/5
[HttpPut("{id}")]
public async Task<IActionResult> PutComment([FromRoute] long id, [FromBody] Comment comment)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != comment.Id)
{
return BadRequest();
}
_context.Entry(comment).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync(User.GetUserId());
}
catch (DbUpdateConcurrencyException)
{
if (!CommentExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return new StatusCodeResult(StatusCodes.Status204NoContent);
}
// POST: api/CommentsApi
[HttpPost] [HttpPost]
public async Task<IActionResult> PostComment([FromBody] CommentPost post) public async Task<IActionResult> Post([FromBody] CommentPost post)
{ {
if (!ModelState.IsValid) if (!ModelState.IsValid)
{ {
@ -131,12 +86,12 @@ namespace Yavsc.Controllers
throw; throw;
} }
} }
return CreatedAtRoute("GetComment", new { id = c.Id }, post); return CreatedAtRoute("GetComment", new { id = c.Id }, new { id = c.Id, dateCreated = c.DateCreated });
} }
// DELETE: api/CommentsApi/5 // DELETE: api/CommentsApi/5
[HttpDelete("{id}")] [HttpDelete("{id}")]
public async Task<IActionResult> DeleteComment([FromRoute] long id) public async Task<IActionResult> Delete([FromRoute] long id)
{ {
if (!ModelState.IsValid) if (!ModelState.IsValid)
{ {

View File

@ -7,7 +7,7 @@
<script src="~/js/comment.js" asp-append-version="true"></script> <script src="~/js/comment.js" asp-append-version="true"></script>
<script> <script>
$.psc.blogcomment.prototype.options.lang = '@System.Globalization.CultureInfo.CurrentUICulture.Name'; $.psc.blogcomment.prototype.options.lang = '@System.Globalization.CultureInfo.CurrentUICulture.Name';
$.psc.blogcomment.prototype.options.apictrlr = '/api/blogcomments/PostComment'; $.psc.blogcomment.prototype.options.apictrlr = '/api/blogcomments';
$.psc.blogcomment.prototype.options.authorId = '@User.GetUserId()'; $.psc.blogcomment.prototype.options.authorId = '@User.GetUserId()';
$.psc.blogcomment.prototype.options.authorName = '@User.GetUserName()'; $.psc.blogcomment.prototype.options.authorName = '@User.GetUserName()';
$(document).ready(function() { $(document).ready(function() {
@ -42,12 +42,10 @@ $('#commentValidation').html(
var comment = $('#Comment').val(); var comment = $('#Comment').val();
$('#Comment').val(''); $('#Comment').val('');
$('#commentValidation').empty(); $('#commentValidation').empty();
var htmlcmt = htmlize(comment); var nnode = '<div data-type="blogcomment" data-id="'+data.id+'" data-allow-edit="True" data-allow-moderate="@ViewData["moderatoFlag"]" data-date="'+data.dateCreated+'" data-username="@User.GetUserName()">'+comment+'</div>';
var nnode = '<div data-type="blogcomment" data-id="'+data.Id+'" data-allow-edit="True" data-allow-moderate="@ViewData["moderatoFlag"]" data-date="'+data.DateCreated+'" data-username="@User.GetUserName()">'+htmlcmt+'</div>';
$('#comments').append($(nnode).blogcomment()) $('#comments').append($(nnode).blogcomment())
}, },
url:'@ViewData["apicmtctlr"]' url:'/api/blogcomments'
}); });
}); });
}) })
@ -83,7 +81,6 @@ $('#commentValidation').html(
<input name="Comment" id="Comment" class="form-control" placeholder="..."/> <input name="Comment" id="Comment" class="form-control" placeholder="..."/>
<span class="input-group-btn"> <span class="input-group-btn">
<span id="commentValidation"></span> <span id="commentValidation"></span>
<input type="button" value="Comment" class="btn btn-secondary" <input type="button" value="Comment" class="btn btn-secondary"
data-receiverId="@Model.Id" id="cmtBtn" data-receiverId="@Model.Id" id="cmtBtn"
/> />

View File

@ -90,8 +90,6 @@ $.widget("psc.blogcomment", {
}, 400); }, 400);
}, },
doDeleteComment: function(_this, ev) { doDeleteComment: function(_this, ev) {
var cmtid = $(_this.element).data("id");
var cmtapi = _this.options.apictrlr;
$.ajax({ $.ajax({
async: true, async: true,
cache: false, cache: false,
@ -105,7 +103,7 @@ $.widget("psc.blogcomment", {
success: function(data) { success: function(data) {
_this.element.remove() _this.element.remove()
}, },
url: cmtapi + '/' + cmtid url: _this.options.apictrlr + '/' + $(_this.element).data("id")
}); });
}, },
doCoC: function(_this, ev) { doCoC: function(_this, ev) {
@ -114,7 +112,7 @@ $.widget("psc.blogcomment", {
var cmtid = $(_this.element).data("id"); var cmtid = $(_this.element).data("id");
var data = { var data = {
Content: comment, Content: comment,
PostId: postid, ReceiverId: postid,
ParentId: cmtid, ParentId: cmtid,
AuthorId: _this.options.authorId AuthorId: _this.options.authorId
}; };
@ -136,11 +134,9 @@ $.widget("psc.blogcomment", {
) )
}, },
success: function(data) { success: function(data) {
var comment = data.Content;
_this.cmtInput.val(''); _this.cmtInput.val('');
$('span.field-validation-valid[data-valmsg-for="Content"]').empty(); $('span.field-validation-valid[data-valmsg-for="Content"]').empty();
var htmlcmt = htmlize(comment); $('<div data-type="blogcomment" data-id="' + data.Id + '" data-allow-edit="True" data-date="' + data.DateCreated + '" data-username="' + _this.options.authorName + '">' + data.Content + '</div>')
$('<div data-type="blogcomment" data-id="' + data.Id + '" data-allow-edit="True" data-date="' + data.DateCreated + '" data-username="' + _this.options.authorName + '">' + htmlcmt + '</div>')
.blogcomment().appendTo(_this.subCmts); .blogcomment().appendTo(_this.subCmts);
}, },
url: _this.options.apictrlr url: _this.options.apictrlr