Tuesday, January 26, 2016

replace Parts Array with New Values

 self.Get_ExaminationForm_ByID = function (vehicleID) {
        $.ajax({
            url: Get_ExaminationForm_ByID_URL,
            type: "POST", async: false,
            data: JSON.stringify({ vehicleID: vehicleID }),
            contentType: 'application/json; charset=utf-8',
            success: function (data, textStatus, jqXHR) {
                self.examination = new ExaminationFormDTO(data);
                self.examination.ImageURL('data:image/jpeg;base64,' + data.ImageURL);
                self.vehicleValue = new VehicleDTO(data.vehicleInfo);
                self.replacePartsArraywithNewValues(data.Parts);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                $("#MessageLabel").html('Error: ' + errorThrown);
                $('#NotificationModel').modal('show'); //alert('Error: ' + errorThrown);
            }
        });
    };

    //replace Parts Array with New Values
    self.replacePartsArraywithNewValues = function (partTypeData) {

        //Loop the Data base Values
        ko.utils.arrayForEach(partTypeData, function (dataBounditem) {

            //Loop the Current array and compare the Database id and Array id
            ko.utils.arrayFirst(self.parttypes(), function (currentArrayitem) {
                //compare the Database id and Array id matached then Replace the Value in Current Array with Database Values
                if (currentArrayitem.PartTypeId() == dataBounditem.PartTypeId) {
                    //      alert('Value Found');
                    currentArrayitem.Availability = dataBounditem.Availability;
                    currentArrayitem.ExaminationFormDetailedId = dataBounditem.ExaminationFormDetailedId;
                }
            });
        });

    };

No comments:

Post a Comment