I am struggling to find a solution to my problem: I have a really simple Web API in C# that GET, POST, PUT and DELETE employees nicely, but everything working with a simple JSON input:
{
"FirstName": "Sam 10",
"LastName": "Wicht 10",
"Gender": "Male",
"Salary": 140000
}
What I want to do is to POST a lot of employees, like:
"employees": [{
"FirstName": "Sam 10",
"LastName": "Wicht 10",
"Gender": "Male",
"Salary": 140000
}, {
"FirstName": "Sam 11",
"LastName": "Wicht 11",
"Gender": "Male",
"Salary": 99000
}]
And in my C# Code, I receive, for instance a List<Employee> containing every employee from JSon and then I loop a For Each ... updating each.
Performance-wise, is this something really bad? Thinking I can limit the List size and avoid running any code if .Count() is higher than X, can you guys please let me know how to retrieve this from the JSON input?
This is the class Employee I have:
public partial class Employee
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Gender { get; set; }
public Nullable<int> Salary { get; set; }
}
Should I include a new Class that represents an IEnumerable<Employee> with all the parameters?
This is for learning and testing purposes, and I tried to retrieve [FromBody] List<Employee> myVariableName; returns null;