I have ASP.NET application. The code looks as following:
View (List.html):
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Events</th>
<th>Date</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="t in ticketGroups">
<td>{{t.Artist}}</td>
<td>{{t.ActionDate}}</td>
<td>{{t.Price}}</td>
<td><input type="number" ng-model="t.NewPrice" /></td>
</tr>
</tbody>
</table>
<section>
<a class="btn btn-success" ng-click="save()">Ok</a>
</section>
AngularJS:
'use strict';
//Routing
var ChangePriceApp = angular.module('ChangePriceApp', ['ngRoute', 'ConcertServices'])
.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/list', { templateUrl: 'partials/ChangePrice/List.html', controller: "ListController" })
.otherwise({ redirectTo: '/list' });
}]);
ChangePriceApp.controller("ListController", ["$scope", "ChangePrice", function ($scope, ChangePrice) {
ChangePrice.get().success(function (ticketGroups) {
$scope.ticketGroups = ticketGroups;
});
$scope.save = function () {
ChangePrice.save($scope.ticketGroups).success(function () {
ChangePrice.get().success(function (ticketGroups) {
$scope.ticketGroups = ticketGroups;
});
toastr.success("saved");
});
}
}]);
Initially, the view displays data correctly. I change data and click "Ok" to save it. The issue is after I clicked "Ok", all data disappeared. I want to reload the view with updated data.
UPDATE:
The MVC methods:
public class PriceController : ConcertApiController
{
private readonly ITicketModelService _service;
public PriceController(ITicketModelService service)
{
_service = service;
}
[HttpGet]
public IEnumerable<RevaluationTicketGroup> GetRevaluationList()
{
return _service.GetRevaluationList(CurrentUser);
}
[HttpPost]
public void PostRevaluationList(IEnumerable<RevaluationTicketGroup> tickets)
{
_service.PostRevaluationList(CurrentUser, tickets);
}
}
The AngularJS service:
.factory('ChangePrice', function ($http, ErrorUI) {
return {
get: function () {
return $http.get('/RestApi/api/Price/').error(ErrorUI.showApiError);
},
save: function (ticketGroups) {
return $http.post('/RestApi/api/Price/', ticketGroups).error(ErrorUI.showApiError);
}
}
})
ChangePrice.get()andChangePrice.save()return?