public ActionResult Create(Surdo collection, string ListStatus) { try { if (ModelState.IsValid) { int id = dbMpContex.Surdo.Select(s => s.id).DefaultIfEmpty(0).Max(); collection.id = dbMpContex.Surdo.Select(s => s.id).DefaultIfEmpty(0).Max() + 1; dbMpContex.Surdo.Add(collection); dbMpContex.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ListStatus = ListStatus; ViewBag.Erro = string.Empty; return(View(collection)); } catch (Exception ex) { ViewBag.ListStatus = ListStatus; ViewBag.Erro = ex.Message.ToString(); return(View()); } }
public ActionResult Edit(Surdo ObjSurdo) { try { if (ModelState.IsValid) { dbMpContex.Entry(ObjSurdo).State = System.Data.Entity.EntityState.Modified; dbMpContex.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ListStatus = ListStatus(ObjSurdo.status); ViewBag.Erro = string.Empty; return(View()); } catch (Exception ex) { ViewBag.ListStatus = ListStatus(ObjSurdo.status); ViewBag.Erro = ex.Message.ToString(); return(View()); } }
void LerArquivo() { int counter = 0; string line; System.IO.StreamReader file = new System.IO.StreamReader(@"C:\Users\dp\Documents\Sistemas\LsMapasNet\LsMapasNet\arquivos\scriptSurdo.txt"); while ((line = file.ReadLine()) != null) { Surdo ObjSurdo = new Surdo(); string[] surdolinha = line.Split('|'); ObjSurdo.id = Convert.ToInt32(surdolinha[1]); if (Convert.ToInt32(surdolinha[1]) == 279) { counter++; } ObjSurdo.nome = surdolinha[2]; ObjSurdo.endereco = surdolinha[3]; ObjSurdo.perimetro = surdolinha[4]; ObjSurdo.classe = surdolinha[5]; ObjSurdo.latitude = surdolinha[6]; ObjSurdo.longitude = surdolinha[7]; ObjSurdo.bairro = surdolinha[8]; ObjSurdo.status = surdolinha[9]; dbMpContex.Surdo.Add(ObjSurdo); dbMpContex.SaveChanges(); counter++; } counter++; }