public async Task <IActionResult> Create([FromBody] Category category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Post p = category.Post.FirstOrDefault(); _context.Category.Add(category); _context.Post.Add(p); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCategory", new { id = category.CategoryId }, category)); }