1
I am having problems at the time of editing, more specifically in the lines below,
db. Entry(Lada). State = Entitystate.Modified;
db Savechanges.();
the update that precedes the lines above, occurs normally, where below indicate.
Data update occurs normally
db. Entry(seq). State = Entitystate.Modified;
db Savechanges.();
Error that occurs in the image attached to this post.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(FormCollection form)
{
var sequenciaViewModel = new SequenciaViewModel();
if (ModelState.IsValid)
{
var seq = new Sequencia
{
SequenciaId = Convert.ToInt16(form["Sequencia.SequenciaId"].ToString()),
DataAbate = Convert.ToDateTime(form["Sequencia.DataAbate"].ToString()),
NumeroLote = Convert.ToInt16(form["Sequencia.NumeroLote"].ToString()),
NumeroSequencia = Convert.ToInt16(form["Sequencia.NumeroSequencia"].ToString())
};
db.Entry(seq).State = EntityState.Modified;
db.SaveChanges();
var aff = db.SequenciaLados.Where(s => s.SequenciaId == seq.SequenciaId).ToList();
foreach (var item in aff)
{
if (item.Lado.Nome.Equals("A"))
{
var ladA = new Lado
{
LadoId = item.LadoId,
Nome = form["Lado_A.Nome"].ToString(),
CamaraId = Convert.ToInt16(form["Camara_Lado_A"].ToString()),
TipoLadoId = Convert.ToInt16(form["Tipo_Lado_A"].ToString())
};
db.Entry(ladA).State = EntityState.Modified;
db.SaveChanges();
}
else if (item.Lado.Nome.Equals("B"))
{
var ladB = new Lado
{
LadoId = item.LadoId,
Nome = form["Lado_B.Nome"].ToString(),
CamaraId = Convert.ToInt16(form["Camara_Lado_B"].ToString()),
TipoLadoId = Convert.ToInt16(form["Tipo_Lado_B"].ToString())
};
db.Entry(ladB).State = EntityState.Modified;
db.SaveChanges();
}
}
return RedirectToAction("Index");
}
return View();
}