We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Same record seen as ADDED and CHANGED in BatchEdit mode

Hi,

I have the following grid:

                            @(Html.EJ().Grid<SlimHub.Models.QuoteSimulationManagementCost>("QuoteSimulationManagementCostsGrid").Datasource(ds => ds.Json((IEnumerable<QuoteSimulationManagementCost>) Model.QuoteSimulationManagementCosts.ToList()).BatchURL("../ManagementCostBatchUpdate").Adaptor(AdaptorType.RemoteSaveAdaptor))
                                  .ShowSummary()
                                  .SummaryRow(row =>
                                  {
                                      row.Title("Totale").SummaryColumns(col => { col.SummaryType(SummaryType.Sum).Format("{0:C}").DisplayColumn("TotalPrice").DataMember("TotalPrice").Add(); }).Add();
                                  })
                                  .EditSettings(edit =>
                                  {
                                      edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch);
                                  })
                                  .Locale("it-IT")
                                  .ToolbarSettings(toolbar =>
                                  {
                                      toolbar.ShowToolbar().ToolbarItems(items =>
                                      {
                                          items.AddTool(ToolBarItems.Add);
                                          items.AddTool(ToolBarItems.Edit);
                                          items.AddTool(ToolBarItems.Delete);
                                          items.AddTool(ToolBarItems.Update);
                                          items.AddTool(ToolBarItems.Cancel);
                                      }).CustomToolbarItems(
                                          new List<object>()
                                          {
                                              //new Syncfusion.JavaScript.Models.CustomToolbarItem() {TemplateID = "#Details"},
                                              new Syncfusion.JavaScript.Models.CustomToolbarItem() {TemplateID = "#Details"}
                                          });
                                  })
                                  .AllowResizing()
                                  .AllowTextWrap(true)
                                  .Columns(col =>
                                  {
                                      col.Field("ManagementCostId").HeaderText("ID").HeaderTextAlign(TextAlign.Center).IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(10).Visible(true).Add();
                                      col.Field("QuoteSimId").HeaderText("ID Simulazione").HeaderTextAlign(TextAlign.Center).DefaultValue(Model.QuoteSimId).Width(10).Visible(true).Add();
                                      col.Field("EquipmentId").HeaderText("Attrezzatura").ForeignKeyField("EquipmentId").ForeignKeyValue("EquipmentDesc").DataSource((IEnumerable<object>) ViewBag.Equipments).HeaderTextAlign(TextAlign.Center).Width(80).Add();
                                      col.Field("NumInt").HeaderText("Numero Interventi").HeaderTextAlign(TextAlign.Center).TextAlign(TextAlign.Right).Format("{0:n0}").EditType(EditingType.Numeric).NumericEditOptions(new Syncfusion.JavaScript.Models.EditorProperties() {MinValue = 0}).Width(30).Add();
                                      col.Field("Quantity").HeaderText("Quantità").HeaderTextAlign(TextAlign.Center).TextAlign(TextAlign.Right).Format("{0:n1}").EditType(EditingType.Numeric).NumericEditOptions(new Syncfusion.JavaScript.Models.EditorProperties() {DecimalPlaces = 2, MaxValue = 99999999.99, Locale = "it-IT", MinValue = 0}).Width(30).Add();
                                      col.Field("UnitPrice").HeaderText("Prezzo Unitario").HeaderTextAlign(TextAlign.Center).TextAlign(TextAlign.Right).Format("{0:c2}").EditType(EditingType.Numeric).NumericEditOptions(new Syncfusion.JavaScript.Models.EditorProperties() {DecimalPlaces = 2, MaxValue = 99999999.99, Locale = "it-IT", MinValue = 0}).AllowEditing(true).Width(30).Add();
                                      col.Field("TotalPrice").HeaderText("Prezzo Totale").HeaderTextAlign(TextAlign.Center).TextAlign(TextAlign.Right).Format("{0:c2}").AllowEditing(true).Width(30).Add();
                                      col.Field("Annotations").HeaderText("Note").HeaderTextAlign(TextAlign.Center).Width(80).Add();
                                  })
                                  .ClientSideEvents(eve =>
                                  {
                                      eve.Create("ManagementGridCreate");
                                      eve.ActionComplete("ActionComplete");
                                      eve.BeforeBatchSave("BeforeBatchSave");
                                      eve.BeforeBatchAdd("ManagementBeforeBatchAdd");
                                      eve.Create("ManageGridCreate");
                                      eve.ToolbarClick("ManageToolBarClick");
                                      eve.CellEdit("ManageCostsCellEdit");
                                      eve.CellSave("ManageCostsCellSave");
                                      eve.QueryCellInfo("CalculateManageCostsTotalPrice");
                                  })
                                  )

