public void UploadIdCards(ExcelFile fileUpload) { var file = fileUpload.FileIdCards; string folderName = "UploadIdCards"; string webRootPath = _hostingEnvironment.WebRootPath; string newPath = Path.Combine(webRootPath, folderName); if (!Directory.Exists(newPath)) { Directory.CreateDirectory(newPath); } if (file.Length > 0) { string sFileExtension = Path.GetExtension(file.FileName).ToLower(); ISheet sheet; string fullPath = Path.Combine(newPath, file.FileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); stream.Position = 0; if (sFileExtension == ".xls" /* || sFileExtension == ".xlsx"*/) { HSSFWorkbook hssfwb = new HSSFWorkbook(stream); //This will read the Excel 97-2000 formats sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } else { XSSFWorkbook hssfwb = new XSSFWorkbook(stream); //This will read 2007 Excel format sheet = hssfwb.GetSheetAt(0); //get first sheet from workbook } IRow headerRow = sheet.GetRow(0); //Get Header Row int cellCount = headerRow.LastCellNum; for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++) //Read Excel File { IRow row = sheet.GetRow(i); if (row == null) { continue; } if (row.Cells.All(d => d.CellType == CellType.Blank)) { continue; } IdCardStudent idCard = new IdCardStudent(); idCard.BirthDate = DateTime.Parse(row.GetCell(0).ToString()); idCard.Country = row.GetCell(1).ToString(); idCard.IdCardNo = row.GetCell(2).ToString(); idCard.IdCardIssuedBy = row.GetCell(3).ToString(); idCard.IdCardIssuedDate = DateTime.Parse(row.GetCell(4).ToString()); idCard.District = row.GetCell(5).ToString(); idCard.Localty = row.GetCell(6).ToString(); idCard.Address = row.GetCell(7).ToString(); idCard.CivilStatus = row.GetCell(8).ToString(); _repository.InsertIdCard(idCard); } } } }
public void UpdateIdCardStudent(Student student, IdCardStudent idCardNew) { IdCardStudent idCardOld = db.IdCardStudents.FirstOrDefault(item => item.Id == student.IdCardStudentId); idCardOld.IdCardNo = idCardNew.IdCardNo; idCardOld.IdCardIssuedBy = idCardNew.IdCardIssuedBy; idCardOld.IdCardIssuedDate = idCardNew.IdCardIssuedDate; idCardOld.Country = idCardNew.Country; idCardOld.District = idCardNew.District; idCardOld.Localty = idCardNew.Localty; idCardOld.Address = idCardNew.Address; idCardOld.CivilStatus = idCardNew.CivilStatus; db.IdCardStudents.Update(idCardOld); }
public IActionResult IDCardInfoUpdate(IdCardStudent idCardStudent) { if (ModelState.IsValid) { _repository.UpdateIdCardStudent(AppController.student, idCardStudent); _repository.SaveAll(); TempData["mess"] = "Updated successfully!"; return(RedirectToAction("HomePageStudent", "HomePageStudent")); } else { ViewBag.ErrorUpdate = "Could not update! Try again!"; } return(View()); }
public void InsertIdCard(IdCardStudent idCard) { db.IdCardStudents.Add(idCard); }
public IActionResult IDCardInfoUpdate() { IdCardStudent idCard = _repository.GetIdCardStudentById(AppController.student.IdCardStudentId); return(View(idCard)); }