예제 #1
0
 public ActionResult CourseEdit([Bind(Include = "student,course,pay,info")] ViewModel.RegisterModel registerModel)
 {
     return(View());
 }
예제 #2
0
 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());
 }