jdanyow / aurelia-breeze-northwind

A Northwind demo using Aurelia and Breeze
http://jdanyow.github.io/aurelia-breeze-northwind/
MIT License
92 stars 35 forks source link

Adding this.entityManager.saveChanges() in entity-view-model.js does not persist changes into db #1

Closed rajajhansi closed 9 years ago

rajajhansi commented 9 years ago

@jdanyow, First of all, thank you so much for this wonderful aurelia breeze sample. I modified the settings.js to point to a local Northwind service endpoint (running as an ASP.NET Web API project). I added this.saveChanges() right after this.acceptChanges in entity-view-model.js as follows:

save() {
    // fake save...
    this.entityManager.acceptChanges();
    this.entityManager.saveChanges();
    Materialize.toast('Changes saved.', 2000)
  }

I also changed the copyEntityManager, which was returning an empty copy to return the actual entityManager as follows:

function copyEntityManager() { 
  return entityManager;
}

I think your comment //fake save... meant that just calling acceptChanges will only update the client cache of breeze but not the server. Even after adding saveChanges(), I don't see the call to saveChanges on my WebAPI in the network tab of my browser. Please let me know what do I miss to make it persist the changes via the WebAPI.

jdanyow commented 9 years ago

'acceptChanges' returns the entity to an EntityState of 'Unchanged' by committing all changes made since the entity was last queried had 'acceptChanges' called on it. You don't want to call 'acceptChanges' prior to calling 'saveChanges' because there won't be any changes to save. Try changing the save method to this:

  save() {
    this.entityManager.saveChanges()
      .then(() => Materialize.toast('Changes saved.', 2000));
  }