public async Task <IActionResult> UpdateWorkorderComment( [FromRoute] int id, [FromRoute] int commentId, [FromBody] WorkorderComment newComment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Entry(newComment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WorkorderExists(id) || !CommentExists(commentId)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> AddNewWorkorderComment( [FromRoute] int id, [FromBody] WorkorderComment comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var workorder = await _context.Workorders.FirstOrDefaultAsync(w => w.Id == id); if (workorder == null) { return(NotFound()); } comment.Timestamp = DateTime.Now; comment.Workorder = workorder; _context.WorkorderComments.Add(comment); await _context.SaveChangesAsync(); return(CreatedAtAction("GetWorkorderComment", new { id, commentId = comment.Id }, comment)); }