Home asp.net "put" method with angular js
Reply: 0

asp.net "put" method with angular js

user2915
1#
user2915 Published in May 27, 2018, 3:38 am

im workin with my website and actually workin with 3 methods-put,post,delete. In my code i did two of them:delete and post and they are correct, but i have no idea how i can do put do edit my TODO list. That's my code, if you can help me i'll be glad. Have a nice day.

This is a service .js file

app.factory('reservationService', ReservationService);

function ReservationService($http) {

var CreateReservation = function (reservation) {
    return $http.post("api/todo", reservation);
}

var EditReservation = function (id) {
    return $http.put("api/todo/", + id);
}

var DeleteReservation = function (id) {

    return $http.delete("api/todo/" + id);
}

var GetAll = function () {
    return $http.get("api/todo");
}


return {
    CreateReservation: CreateReservation,
    EditReservation: EditReservation,
    DeleteReservation: DeleteReservation,
    GetAll: GetAll
}

}

this is a angular maincontroller code

app.controller('mainCtrl', mainCtrl);

function mainCtrl($scope, reservationService) {

$scope.list = [];
$scope.reservation = {};
getReservations();

InitDateTimePickers();

$scope.isSelected = function () {
    return getSelectedItems().length > 0;
};

$scope.append = function (id) {
    var editedItem = _.first(getSelectedItems());

    $scope.reservation = editedItem;

    reservationService.EditReservation(id).then(function (result) {
        getReservations();
    }); 
};

function getReservations() {
    reservationService.GetAll().then(function (result) { 

        for (var i = 0; i < result.data.length; i++) {

            result.data[i].timeFormatted = moment(result.data[i].Time, "HH:mm").format("hh:mm");
        }

        $scope.list = result.data;

    });
}

function removeReservation(id) {
    reservationService.DeleteReservation(id).then(function (result) {            
        getReservations();
    }); 
}
$scope.add = function () {
    reservationService.CreateReservation($scope.reservation).then(function (result) {
        getReservations();
    });
};

function InitDateTimePickers() {
    $('#timepickerFrom').bootstrapMaterialDatePicker({ date: false, format: 'HH:mm' }).on('change', function (e, date) {

    }); }

$scope.remain = function () {
    var count = 0;
    angular.forEach($scope.list, function (todo) {
        count += todo.done ? 0 : 1;
    });
    return count;
};

var getSelectedItems = function () {
    return _.filter($scope.list, function (n) {
        return n.done;
    });
}

$scope.archive = function () {
    var itemsToRemove = getSelectedItems();

    _.each(itemsToRemove, function (item) {
        removeReservation(item.id)
    });
};

$scope.edit = function () {
    var editedItem = _.first(getSelectedItems());

    $scope.reservation = editedItem;
}

};

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.306151 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO