From 18ca73730759e23f6aff3b68baa722d9e819989a Mon Sep 17 00:00:00 2001 From: Adam Moussa <166072409+amoussa1229@users.noreply.github.com> Date: Thu, 16 Apr 2026 18:22:34 -0400 Subject: [PATCH] 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 --- .../Controllers/WorkOrderController.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs b/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs index 27153a0..f873791 100644 --- a/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs +++ b/Api.SeaHavenIndustries/Controllers/WorkOrderController.cs @@ -824,6 +824,40 @@ namespace Api.SeaHavenIndustries.Controllers } } + [HttpPost] + [Route("AddCommentJson")] + public async Task 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 GetComments()