This is the Controller Batch Update method:

        public ActionResult ManagementCostBatchUpdate(string action, List<QuoteSimulationManagementCost> added,
            List<QuoteSimulationManagementCost> changed, List<QuoteSimulationManagementCost> deleted, int? key)
        {
            if (added != null)
            {
                foreach (QuoteSimulationManagementCost qsmc in added)
                {
                    db.QuoteSimulationManagementCosts.Add(qsmc);
                }
            }
            if (changed != null)
            {
                foreach (QuoteSimulationManagementCost qsmc in changed)
                {
                    qsmc.TotalPrice = qsmc.NumInt * qsmc.Quantity * qsmc.UnitPrice;
                    db.Entry(qsmc).State = EntityState.Modified;
                }
            }
            if (deleted != null)
            {
                foreach (QuoteSimulationManagementCost qsmc in deleted)
                {
                    QuoteSimulationManagementCost quoteManagementCost = db.QuoteSimulationManagementCosts.Find(qsmc.ManagementCostId);
                    if (quoteManagementCost != null)
                    {
                        db.QuoteSimulationManagementCosts.Remove(quoteManagementCost);
                    }
                }
            }

            db.SaveChanges();

            var data = db.QuoteSimulations.ToList();
            return Json(data, JsonRequestBehavior.AllowGet);
        }

When I add a new record, in the ManagementCostBatchUpdate method the record is added either in the ADDED list or in the CHANGED list, so the SaveChanges() gives a concurrent modification error.

I think the issue is related to the fact that EquipmentId column is a dropdownlist with a datasource updated by an ajax call...

Can you help me?

Thanks 

Claudio


3 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team May 24, 2017 12:01 PM UTC

Hi Claudio, 

Thanks for contacting Syncfusion support.  

We created a sample with your code example and when we add a new record in BatchURL the record is added in added list only. In this you have mentioned that the issue is related to the Equipment Id column. The Equipment Id column is a foreignKey column. We also checked with foreignKey column and we unable to reproduce the mentioned issue at our end.  

To find out the root cause, we need the following details, 

1. Share the screenshot or video demonstration of an issue while adding new record. 

2. You also mentioned that you have updated datasource by an ajax call. Are you updating the datasource for a ForeignKey column by using ajax call? 
 
3. Essential Studio Version details. 
 

Regards, 
Prasanna Kumar N.S.V 
 



CR CLAUDIO RICCARDI May 24, 2017 02:13 PM UTC

Hi,

I have done the following operations on the grid:
1) Add a new record
2) Do not update clicking on the opdate button of the toolbar
3) Remove an existing record
4) Update clicking on the opdate button of the toolbar

After these operations, in the ManagementCostBatchUpdate method, I see 1 entry in the added items list  (which is correct) and 2 entries in the changed items list (which is not correct, as I have changed no records).

2) I update the DateSource of EquipmentId dropbox calling this js function:

    function UpdateEquipmentsDataSource() {
        debugger;
        var srvId = 0;
        var srvId2 = 0;
        var srvId3 = 0;
        var srvId4 = 0;
        var srvId5 = 0;

        if (ServiceTypeIdValue > 0)
        {
            srvId = ServiceTypeIdValue;
        }
        if (ServiceTypeIdValue2 > 0)
        {
            srvId2 = ServiceTypeIdValue2;
        }
        if (ServiceTypeIdValue3 > 0)
        {
            srvId3 = ServiceTypeIdValue3;
        }
        if (ServiceTypeIdValue4 > 0)
        {
            srvId4 = ServiceTypeIdValue4;
        }
        if (ServiceTypeIdValue5 > 0)
        {
            srvId5 = ServiceTypeIdValue5;
        }

        var srvlist = [srvId, srvId2, srvId3, srvId4, srvId5];

        //Se ho più di un servizio, disattivo il bottone di generazione automatica dell'offerta...
        var a = [];
        for (var i=0, l=srvlist.length; i<l; i++)
        {
            if (srvlist[i] != 0 && a.indexOf(srvlist[i]) === -1)
            {
                a.push(srvlist[i]);
            }
        }
        if (a.length > 1)
        {
            $("#QuoteFromSimulation").prop("disabled", true);
        }
        else
        {
            $("#QuoteFromSimulation").prop("disabled", false);
        }

        var pGridObj = $("#QuoteSimulationPlantCostsGrid").data("ejGrid");
        var mGridObj = $("#QuoteSimulationManagementCostsGrid").data("ejGrid");

        $.ajax({
            url: '@Url.Action("GetSrvEquipments", "QuoteSimulation")',
            type: 'POST',
            async: false,
            contentType: 'application/json;',
            data: JSON.stringify({ SrvArray: srvlist }),
            success: function (data)
            {
                for (var p = 0; p < pGridObj.model.columns.length; p++)
                {
                    if (pGridObj.model.columns[p].field === "EquipmentId")
                    {
                        pGridObj.model.columns[p].dataSource = data;
                        /*After updating the columns dropdown datasource pass the columns it to the grid`s columns method to update them.*/
                        pGridObj.columns(pGridObj.model.columns[p].field,"update");
                        break;
                    }
                }
                for (var m = 0; m < mGridObj.model.columns.length; m++)
                {
                    if (mGridObj.model.columns[m].field === "EquipmentId")
                    {
                        mGridObj.model.columns[m].dataSource = data;
                        /*After updating the columns dropdown datasource pass the columns it to the grid`s columns method to update them.*/
                        mGridObj.columns(pGridObj.model.columns[m].field,"update");
                        break;
                    }
                }
            }
        });
    }

3) I use version 15.1460.0.41 of Essential Studio

Thanks.

Claudio



MS Mani Sankar Durai Syncfusion Team May 26, 2017 10:42 AM UTC

Hi CLAUDIO, 

A support incident has been created under your account to track the status of this requirement. Please log on to our support website to check for further updates.   
 
Regards,   
Manisankar Durai 


Loader.
Live Chat Icon For mobile
Up arrow icon