public ActionResult Upload(HttpPostedFileBase upload) { if (ModelState.IsValid) { if (upload != null && upload.ContentLength > 0) { if (upload.FileName.EndsWith(".csv")) { Stream stream = upload.InputStream; DataTable csvTable = new DataTable(); using (CsvReader csvReader = new CsvReader(new StreamReader(stream), true)) { csvTable.Load(csvReader); } foreach (DataRow row in csvTable.Rows) { foreach (DataColumn col in csvTable.Columns) { int i = 0; string colData = row[i].ToString(); string colDataFormatted = colData.Replace("\"", ""); var stringArray = colDataFormatted.Split(','); InfectedData data = new InfectedData() { Idade = int.Parse(stringArray[0]), Sexo = stringArray[1], TpPaciente = stringArray[2], Bairro = stringArray[3], DataInclusao = getDatetimeFromString(stringArray[4]), DataNotificacao = getDatetimeFromString(stringArray[5]), DataRecuperacao = getDatetimeFromString(stringArray[6]), DataObito = getDatetimeFromString(stringArray[7]), }; db.InfectedDatas.Add(data); i++; } } db.SaveChangesAsync(); return(View(csvTable)); } else { ModelState.AddModelError("Arquivo", "Formato do arquivo não é suportado"); return(View()); } } else { ModelState.AddModelError("Arquivo", "Faça o Upload do arquivo"); } } return(View()); }
public ActionResult DeleteConfirmed(int id) { InfectedData infectedData = db.InfectedDatas.Find(id); db.InfectedDatas.Remove(infectedData); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,Idade,Sexo,TpPaciente,Bairro,DataInclusao,DataNotificacao,DataRecuperacao,DataObito")] InfectedData infectedData) { if (ModelState.IsValid) { db.Entry(infectedData).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(infectedData)); }
public ActionResult Create([Bind(Include = "ID,Idade,Sexo,TpPaciente,Bairro,DataInclusao,DataNotificacao,DataRecuperacao,DataObito")] InfectedData infectedData) { if (ModelState.IsValid) { db.InfectedDatas.Add(infectedData); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(infectedData)); }
// GET: InfectedDatas/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } InfectedData infectedData = db.InfectedDatas.Find(id); if (infectedData == null) { return(HttpNotFound()); } return(View(infectedData)); }