What would be the best and simplest alternative?
I have the Web Api:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Generico.Dominio;
using Generico.Aplicacao;
namespace AspNetWebApi.Controllers
{
[RoutePrefix("api/AspNetWebApi")]
public class DefaultController : ApiController
{
//http://localhost:7630/api/AspNetWebApi/consulta/JogosPorID/5
[HttpGet]
[Route("consulta/JogosPorID/{id:int}")]
public HttpResponseMessage JogosPorID(int id)
{
try
{
var tTabela = new JogoDetalheAplicacao();
var listar = tTabela.ListarTodos(id);
return Request.CreateResponse(HttpStatusCode.OK, listar.ToArray());
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
//http://localhost:7630/api/AspNetWebApi/cadastrar/jogo/4512/20.01/20.10/5
[HttpPost]
[Route("cadastrar/jogo/{nJogo}/{valor}/{total}/{idusuario}")]
public HttpResponseMessage Cadastro(int nJogo, decimal valor, decimal total, int idusuario)
{
try
{
var tTabela = new JogoDetalheAplicacao();
tTabela.Inseri(nJogo, valor,total,idusuario);
return Request.CreateResponse(HttpStatusCode.OK, "Cadastro realizado.");
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
//http://localhost:7630/api/AspNetWebApi/deletar/jogo/4512/5
//precisa usar o postman com opção delete formato json
[HttpDelete]
[Route("deletar/jogo/{nJogo}/{idusuario}")]
public HttpResponseMessage Deletar(int nJogo, int idusuario)
{
try
{
var tTabela = new JogoDetalheAplicacao();
var resultado = tTabela.Excluir(nJogo, idusuario);
return Request.CreateResponse(HttpStatusCode.OK, resultado);
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
//http://localhost:1608/api/ApiGuiaCidade/datahora/consulta
[HttpGet]
[Route("datahora/consulta")]
public HttpResponseMessage GetDataHoraServidor()
{
try
{
var dataHora = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
return Request.CreateResponse(HttpStatusCode.OK, dataHora);
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
}
}
I have the Script:
(function () {
'use strict';
var numeros = angular
.module("myModule", [])
.controller("myController", function ($scope, $http, $log) {
var sv = this;
var sucessoCalBack = function (response) {
$scope.detalhes = response.data;
};
var erroCalBack = function (response) {
$scope.error = response.data;
};
//assim funciona, passando o parametro direto
$http({
method: 'GET',
params: { idusuario: 5 },
url: 'http://localhost:7630/api/AspNetWebApi/consulta/JogosPorID/5'})
.then(sucessoCalBack,erroCalBack);
});
sv.getAll = function (idusuario, onSuccess, onFail) {
var config = {
method: 'GET',
url: 'http://localhost:7630/api/AspNetWebApi/consulta/JogosPorID/',
params: { idusuario:idusuario }
};
$http(config)
.then(function (response) {
onSuccess(response.data);
}, function (response) {
onFail(response.statusText);
});
};
//Inser Detalhe
sv.post = function (nJogo, valor, total, idusuario, onSuccess, onFail) {
var config = {
method: 'POST',
url: 'http://localhost:7630/api/AspNetWebApi/cadastrar/jogo/',
params: { nJogo: nJogo, valor: valor, total: total, idusuario: idusuario }
};
$http(config)
.then(function (response) {
onSuccess(response.data);
}, function (response) {
onFail(response.statusText);
});
};
//Delete detalhe
sv.delete = function (idusuario,numerojogo , onSuccess, onFail) {
var config = {
method: 'DELETE',
url: 'http://localhost:7630/api/AspNetWebApi/deletar/jogo/',
params: { idusuario: idusuario, numerojogo: numerojogo }
}
$http(config)
.then(function (response) {
onSuccess(response.data);
}, function (response) {
onFail(response.statusText);
});
};
})();
Questions:
1-IneedtogetGetpassingaparameterthatwouldbetheUserID
2-IneedtodothepostanddeletealsosendingtheUserIDisgamenumber
I'mmakingtheprojectcomplete,there'sonlyonetable(withscriptalreadywithdata),ifanyonecanhelpmelearnthis,I'musingVS2015,thankyou.
link