public async Task <IActionResult> PostBugAsync([FromBody] Bug bug, string libraryId) { if (libraryId.Length != 24) { return(BadRequest(new { message = $"Library Id should be a 24 characters hex string" })); } if (bug.Name == null || bug.Description == null) { return(BadRequest(new { message = "Bug name or description cannot be blank" })); } if (bug.LibraryId != libraryId) { return(BadRequest(new { message = "Library Id does not match an existing library" })); } try { await _bugService.AddBugAsync(bug); } catch (MongoException mongoException) { return(StatusCode(StatusCodes.Status500InternalServerError, new { message = mongoException.Message })); } return(bug.Id != null ? (IActionResult)Ok(bug.Id) : BadRequest()); }