public ActionResult <IEnumerable <int> > PostMany([FromBody] IEnumerable <Question> questionsInput, [FromRoute] int?category) { // if no category is specified one will be created if (category == null) { var newCategory = new Categories { Name = Guid.NewGuid().ToString(), Comment = "created on import" }; DbConn.Categories.Add(newCategory); DbConn.SaveChanges(); category = newCategory.Id; } // if the specified category can't be found it's wrong else if (DbConn.Categories.Find(category) == null) { return(BadRequest()); } var questions = questionsInput .Select((questionInput, index) => new Questions(questionInput, category, index)).ToList(); DbConn.AddRange(questions); DbConn.SaveChanges(); return(Ok(questions.Select(q => q.Id).OrderBy(id => id))); }