The breeze is puzzled by the altered being, unable to identify it

I am currently working on a breeze implementation that involves displaying properties from a location object on the UI. However, when I make changes to some properties and attempt to save them, breeze does not recognize the entity as being changed. Here is the code snippet in question:

    [HttpGet]
    [CustomAuthorize(Claims = "permission:CanViewLocationAttributes")]
    public Location GetLocationById(int clientId, int locationId)
    {
        //returns a single Location object

    }

On the client-side, I have implemented functionality to retrieve and save the entity:

    function getLocationById(clientId, locationId) {
        var self = this;

        return EntityQuery.from('GetLocationById')
                            .withParameters({ clientId: clientId, locationId : locationId })
                            .using(self.manager)
                            .execute()
                            .then(querySucceeded, this._queryFailed);

        function querySucceeded(data) {
            if (data.results.length > 0) {
                return data.results[0];
            }
            logSuccess(localize.getLocalizedString('_RetrievedLocations_'), locations, true);
        }
    }

        function saveLocationSettings(clientId) {
        var self = this;
        var saveOptions = this.manager.saveOptions.using({ resourceName: "SaveLocationSettings",  allowConcurrentSaves: true });
        var entitiesToSave = self.manager.getChanges();
        return self.manager.saveChanges(entitiesToSave, saveOptions).then(saveSucceeded, saveFailed);
    }

The issue I am facing is that the value of entitiesToSave is always 0, even after I make changes to the fields in the UI and attempt to save them.

Here is how I bind the entity to my angular model:

  function getLocationDetails() {
        clientcontext.location.getLocationById($route.current.params.clientId, $route.current.params.id)
  .then(function (data) {
      basicLocationSettings.id = data.locationId;
      basicLocationSettings.parent = data.fkParentLocationId;
      basicLocationSettings.locationType = data.locationType;
      basicLocationSettings.locationName = data.locationName;
      basicLocationSettings.locationDisplayName = data.locationDisplayName;
      basicLocationSettings.locationCode = data.locationCode;
      basicLocationSettings.isActive = data.activeStatus;
      basicLocationSettings.timeZone = data.fkTimeZoneId;
      basicLocationSettings.usesAppointments = data.usesAppointments;
      basicLocationSettings.availabilityWindowDays = data.availabilityWindowDays;
      basicLocationSettings.appointmentCutOffDays = data.appointmentCutOffDays;
      basicLocationSettings.dailySummaryEmailTime = data.dailySummaryEmailTime;
      basicLocationSettings.reminderBeforeApptEmailTime = data.reminderBeforeApptEmailTime;
      basicLocationSettings.saveLocationSettings = function () {
          clientcontext.location.saveLocationSettings($route.current.params.clientId);
      }
  });
    }

If anyone could provide guidance on what might be going wrong here, I would greatly appreciate it as I am new to using breeze and currently feeling stuck.

Answer №1

It appears that you are transferring the location details from the breeze location entity to a pojo object variable called "basicLocationSettings". If any modifications are made to basicLocationSettings, they will not be monitored by the breeze entity manager or reflected in the original breeze entity. To ensure that user input directly alters the entity property values, you must connect the actual breeze entity to your UI.

Answer №2

After making some adjustments to my code, I have successfully resolved the saving issue:

 function retrieveLocation(clientId, locationId) {
        var self = this;
        var location = null;

        return EntityQuery.from('GetLocationById')
                            .withParameters({ clientId: clientId, locationId : locationId })
                            .using(self.manager)
                            .execute()
                            .then(querySuccess, this._queryFailed);

        function querySuccess(data) {
            if (data.results.length > 0) {
                location = data.results[0];
            }
            logSuccess(localize.getLocalizedString('_RetrievedLocations_'), locations, true);
            return location;
        }
    }

I want to highlight that the retrieved object is a location, which I then bind to my POJO in the controller.

        function getLocationDetails() {
        clientcontext.location.retrieveLocation($route.current.params.clientId, $route.current.params.id)
  .then(function (data) {
      basicLocationSettings.location = data;
      basicLocationSettings.saveLocationSettings = saveLocationSettings;
  });
    }

