Hi @Markus Freitag ,
How can I achieve this?
How can I test this?
If you are using Asp.net core API, you can create an Asp.net core Web API project, by default in asp.net 6, it has configured with Swagger, then after creating the API controller, you could use the swagger UI to test the API methods.
I think I have to send it by POST, because I have data with a relationship in it. 1 to n link.
What is the best way to achieve the goal?
To create the API or Rest Service, first, you need to create model based on the JSON data, you can search "json to c# class online" using Google or Bing, there have some online tools to generate the C# class based on the JSON data. And the Model like this:
//required using System.ComponentModel.DataAnnotations;
public class TodoModel
{
[Key]
public int TodoId { get; set; }
public string actorname { get; set; }
public string taskname { get; set; }
public string stepname { get; set; }
public List<Parameter> parameters { get; set; }
}
public class Parameter
{
[Key]
public int PId { get; set; }
public string name { get; set; }
public double value { get; set; }
}
Then, right click the Controllers folder-> Add-> New Scaffolded Item.. , in the Popup window, Select API -> API Controller with actions, using Entity Framework. Finally, click the Add button:
After that, it will generate the Controller with the CRUD and Put methods:
Then, you can enable migration to generate the database and the table.
PUT, when must I need PUT?
The Put method is used to update the entity. Refer Web API Overview
Running the application, and test the API method using Swagger UI:
Reference:
first-web-api/samples
Tutorial: Get started with EF Core in an ASP.NET MVC web app(This is similar in the API project)
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion