public ActionResult Edit(Student student) { if (ModelState.IsValid) { Db.Entry(student).State = EntityState.Modified; Db.SaveChanges(); return RedirectToAction("Index"); } return View(student); }
public ActionResult Create(Student student) { if (ModelState.IsValid) { Db.Students.Add(student); Db.SaveChanges(); return RedirectToAction("Index"); } return View(student); }
public virtual List<Student> AnalysisExcelToStudent(string filePath, ref string errorInfo) { var dataTable = NPOIHelper.Import(filePath); var resultList = new List<Student>(); for (var i = 1; i < dataTable.Rows.Count; i++) { var name = dataTable.Rows[i][0].ToString(); var sex = dataTable.Rows[i][1].ToString(); var nation = dataTable.Rows[i][2].ToString(); var department = dataTable.Rows[i][3].ToString(); var grade = dataTable.Rows[i][4].ToString(); var classabb = dataTable.Rows[i][5].ToString(); var id = dataTable.Rows[i][6].ToString(); var idcard = dataTable.Rows[i][7].ToString(); var dormnum = dataTable.Rows[i][8].ToString(); var ydtel = dataTable.Rows[i][9].ToString(); var dxtel = dataTable.Rows[i][10].ToString(); var lttel = dataTable.Rows[i][11].ToString(); var province = dataTable.Rows[i][12].ToString(); var city = dataTable.Rows[i][13].ToString(); var address = dataTable.Rows[i][14].ToString(); var teachername = dataTable.Rows[i][15].ToString(); var teachertel = dataTable.Rows[i][16].ToString(); var fathername = dataTable.Rows[i][17].ToString(); var fathertel = dataTable.Rows[i][18].ToString(); var mothertel = dataTable.Rows[i][19].ToString(); var mothername = dataTable.Rows[i][20].ToString(); if (String.IsNullOrEmpty(classabb) || String.IsNullOrEmpty(id)) { continue; } var classInfo = ClassInfoDao.GetClassInfoByAbbreviation(classabb); if (classInfo == null) { if (!ClassInfoDao.AddClass(classabb, teachername)) { errorInfo += "第" + i + "条数据班级不存在 "; return null; } } var student = new Student() { Name = name, Sex = sex, Nation = nation, ClassInfo = classInfo, Id = id, IdCard = idcard, DormInfo = DormInfoDao.GetDormInfoByNum(dormnum), YdTel = ydtel, DxTel = dxtel, LtTel = lttel, Province = province, City = city, Address = address, TeacherName = teachername, TeacherTel = teachertel, FatherName = fathername, FatherTel = fathertel, MotherName = mothername, MotherTel = mothertel }; if (Db.Students.FirstOrDefault(u => u.Id == student.Id) == null && resultList.FirstOrDefault(u => u.Id == student.Id) == null) { resultList.Add(student); } else { errorInfo = "第" + i + "条数据已存在"; return null; } } return resultList; }