samedi 25 juin 2016

Change(Put) data in ASP.NET WebApi server from AngularJS client can't change in SQL DataBase

I'm working in a project where i put data in restaurant (table in DataBase) but nothing change in Sql DataBase ,The UI of the project in asp.net My Html file <tr> <td> <asp:TextBox ID="TextBox1" runat="server" name="rest" placeholder="Write the restaurant ID" ng-model="resturantid" required></asp:TextBox> </td> <td> <input type="button" value="Find" class="btn btn-primary-outline" ng-click="getRestaurantById(resturantid)" /> </td> </tr> <tr> <th>Restaurant Name</th> <td> <asp:TextBox ID="TextBox2" runat="server" ng-model="res.R_Name" required>{{res.R_Name}} </asp:TextBox> </td> </tr> <tr> <td> <input type="button" class="btn btn-primary-outline" ng-click="toggleEdit(res.R_ID,res)" formmethod="put" value="Edit" /> </td> <td></td> </tr> </table> My Script app.controller("editownercontroller", ['$scope', '$http', function ($scope, $http) { ///////////////////edit profile///////////////////////////////// $scope.Flag = 0; $scope.getRestaurantById = function (id) { $http.get("http://localhost:10566/api/Restaurants/" + id).then(function (response) { if (response) { $scope.res = response.data; } } ) }; $scope.getData = function (id,Restaurant) { getcuisine(); toggleEdit(id, Restaurant); } $scope.getcuisine = function () { $http.get("http://localhost:10566/api/Cuisines").then(function (response) { if (response) { $scope.cuisines = response.data; } }); }; $scope.updatecuisine = function (id, cuisine) { $http.put("http://localhost:10566/api/Cuisines/" + id, cuisine).then(function () { }); } $scope.toggleEdit = function (id, new_res) { $http.put("http://localhost:10566/api/Restaurants/" + id, new_res).then(function () { }); } ,And in the Web API Server // PUT: api/Restaurants/5 [ResponseType(typeof(void))] public IHttpActionResult PutRestaurant(int id, Restaurant restaurant) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != restaurant.R_ID) { return BadRequest(); } db.Entry(restaurant).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RestaurantExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); } }]);

Aucun commentaire:

Enregistrer un commentaire