Add JSON-based AddCommentJson endpoint

- Accepts JSON body instead of FormData for simple text comments
- Returns new comment with user name for immediate UI update
- Defaults to internal comment type
This commit is contained in:
Adam Moussa 2026-04-16 18:22:34 -04:00
parent e1f57d3fb2
commit 18ca737307

View file

@ -824,6 +824,40 @@ namespace Api.SeaHavenIndustries.Controllers
}
}
[HttpPost]
[Route("AddCommentJson")]
public async Task<IActionResult> AddCommentJson([FromBody] Comments_DTO model)
{
try
{
var userId = _httpContext?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? "";
var comment = new Comments
{
CreatedDate = DateTime.UtcNow,
UserId = userId,
WorkerOrderId = model.WorkorderId,
Commenttext = model.Text,
CommentType = model.CommentType ?? "internal",
};
_db.Comments.Add(comment);
await _db.SaveChangesAsync();
var user = await _db.Users.FindAsync(userId);
return Ok(new
{
comment.Id,
comment.CreatedDate,
comment.Commenttext,
comment.CommentType,
userName = user != null ? (user.FirstName + " " + user.LastName).Trim() : ""
});
}
catch (Exception ex)
{
return BadRequest(new Response { Status = "Error", Message = ex.Message });
}
}
[HttpGet]
[Route("GetComments")]
public async Task<IActionResult> GetComments()