I created an MVC project and within an API.
I need to get the API when I upload the project to (F5).
Example, I created a service that is a GET in my Type table.
How can I map the API to be able to get inside an MVC controller?
My project is Asp.Net MVC and inside it I have a Web API project, the services are in the Web API and by MVC I should get the service and fill in some Views.
This method works inside the API service, but now with MVC I do not know how to call.
public class GetCidades
{
BancoContext banco = new BancoContext();
public List<Cidade> getCidades()
{
var result = banco.Database.SqlQuery<Cidade>("sp_cons_cidade").ToList();
return result;
}
}
How do I get this service inside the MVC. I did this
public class GetCidades
{
HttpClient client = new HttpClient();
List<Cidade> cidades = new List<Cidade>();
public async Task<List<Cidade>> GetCidadesAsync()
{
string url = $"http://localhost:51381/api/";
var response = await client.GetStringAsync(url);
var _cidade = JsonConvert.DeserializeObject<List<Cidade>>(response);
return _cidade;
}
}
But I do not know what else to do.
Do I need to map anything? Because when I give F5 up the two, right, MVC and API and from within the MVC how do I get the API?
EDIT1
My controller within the MVC
public class GetCidadeController : Controller
{
// GET: GetCidade
public ActionResult Index()
{
return View();
}
public ActionResult GetCidades()
{
return View();
}
}
The API controller
[RoutePrefix("api/[controller]")]
public class GetCidadesController : ApiController
{
GetCidades cidades = new GetCidades();
[AcceptVerbs("Get")]
public IEnumerable<Cidade> getCidades()
{
return cidades.getCidades().AsEnumerable().ToList();
}
}
Lost. I do not know if this is how it should be done