The problem is not creating a POCO. The problem is your Blazor client design does not submit a developerId with the ActionItem! The developerId is needed so you can add or edit an ActionItem. While I agree the Web API data interface should use POCOs not entities, it does not change the fact that a developerId - the foreign key - is needed to add the action item to the correct developer.
You really need to go through a few beginning level tutorials before moving forward.
POCO
public class ActionItemPoco
{
public string? Tilte { get; set; }
public string? Description { get; set; }
public string? State { get; set; }
public DateTime? OpenDate { get; set; }
public DateTime? PlanDate { get; set; }
public DateTime? CloseDate { get; set; }
public int DeveloperId { get; set; }
}
Action
// POST api/<ActionItemController>
[HttpPost]
public async Task<ActionResult<ActionItemPoco>> Post([FromBody] ActionItemPoco poco)
{
Developer? developer = await _context.Developers
.Include(a => a.ActionItems)
.FirstOrDefaultAsync(d => d.DeveloperId == poco.DeveloperId);
if (developer == null)
{
return NotFound();
}
ActionItem ac = new ActionItem()
{
ActionItemId = 0,
DeveloperId = poco.DeveloperId,
CloseDate = poco.CloseDate,
Description = poco.Description,
OpenDate = poco.OpenDate,
PlanDate = poco.PlanDate,
State = poco.State,
Tilte = poco.Tilte
};
developer.ActionItems.Add(ac);
await _context.SaveChangesAsync();
return CreatedAtAction(nameof(GetActionItem), new { id = ac.ActionItemId }, poco);
}
JSON
{
"actionItemId": 0,
"tilte": "Action Title 2",
"description": "Description 2",
"state": "State 2",
"openDate": "2022-11-18",
"planDate": "2022-11-18",
"closeDate": "2022-11-18",
"developerId": 1
}