public ActionResult UploadFile(HttpPostedFileBase file) { //dat ten cho file string _FileName = "ruoumoi.xls"; //duong dan luu file string _path = Path.Combine(Server.MapPath("~/Uploads/Excels"), _FileName); //luu file len server file.SaveAs(_path); //doc du lieu tu file excel DataTable dt = ReadDataFromExcelFile(_path); /* CopyDataByBulk(dt);*/ for (int i = 0; i < dt.Rows.Count; i++) { KhoRuou kr = new KhoRuou(); kr.TenRuou = dt.Rows[i][0].ToString(); kr.NongDo = dt.Rows[i][1].ToString(); kr.TinhChat = dt.Rows[i][2].ToString(); kr.SoLuong = dt.Rows[i][3].ToString(); kr.DonVi = dt.Rows[i][4].ToString(); kr.TheTich = dt.Rows[i][5].ToString(); kr.NguonGoc = dt.Rows[i][6].ToString(); kr.DanhGia = dt.Rows[i][7].ToString(); db.KhoRuous.Add(kr); db.SaveChanges(); } /* CopyDataByBulk(excel.ReadDataFromExcelFile(_path));*/ return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { KhoRuou khoRuou = db.KhoRuous.Find(id); db.KhoRuous.Remove(khoRuou); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "IDRuou,TenRuou,NongDo,TinhChat,SoLuong,DonVi,TheTich,NguonGoc,DanhGia")] KhoRuou khoRuou) { if (ModelState.IsValid) { db.Entry(khoRuou).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(khoRuou)); }
public ActionResult Create([Bind(Include = "IDRuou,TenRuou,NongDo,TinhChat,SoLuong,DonVi,TheTich,NguonGoc,DanhGia")] KhoRuou khoRuou) { if (ModelState.IsValid) { db.KhoRuous.Add(khoRuou); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(khoRuou)); }
// GET: KhoRuous/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } KhoRuou khoRuou = db.KhoRuous.Find(id); if (khoRuou == null) { return(HttpNotFound()); } return(View(khoRuou)); }