Reputation: 401
I am trying to update a users hours for an attended club. I was able to do it once before, but now I always get the same error of Failed to load resource: the server responded with a status of 409 (Conflict). This is troubling to me because I am updating with the correct id and it should work. Another problem is it does not give me enough information in the error to know what is happening. That is why I'm asking for help. Thank you in advance.
The service where the error is coming from
.service('hourAdder', function(){
return{
addHours:function(userID,meetingID){
var client = new WindowsAzure.MobileServiceClient('My mobile Service');
client.getTable('Meeting').where({id: meetingID}).read().done(function (results) {
var hours = results[0].Hours;
var points = results[0].Points;
var club = results[0].ClubID;
console.log("Hours:" + hours+" Points:"+points+" Club:"+club);
client.getTable('AttendedClubs').where({id: club,UniqueUserID: userID}).read().done(function(hoursPoints){
points = points + parseInt(hoursPoints[0].Points);
hours = hours + parseInt(hoursPoints[0].Hours);
client.getTable('AttendedClubs').update({id: club,UniqueUserID: userID, Hours: hours, Points: points}).done(function(updated){
}, function(error)
{
console.log("Updating Hours Errors"+ error);
});
}, function(error)
{
console.log("Getting Attended Clubs"+ error);
});
}, function(error)
{
console.log("One of the poeple returned an error");
});
}
}
})
Upvotes: 1
Views: 10084
Reputation: 8035
In order for an update operation to work, the version you last downloaded on the client MUST be the same version as the version on the server. i.e. the version fields (exposed by the ETag header in the response and the version property in the object) MUST match. If they don't, you get a conflict.
Check out https://shellmonger.com/2016/04/25/30-days-of-zumo-v2-azure-mobile-apps-day-12-conflict-resolution/ for details on how to handle conflicts.
I also note that you are not using a Singleton for your MobileServiceClient. Check out https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/chapter6/angular/ for some hints on how to use the MobileServiceClient in an Angular app. Specifically, note that you should place the MobileServiceClient in a factory so that it becomes a singleton in your app.
Upvotes: 2