When invoking saveChanges(), I provide the location object to the repository:

      function saveLocationSettings() {
        clientcontext.location.saveLocationSettings(basicLocationSettings.location);
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Utilizing jQuery to apply a class based on the attributes of CSS

Is there a way in jQuery (or plain JS) to create a condition based on whether a div has a specific CSS attribute? For instance, I need jQuery to apply position:fixed to an element's CSS when another element has display:none, but switch back to positi ...

Issue with Pagination functionality when using Material-UI component is causing unexpected behavior

My database retrieves data based on the page number and rows per page criteria: const { data: { customerData: recent = null } = {} } = useQuery< .... //removed to de-clutter >(CD_QUERY, { variables: { input: { page: page, perPag ...

Exploring the process of defining and authenticating an array of objects utilizing cuid as the key and ensuring the object contains designated properties

I have a customized data set that requires validation: { "name": "Some unique name", "blocks": [ {"cj5458hyl0001zss42td3waww": { "quantity": 9, "rate": 356.77, ...

Is it possible to utilize v-html with message data in Vue without any limitations on the <title> element?

Currently utilizing Vue.js 2 and my SDK is IntelliJ: I am attempting to bring HTML content into a Vue.js file. The main objective is to include the <title></title> attribute, as it seems that Vue doesn't have direct support for this feat ...

Implementing the 'keepAlive' feature in Axios with NodeJS

I've scoured through numerous sources of documentation, Stack Overflow threads, and various blog posts but I'm still unable to make the 'keepAlive' functionality work. What could I be overlooking? Here's my server setup: import ex ...

How can I update data in Select2 after it has been initialized?

After initializing select2, I am trying to set an array of data in the following way: var selection = $('#selection').select2({}); selection.data([ {id: 1, text: 'value1'}, {id: 1, text: 'value1'} ]); However, I am encou ...

Tips for incorporating a Survey Monkey website embed into an Angular application

I have a Survey Monkey account with multiple surveys. I am trying to embed a survey from this website into my Angular website, which already has Bootstrap and jQuery added. I attempted to directly add the script in an HTML component, but it did not work. ...

I'm having trouble asynchronously adding a row to a table using the @angular/material:table schematic

Having trouble asynchronously adding rows using the @angular/material:table schematic. Despite calling this.table.renderRows(), the new rows are not displayed correctly. The "works" part is added to the table, reflecting in the paginator, but the asynchron ...

implementing datepicker on multiple textboxes in jQuery upon button click

I have the ability to show multiple text boxes using jQuery. I am now looking to add a datepicker to those text boxes. Any assistance in finding a solution would be greatly appreciated. Thank you in advance. ...

Are elements in React Native PanResponder capable of being clicked?

While I have movable panresponders, I also require the ability to click on one for an onPress event. Is it achievable? At present, they are <View> elements. If I attempt to switch them to <TouchableOpacity> or a similar element, it results in ...

"Converting an object to a JSON string using URLSearchParams: A step-by

I am currently working on a piece of code that retrieves all the input types from a form const form = document.querySelector('form'); const data = new URLSearchParams(new FormData(form).entries()); My main concern is how to convert the above ...

Embed a static label inside an input field that remains constant even while text is inputted, without using a placeholder. Crafted using HTML,

Take a look at the screenshot below - what you see on the left side is my current setup, while on the right side is the desired outcome achieved without any plugins or HTML5 attributes The left side scenario occurs when I have 2 input fields - one with th ...

What are the steps for importing KnockOut 4 in TypeScript?

It appears straightforward since the same code functions well in a simple JS file and provides autocompletion for the ko variable's members. Here is the TypeScript code snippet: // both of the following import lines result in: `ko` undefined // impo ...

Guide on setting up and customizing run.json within the latest JetBrains Fleet for Next.js

I've been attempting to set up input/output for the latest IDE from JetBrains, Fleet. However, I've hit a roadblock and can't seem to figure it out on my own. That's why I'm turning to the Stack Overflow community for help - how do ...

"if the condition is not met, the outcome will not be shown in the while

I have a looping structure that includes conditions for if, else if, and else. However, I have noticed that the else condition at the end of the loop is not being executed as expected. I am currently investigating why this might be happening. Here is the ...

Tackling the sticky header problem with in-browser anchoring and CSS dynamic height restrictions

I am experimenting with a unique combination of a Pure CSS in-page anchoring solution using scroll-behavior: smooth and scroll-margin-top settings, along with a sticky header for in-page navigation. By utilizing IntersectionObserver, I can identify when t ...

Looking to update the background color of a div every 3 seconds?

Every 3 seconds, I need to change the background color of each div. To do this, I attempted to modify the values in the color array every 3 seconds. For example, the value at index 0 (which is "red") would move to index 1, then the value at index 1 would ...

Creating Custom Filters in Angular using Functions

Attempting to filter ng-repeat using a function instead of an actual filter has presented some challenges. The code snippet below demonstrates the attempt: <tr ng-repeat="(key, value) in dataObj| filter:dataFilter"> The intention is to define dataF ...

Encountering issues with Vue 2.5 dynamic dropdown clicks not working as expected

Creating a dynamic dropdown with Vue.js 2.5 A static dropdown menu example: <ul class="dropdown-menu" role="menu" id="dropdown"> <li><a href="#" v-on:click="setDate('2018-11-11')">2018-11-11</a></li> <li> ...

What is the best method for purging a previously stored variable from the cache when making an Ajax call and simultaneously passing a

I am encountering an issue with variable loading during the ajax call. Upon clicking, I pass a variable to the ajax call which then sends the value to a PHP script. The data obtained is from: rnc.csv DLRNC01 DLRNC02 DLRNC03 DLRNC04 DLRNC05 DLRNC06 DLR ...