D
D
dgash22012021-04-20 00:13:28
ASP.NET
dgash2201, 2021-04-20 00:13:28

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

3 answer(s)
C
cicatrix, 2021-04-20
@cicatrix

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.

R
Roman, 2021-04-20
@yarosroman

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?

V
Vladimir Korotenko, 2021-04-20
@firedragon

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;}
}

https://ru.wikipedia.org/wiki/%D0%9F%D1%80%D0%B5%D...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question