when i click update button if i didn't add any new column, work correct but after i add new column, update button sometimes call update function, sometimes call create function. thats my problem
view
@(Html.Kendo().Grid(Model)
.Name("dersler")
.Columns(columns =>
{
columns.Bound(p => p.Tanim).Width(200);
columns.Bound(p => p.Aciklama).Width(100);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(180);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.PopUp)
.Window(conf => conf.Title("Yeni Ders"))
.TemplateName("DersTemplate"))
.Pageable()
.Sortable()
.Scrollable()
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.Id))
.Create(create => create.Action("DersOlustur", "Tanim"))
.Update(update => update.Action("DersGuncelle", "Tanim"))
.Destroy(destroy => destroy.Action("DersSil", "Tanim"))
)
)
controller
#region Ders
public ActionResult Dersler()
{
return View(Helper.Islemci.DersleriVer());
}
[AcceptVerbs(HttpVerbs.Post)]
public void DersOlustur([DataSourceRequest] DataSourceRequest request, Ders model)
{
if (model != null && ModelState.IsValid)
{
Helper.Islemci.DersTanimla(model);
}
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DersGuncelle([DataSourceRequest] DataSourceRequest request, Ders ders)
{
if (ders != null && ModelState.IsValid)
{
var target = Helper.Islemci.DersAra(ders.Id);
if (target != null)
{
target.Tanim = ders.Tanim;
target.Aciklama = ders.Aciklama;
ders = Helper.Islemci.DersGuncelle(target);
}
}
return Json(new[] { ders }.ToDataSourceResult(request, ModelState));
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult DersSil([DataSourceRequest] DataSourceRequest request, Ders ders)
{
if (ders != null)
{
Helper.Islemci.DersSil(ders);
}
return Json(new[] { ders }.ToDataSourceResult(request, ModelState));
}
#endregion
and my helper *
#region Ders
public List<Kurslar.Models.Ders> DersleriVer()
{
string sql = "SELECT * FROM KURS.DERSLER";
var dersler = DataManager.ReadIntoList<Kurslar.Models.Ders>(sql, _dbnumber);
return dersler;
}
public Kurslar.Models.Ders DersAra(int ID)
{
string sql = "SELECT * FROM KURS.DERSLER WHERE ID={0}";
sql = string.Format(sql, ID);
var ders = DataManager.ReadIntoList<Kurslar.Models.Ders>(sql, _dbnumber);
return ders.FirstOrDefault();
}
public Ders DersGuncelle(Ders model)
{
model.DurumKodu = "A";
model.IslemNo = model.IslemNo + 1;
IDatabase db = DataManager.GetDatabase(_dbnumber);
using (DbConnection conn = db.CreateConnection())
{
conn.Open();
using (DbTransaction trans = conn.BeginTransaction())
{
model.Update(trans);
trans.Commit();
}
}
return model;
}
public void DersTanimla(Ders ders )
{
ders.DurumKodu= "A";
ders.IslemNo= 1;
IDatabase db = DataManager.GetDatabase(_dbnumber);
using (DbConnection conn = db.CreateConnection())
{
conn.Open();
using (DbTransaction trans = conn.BeginTransaction())
{
ders.Id = (short)db.GetNextIdFor(ders.GetType(), trans);
ders.Insert(trans);
trans.Commit();
}
}
}
public Ders DersSil(Ders ders)
{
IDatabase db = DataManager.GetDatabase(_dbnumber);
using (DbConnection conn = db.CreateConnection())
{
conn.Open();
using (DbTransaction trans = conn.BeginTransaction())
{
ders.Delete(trans);
trans.Commit();
}
}
return ders;
}
#endregion