public ActionResult Upload(FormCollection formCollection) { var subpieceList = new List <Kapasitematik_TakimOmru_v3.SubPiece>(); if (Request != null) { HttpPostedFileBase file = Request.Files["UploadedFile"]; if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName)) { string fileName = file.FileName; string fileContentType = file.ContentType; byte[] fileBytes = new byte[file.ContentLength]; var data = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength)); using (var package = new ExcelPackage(file.InputStream)) { ExcelPackage.LicenseContext = LicenseContext.NonCommercial; var currentSheet = package.Workbook.Worksheets; var workSheet = currentSheet.First(); var noOfCol = workSheet.Dimension.End.Column; var noOfRow = workSheet.Dimension.End.Row; for (int rowIterator = 1; rowIterator <= noOfRow; rowIterator++) { var subpiece = new Kapasitematik_TakimOmru_v3.SubPiece(); subpiece.SubPieceName = workSheet.Cells[rowIterator, 1].Value.ToString(); subpiece.ToolLife = Convert.ToInt32(workSheet.Cells[rowIterator, 2].Value); subpieceList.Add(subpiece); } } } } using (TakimOmruDBEntities db = new TakimOmruDBEntities()) { foreach (var item in subpieceList) { db.SubPiece.Add(new SubPiece() { SubPieceName = item.SubPieceName, ToolLife = item.ToolLife, FKPieceID = Convert.ToInt32(formCollection["id"]), Type = Convert.ToBoolean("false") }); } db.SaveChanges(); } return(RedirectToAction("TakimOmru", "Home")); }
public ThreeModel() { subPiece = new Kapasitematik_TakimOmru_v3.SubPiece(); }