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