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()