Answer the question
In order to leave comments, you need to log in
How to create controller methods to create entities of 2 classes?
Hello! I am making a sports events service on asp.net. Since sports events can be both team and not, I created two classes - Event and EventWithTeams. EventWithTeams inherits from Event.
But how to make request methods to create them in the controller? Make two Create methods but with different routes? Or in some other way?
Answer the question
In order to leave comments, you need to log in
I would generally make one method on the controller, and with or without the create command, I would regulate the parameter passed in the request.
As an option, use different http requests, for example, post and patch, respectively, put the [HttpPost] and [HttpPatch] attributes above different methods.
And in general, is there a difference if the actions of the controller are called differently?
I would do this
/ api / Events / (POST)
And depending on the values passed, I would choose what to execute next.
The model is like this.
public class EventCreateModel{
public string Name {get;set;}
// проверяем если пустое то это просто Event, если нет то это командное
public string Team {get;set;}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question