Sending data to an Api

1

I have two methods of type Post But what I do not know is how to differentiate one method from the other in the Post type request.

 [HttpPost]
    public ExpedienteDto Post(ExpedienteDto dto)
    {
        return ProcesosService.CrearExpediente(dto);
    }



    [HttpPost]
    public NumeroExpediente GuardarNumeroConsuta(NumeroExpediente numero, string IdUsuario)
    {
        Console.Write(numero.ToString());
        return ProcesosService.GuardarNumeroConsuta(numero, IdUsuario);
    }

How do I differentiate that in this part so that when I send the request fence to the method it should be that in this case it is the second one in the code.

    
asked by lARAPRO 25.09.2018 в 16:43
source

1 answer

2

You can use the [Route] attribute

    [HttpPost]
    [Route("OtroNombreGuardarNumeroConsulta")]
    public NumeroExpediente GuardarNumeroConsuta(NumeroExpediente numero, string IdUsuario)
    {
        Console.Write(numero.ToString());
        return ProcesosService.GuardarNumeroConsuta(numero, IdUsuario);
    }

To be able to combine both the default routing {Controller} / {Action} / {id} with the attribute Route you have to add routes.MapMvcAttributeRoutes(); in the RegisterRoutes method:

public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapMvcAttributeRoutes();

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Menu", action = "Home", id = UrlParameter.Optional }
            );
        }
    }
    
answered by 26.09.2018 / 01:33
source