I'm having problems at the time of editing, more specifically in the line below,
db.Entry (ladA) .State = EntityState.Modified;
db.SaveChanges ();
The update that precedes the above lines usually occurs, where I indicate below.
Data update usually occurs
db.Entry (seq) .State = EntityState.Modified;
db.SaveChanges ();
Error that occurs in the image attached to this post.
[HttpPost][ValidateAntiForgeryToken]publicActionResultEdit(FormCollectionform){varsequenciaViewModel=newSequenciaViewModel();if(ModelState.IsValid){varseq=newSequencia{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();
}