// GET: Student/Delete/5 public ActionResult CourseDelete(string id, string course) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } int c_id = PageValidate.FilterParam(course); Student_vs_Course svc = db.Student_vs_Courses.Where(x => x.svc_stu_id == id && x.svc_course_id == c_id).FirstOrDefault(); if (svc == null) { ViewBag.msg = "没有找到相关课程信息。"; } return(View(svc)); }
public ActionResult CourseDeleteConfirmed(string id, string courese) { int c_id = PageValidate.FilterParam(courese); Student_vs_Course svc = db.Student_vs_Courses.Where(x => x.svc_stu_id == id && x.svc_course_id == c_id).FirstOrDefault(); db.Student_vs_Courses.Remove(svc); db.SaveChanges(); var svcts = from svct in db.Student_vs_CTimess join cvt in db.Course_vs_Times on svct.svct_cvt_id equals cvt.cvt_id join c in db.Course_Infos on cvt.cvt_course_id equals c.course_id where svct.svct_stu_id == id && c.course_id == c_id select svct; if (svcts.Count() > 0) { db.Student_vs_CTimess.RemoveRange(svcts); db.SaveChanges(); } return(RedirectToAction("Details", new { id = id })); }
public ActionResult Register([Bind(Include = "student,course,pay,info")] ViewModel.RegisterModel registerModel) { if (ModelState.IsValid) { string stu_id = PageValidate.InputText(registerModel.student, 10); if (string.IsNullOrEmpty(stu_id)) { ViewBag.msg = "学生ID没有输入。"; return(Register()); } if (PageValidate.IsNumber(stu_id)) { if (db.Student_Infos.Where(x => x.stu_id == stu_id).Count() == 0) { ViewBag.msg = "学生信息不存在。"; return(Register()); } } else { var user = db.Student_Infos.Where(x => x.stu_name == stu_id).First(); if (user == null) { ViewBag.msg = "学生信息不存在。"; return(Register()); } stu_id = user.stu_id; } int course_id = registerModel.course; if (course_id == 0) { ViewBag.msg = "没有选择课程。"; return(Register()); } if (db.Course_Infos.Where(x => x.course_id == course_id).Count() == 0) { ViewBag.msg = "该课程不存在或已被删除,请刷新重新报名。"; return(Register()); } var cvtList = db.Course_vs_Times.Where(x => x.cvt_course_id == course_id); if (cvtList.Count() == 0) { ViewBag.msg = "该课程上课时间未安排,无法报名。"; return(Register()); } string info = PageValidate.InputText(registerModel.info, 8000); if (db.Student_vs_Courses.Where(x => x.svc_stu_id == stu_id && x.svc_course_id == course_id).Count() > 0) { ViewBag.msg = "该学生已报名该科目,请勿重复报名。"; return(Register()); } Student_vs_Course svcModel = new Student_vs_Course { svc_course_id = course_id, svc_add_time = DateTime.Now, svc_add_user = 1, svc_info = info, svc_pay = registerModel.pay, svc_stu_id = stu_id }; db.Student_vs_Courses.Add(svcModel); if (db.SaveChanges() == 0) { ViewBag.msg = "报名失败,请重新尝试。"; return(Register()); } List <Student_vs_CTimes> svcList = new List <Student_vs_CTimes>(); foreach (Course_vs_Time model in cvtList) { Student_vs_CTimes svctModel = new Student_vs_CTimes(); svctModel.svct_cvt_id = model.cvt_id; svctModel.svct_stu_id = stu_id; svctModel.svct_roll_call = 1; svcList.Add(svctModel); } db.Student_vs_CTimess.AddRange(svcList); if (db.SaveChanges() == 0) { ViewBag.msg = "报名成功,但是上课时间录入失败,请联系管理员处理。"; return(Register()); } return(RedirectToAction("Index")); } return(View()); }