Olá Ivan.
Antes de mais, aconselho-te a escrever em inglês, por mais que não seja 
perfeito. É maior a probabilidade de obteres resposta!

Em relação ao código, não vejo nenhum problema na parte AngularJS, deve 
estar em falta alguma configuração do lado do ASP.NET.
Experimenta usar um fórum .NET ou o StackOverflow para obter melhor 
resposta!

Cumprimentos,
*Luís Loureiro*

quinta-feira, 18 de Junho de 2015 às 01:53:25 UTC+1, Ivan Teles escreveu:
>
> Boa noite a todos.
>
> Vou explicar meu problema e vocês tentem me informar onde esta o erro.
>
> Tenho meu método C# assim
>
> [ResponseType(typeof(Categoria))]
>         public async Task<IHttpActionResult> Post(Categoria model)
>         {
>             if (!ModelState.IsValid)
>             {
>                 return BadRequest(ModelState);
>             }
>             if (_repositorio.InsertOrUpdate(model, out Res))
>             {
>                 _repositorio.Save();
>                 return CreatedAtRoute("DefaultApi", new { id = model.Id }, 
> model);
>             }
>             return BadRequest("Erro ao tentar salvar, tente novamente mais 
> tarde");
>             
>         }
>
> Tenho minha fabrica assim:
>
> .factory("categoriasService", function($http, config, $q) {
> var _postItem = function(record) {
>             var deferred = $q.defer();
>             $http.post(config.baseUrl + "/api/Categoria/Post", 
> record).then(
>                 function(result) {
>                     deferred.resolve(result.data);
>                 },
>                 function (erroResult) {
>                     deferred.reject();
>                 }
>             );
>             return deferred.promise;
>         };
>         return {            
>             postItem: _postItem
>         };
>     })
>
> Ao chamar em meu controller assim:
>
> .controller("newCategoriaCtrl", [
>         "$scope", "$http", "$window", "categoriasService", 
> "modalConfirmationService", "$routeParams",
>         function ($scope, $http, $window, categoriasService, 
> modalConfirmationService, $routeParams) {            
>             if ($routeParams.id !== undefined) {
>                 categoriasService.find($routeParams.id).then(function 
> (result) {
>                     $scope.newCategoria = result;
>                 });
>                 $scope.titleAcao = "Alterar";
>             } else {
>                 $scope.newCategoria = { Id: 0 };
>                 $scope.titleAcao = "Cadastrar";
>             }
>             
>             $scope.save = function() {
>                 //console.log($scope.newCategoria);
>                 categoriasService.postItem($scope.newCategoria)
>                     .then(function (newCategoria) {
>                             console.log(newCategoria);//aqui o objeto está 
> sempre vazio por que acontece o erro 500.
>                             
> modalConfirmationService.getModalInstance("Sucesso", "Dados salvos com 
> sucesso!");
>                         },
>                         function() {
>                             
> modalConfirmationService.getModalInstance("Erro", "Não foi possível 
> executar sua ação, tente novamente mais tarde.");
>                         })
>                     .then(function() {
>                         $window.location = "#";
>                     });
>             };
>         }
>     ]);
>     
> Quando chamo a aplicação sem ativar o debug no console do navegador sempre 
> ocorre erro 500 e não sava a informação na base de dados.
>
> http://localhost:54100/api/Categoria/Post 500 (Internal Server Error)
>
> Mas se eu ativar o modo debug no VS, dá o mesmo erro no console, mas a 
> informação é salva na base de dados.
>
> O que está errado? tenho que configurar algo na app web.api?
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to