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 Firebase authentication to sign in via phone number in conjunction with Express on Node.js

Encountering an issue while implementing backend Firebase Authorization. After thoroughly reading the documentation (https://firebase.google.com/docs/auth/web/phone-auth), I came to understand that Authorization requires two steps: send phone send code ...

How can I resolve the issue of <td> being repeatedly displayed five times instead of just twice in PHP?

Can someone assist me with fixing this for loop issue? I am trying to display controls next to each item in the row, but it is showing 5 sets of controls instead of just 2. <tbody> <?php //retrieve list of supplies $numOfRows = 0; $result = my ...

The hover feature on my website is making the picture flicker

I am experiencing an issue with a map on my website that contains four colored squares. When I hover over one of the squares, the image of the map changes to show the route corresponding to that color. However, this causes the image to shift position and i ...

Adding a button to a shadow root that already exists is not the proper procedure

var shadow = document.getElementById( "3rd-party-div" ).shadowRoot; let style = document.createElement("style"); style.textContent = ` .custom_button{ padding: 10px; display:block; float:left; text-ali ...

Timepicker Bootstrapping

I've been searching for a time picker widget that works well with Bootstrap styling. The jdewit widget has a great style, but unfortunately it comes with a lot of bugs. I'm on a tight deadline for my project and don't have the time to deal w ...

How can I retrieve the span html element without using a class with ajax?

Trying to work with Ajax syntax for the first time, I have this HTML code. <div class="select2-container select2" id="s2id_ServiceID-2-1" style="width: 100%;"> <a href="javascript:void(0)" onclick="return false;" class="select2-choice" tabind ...

The Alert Component fails to display when the same Error is triggered for the second time

In the midst of developing a Website using Nuxt.js (Vue.js), I've encountered an issue with my custom Alert Component. I designed a contact form on the site to trigger a specialized notification when users input incorrect data or omit required fields ...

Error encountered with AngularJS code when attempting to load content from another page using ajax

I'm currently tackling a challenge with AngularJs and php. Whenever I try to load content from another page, AngularJs seems to stop working. Let me provide you with a sample code snippet to illustrate my issue. main-page.php <div id="form-secti ...

The functionality of TypeScript's .entries() method is not available for the type 'DOMTokenList'

I'm currently working with a stack that includes Vue3, Vite, and TypeScript. I've encountered an issue related to DOMTokenList where I'm trying to utilize the .entries() method but TypeScript throws an error saying Property 'entries&apo ...

Bring in dynamically

I am interested in dynamically importing a module only when it is needed. To achieve this, I have created a small mixin: import {extend} from "vee-validate"; export const rules = { methods: { addRule (name) { let requi ...

Error encountered while parsing Node.js code for MySQL query execution

I am encountering an error message from Node that reads: Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TIMESTAMPDIFF(second, entered_at, c ...

Adjustable Bootstrap Progress Bar - Modify element width on the fly

I have encountered an issue with my progress bars on the webpage. The static HTML version works perfectly fine, but the dynamically created one using jQuery seems to be instantly at 100% without any delay in progression. To illustrate the problem better, ...

What are the steps to implement timer control in Ajax using JavaScript?

Hello, I have been trying to establish communication with the server through my application. To achieve this, I made a call to the webservice using AJAX. Now, I am looking to incorporate a time interval in AJAX. Can anyone kindly provide guidance on how ...

Angular UI directive for modal confirmation

Looking to create a custom Angular directive using angular-bootstrap that mimics the confirm() function. Check out the visual result and desired behavior in this plunk: http://embed.plnkr.co/27fBNbHmxx144ptrCuXV/preview Now, I want to implement a directi ...

Guide to sending AJAX requests to SQL databases and updating the content on the webpage

One way I have code to showcase a user's name is by using the following snippet: <div><?php echo 'My name is ' . '<span id="output">' . $_SESSION['firstname'] . '</span>' ?></div> ...

Troubleshooting PHP and jQuery AJAX: Why is $_POST always empty?

I'm struggling to display the $_POST value in an alert box using jQuery AJAX function. However, the $_POST value from my PHP controller always turns out to be empty, resulting in an empty array in the response. My setup includes PHP version 5.5 and j ...

Securely encoding information with PHP and decrypting it using JavaScript

I'm currently working with 2 servers. My goal is to generate a pair of keys, store the private key in local storage, and send the public key to my PHP server. The main objective is to encrypt data using the public key in PHP and decrypt it using Jav ...

How can I design a form that resembles the sign-in form used by Google?

Currently, I am in the process of creating a contact form for a website that is inspired by the design of Google's material sign-in form. I have successfully implemented an effect where clicking on the input field causes the label to change its posit ...

Tips for swapping out an item mid-scrolling?

What is the best way to change the navbar when scrolling a page in React? How can I achieve this while following React's concepts? Is using getElementById considered bad practice? const useState = React.useState const useEffect = React.useEffect con ...

Stop the flow of data in the RxJS stream depending on a specific value within the stream

I developed a straightforward component featuring a single button that initiates and halts a sequence of numbers generated by RxJS timer. import { Component, OnInit } from '@angular/core'; import { BehaviorSubject, Observable, timer, merge } fro ...