// GET: Student/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewModel.StudentsModel studend_Info = (from stus in db.Student_Infos where stus.stu_id == id select new ViewModel.StudentsModel { address = stus.stu_home_address, birthday = stus.stu_birthday, cardType = stus.stu_card_type, email = stus.stu_email, grade = stus.stu_grade_id, id = stus.stu_id, IdCard = stus.stu_idCard, name = stus.stu_name, phone = stus.stu_phone, photo = stus.stu_photo_path, school = stus.stu_school_id, sex = stus.stu_sex }).FirstOrDefault(); if (studend_Info == null) { //return HttpNotFound(); ViewBag.msg = "没有查到该学生信息,可能已被删除。"; } CreateSelect(); return(View(studend_Info)); }
public ActionResult Edit([Bind(Include = "id,name,sex,birthday,photo,phone,email,school,grade,address,cardType,IdCard")] ViewModel.StudentsModel StudentsModel) { if (ModelState.IsValid) { try { Student_Info student_info = db.Student_Infos.Find(StudentsModel.id); if (student_info == null) { ViewBag.msg = "没有查到该学生信息,可能已被删除。"; CreateSelect(); return(View(StudentsModel)); } if (db.Student_Infos.Where(x => x.stu_id != StudentsModel.id && x.stu_card_type == StudentsModel.cardType && x.stu_idCard == StudentsModel.IdCard).Count() > 0) { ViewBag.msg = "该证件号已存在,请勿重新添加。"; CreateSelect(); return(View(StudentsModel)); } student_info.stu_id = StudentsModel.id; student_info.stu_card_type = StudentsModel.cardType; student_info.stu_idCard = PageValidate.InputText(StudentsModel.IdCard, 18); student_info.stu_birthday = StudentsModel.birthday; student_info.stu_email = PageValidate.InputText(StudentsModel.email, 200); student_info.stu_grade_id = StudentsModel.grade; student_info.stu_home_address = PageValidate.InputText(StudentsModel.address, 500); student_info.stu_name = PageValidate.InputText(StudentsModel.name, 50); student_info.stu_phone = PageValidate.InputText(StudentsModel.phone, 20); student_info.stu_school_id = StudentsModel.school; student_info.stu_sex = PageValidate.InputText(StudentsModel.sex, 2); string up_photo = PageValidate.InputText(StudentsModel.photo, 50); if (up_photo != student_info.stu_photo_path) { string file_name = string.Format("{0}.jpg", student_info.stu_idCard); string save_name = string.Format(Server.MapPath(string.Format("~/images/stu/{0}", file_name))); string old_path = string.Format(Server.MapPath(string.Format("~/images/temp/{0}", up_photo))); FileInfo fi = new FileInfo(old_path); fi.CopyTo(save_name, true); student_info.stu_photo_path = file_name; } db.Entry(student_info).State = EntityState.Modified; db.SaveChanges(); DataCache.RemoveCache("cache_student"); } catch (Exception e) { ViewBag.msg = e.ToString(); CreateSelect(); return(View(StudentsModel)); } } return(RedirectToAction("ViewList")); }
public ActionResult Create([Bind(Include = "name,sex,birthday,photo,phone,email,school,grade,address,cardType,IdCard")] ViewModel.StudentsModel StudentsModel) { if (ModelState.IsValid) { if (db.Student_Infos.Where(x => x.stu_card_type == StudentsModel.cardType && x.stu_idCard == StudentsModel.IdCard).Count() > 0) { ViewBag.msg = "该证件号已存在,请勿重新添加。"; CreateSelect(); return(View(StudentsModel)); } Student_Info student_info = new Student_Info(); student_info.stu_card_type = StudentsModel.cardType; student_info.stu_idCard = PageValidate.InputText(StudentsModel.IdCard, 18); student_info.stu_birthday = StudentsModel.birthday; student_info.stu_email = PageValidate.InputText(StudentsModel.email, 200); student_info.stu_grade_id = StudentsModel.grade; student_info.stu_home_address = PageValidate.InputText(StudentsModel.address, 500); student_info.stu_name = PageValidate.InputText(StudentsModel.name, 50); student_info.stu_phone = PageValidate.InputText(StudentsModel.phone, 20); student_info.stu_photo_path = PageValidate.InputText(StudentsModel.photo, 50); student_info.stu_school_id = StudentsModel.school; student_info.stu_sex = PageValidate.InputText(StudentsModel.sex, 2); string up_photo = PageValidate.InputText(StudentsModel.photo, 50); if (!string.IsNullOrEmpty(up_photo)) { string file_name = string.Format("{0}.jpg", student_info.stu_idCard); string save_name = string.Format(Server.MapPath(string.Format("~/images/stu/{0}", file_name))); string old_path = string.Format(Server.MapPath(string.Format("~/images/temp/{0}", up_photo))); FileInfo fi = new FileInfo(old_path); fi.CopyTo(save_name, true); student_info.stu_photo_path = file_name; } if (db.Student_Infos.Count() == 0) { student_info.stu_id = DateTime.Now.ToString("yyyy") + "100001"; } else { string strNum = db.Student_Infos.OrderByDescending(x => x.stu_id).First().stu_id.Substring(4, 6); int Num = Int32.Parse(strNum) + 1; student_info.stu_id = DateTime.Now.ToString("yyyy") + Num.ToString(); } db.Student_Infos.Add(student_info); db.SaveChanges(); ViewBag.msg = "添加成功。"; DataCache.RemoveCache("cache_student"); //return RedirectToAction("Index"); } CreateSelect(); return(View(StudentsModel)); }
// GET: Student/Create public ActionResult Create() { CreateSelect(); ViewModel.StudentsModel model = new ViewModel.StudentsModel(); return(View(model)); }
// GET: Student/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewModel.StudentDetail detail = new ViewModel.StudentDetail(); ViewModel.StudentsModel student_Info = (from stus in db.Student_Infos join school in db.Dic_Schools on stus.stu_school_id equals school.school_id into T1 from t1 in T1.DefaultIfEmpty() join grade in db.Dic_Grades on stus.stu_grade_id equals grade.grade_id into T2 from t2 in T2.DefaultIfEmpty() where stus.stu_id == id select new ViewModel.StudentsModel { address = stus.stu_home_address, birthday = stus.stu_birthday, cardType = stus.stu_card_type, email = stus.stu_email, grade = stus.stu_grade_id, id = stus.stu_id, IdCard = stus.stu_idCard, name = stus.stu_name, phone = stus.stu_phone, photo = stus.stu_photo_path, school = stus.stu_school_id, sex = stus.stu_sex, school_name = t1.school_name == null ? "" : t1.school_name, grade_name = t2.grade_name == null ? "" : t2.grade_name }).FirstOrDefault(); if (student_Info == null) { ViewBag.msg = "没有找到学生信息。"; return(View(student_Info)); } detail.student_Info = student_Info; var stu_courses = from svc in db.Student_vs_Courses join course in db.Course_Infos on svc.svc_course_id equals course.course_id join sub in db.Dic_Subjects on course.c_sub_id equals sub.sub_id join season in db.Course_Seasons on course.c_cs_id equals season.c_season_id where svc.svc_stu_id == id orderby svc.svc_add_time select new ViewModel.StudnentCourse { student = id, course = svc.svc_course_id, course_name = course.course_name, season = season.c_season_name, state = svc.svc_is_end ? "完结" : "进行中", subject = sub.sub_name, time = course.c_time_info }; detail.stu_courses = stu_courses.ToList(); return(View(detail)); }