user5260143
user5260143

Reputation: 1098

breeze array , after push items, know in the server that array has changed

I have array of breeze in durandal project. in my client-side, after accept data from server, I push new items to the array. but when I come to server-side, it not show the array in the "originalValuesMap". it doesn't understanr that if I have add items to array- it mean that the array is now modified. what should I do?

here is my code:

in model.js, the definition of the classes is:

      addPersonType(store);
    function addPersonType(store) {
        store.addEntityType({
            shortName: "PersonDTO",
            namespace: "myServer.Entities",
            autoGeneratedKeyType: AutoGeneratedKeyType.Identity,
            dataProperties: {
                Emp_no1: { dataType: DataType.Int32, isNullable: false, isPartOfKey: true },                   
                personAccessData: {
                    name: "personAccessData",
                    complexTypeName: "PersonAccessDTO:#myServer.Entities",
                    isNullable: true
                }
            }

        });
        store.registerEntityTypeCtor("EmployeeDTO", null, employeeInit);
    }

   addPersonAccessType(store);
    function addPersonAccessType(store) {
        store.addEntityType({
            shortName: "PersonAccessDTO",
            namespace: "myServer.Entities",
            isComplexType: true,
            dataProperties: {
                PermGroup: { dataType: DataType.Int32, isNullable: true, isPartOfKey: false },
                PermGroupName: { dataType: DataType.String, isPartOfKey: false },                  

                MultyProfilesList: {  isPartOfKey: false, isScalar: false }
            }

        });
        store.registerEntityTypeCtor("PersonAccessDTO", null, null);
    }

my logic is:

        for (var i = 0; i < vm.multyProfilesSelectBox.destination().length; i++) {
        vm.data().MultyProfilesList().push(vm.multyProfilesSelectBox.destination()[i]);
    }

in the server:

      List<EntityInfo> infos;
        string errorMessage = "";
        if (!saveMap.TryGetValue(typeof(PersonDTO), out infos))
        {
            return "";
        }
        foreach (var ei in infos)
        {
            var personData = (PersonDTO)ei.Entity;
            if (personData .IsValid())
            {
                if (ei.EntityState == EntityState.Added)
                {
                   //some code...
                }
                else if (ei.EntityState == EntityState.Modified)
                {
                    if (ei.OriginalValuesMap.ContainsKey("personAccessData"))
                    {
                          //some code...
                    }
                }

            }
            else
            {
                throw new Exception("there validations errors in employee " + employeeData.GetErrorMessages());
            }
        }

the problem is that the condition :

        if (ei.OriginalValuesMap.ContainsKey("personAccessData"))

return false!!!

Upvotes: 0

Views: 368

Answers (2)

user3127364
user3127364

Reputation:

first, you have to define your array in another way:

       MultyProfilesList: {  
         name: 'multyProfilesList'
         complexTypeName: 'PersonAccessDTO:#myServer.Entities'
         isPartOfKey: false,
         isScalar: false
       }

second, when you push item to the array, you have create the item as un-bound instance of your complex-type. (see What's the correct way to create an unbound instance of a complex type in breeze?)

now, try to see if it works well.

Upvotes: 1

Dominictus
Dominictus

Reputation: 721

You need to understand how data flows in your application. You ask server for data to show in your browser. Server sends you data. You have data shown. That data is just copy of data from server. Once you modify that copy, it is modified in your browser, but server has no way of knowing that. In order for server to modify real data, you need to send it what has changed. You should make call like this:

manager.saveChanges();

That should make client send server data which should be saved.

edit: looking at your code, I suggest you check out HotTowel template and tutorial by John Papa. It might make your life easier.

Upvotes: 0

Related Questions