I am trying to update a records in my project but I'm stuck and wondering if I could get some help.
Angular Controller
$scope.userId = 1;
$scope.Age = 23;
$scope.updateRec = function(){
var post = myservice.update($scope.userId, $scope.Age);
post.then(function(data))
return data;
});
}
myservice js
this.update(id, age){
var request = $http({
method: 'put',
url: '/api/updateuser/update/' + id,
data: age
});
return request;
}
Api Controller
private context _db = new context();
[AcceptVerbs("GET", "POST")]
[HttpGet]
public bool Update(UserTable model)
{
model.age = //<< here is where I'm stuck, how do I update the user's age here ?
_db.SaveChanges();
return true;
}
model
public class UserTable{
public int userId {get:set;}
public stringName {get;set;}
public int Age {get;set;}
}
As you can see I'm trying to update the user's age by using the userId. but I'm stuck on how I receive the age from the client and update the database. Could some direct me here please?
data : { Age = age }or webapi:bool Update(int userId, int age). Then add the code to update your EF db.