예제 #1
0
        public static bool UpdateStudentInfo(Student s)
        {
            try
            {
                ////查询出来一个student
                //Student stu = StudentServer.SelectStudentByID(s.StuID);
                //ExamDBEntities db = new ExamDBEntities();
                //db.Entry(stu).State = EntityState.Modified;
                ////逐个更新
                //stu.StuName = s.StuName;
                //stu.StuLoginName = s.StuLoginName;
                //stu.StuSex = s.StuSex;
                //stu.StuGrade = s.StuGrade;
                //stu.StuEmail = s.StuEmail;
                //stu.StuLoginPwd = s.StuLoginPwd;
                //stu.StuPhone = s.StuPhone;

                //查询出来一个student
                Student        stu = StudentServer.SelectStudentByID(s.StuID);
                ExamDBEntities db  = new ExamDBEntities();
                //这也可以实现对象的快速修改,推荐用这个方法
                db.Entry(s).State = EntityState.Modified;    //直接将传入的对象,设置修改装填
                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #2
0
 public ActionResult Edit([Bind(Include = "UserId")] Teacher teacher)
 {
     if (ModelState.IsValid)
     {
         db.Entry(teacher).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(teacher));
 }
예제 #3
0
 public ActionResult Edit([Bind(Include = "Id,CourseId,Question,Active,Answer1,Answer2,Answer3,GoodAnswer")] Task task)
 {
     if (ModelState.IsValid)
     {
         db.Entry(task).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CourseId = new SelectList(db.Course, "Id", "Name", task.CourseId);
     return(View(task));
 }
예제 #4
0
 public ActionResult Edit([Bind(Include = "Id,StudentId,StartTime,EndTime,T1,A1,T2,A2,T3,A3,T4,A4")] Exam exam)
 {
     if (ModelState.IsValid)
     {
         db.Entry(exam).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.StudentId = new SelectList(db.Student, "UserId", "UserId", exam.StudentId);
     ViewBag.T1        = new SelectList(db.Task, "Id", "Question", exam.T1);
     ViewBag.T2        = new SelectList(db.Task, "Id", "Question", exam.T2);
     ViewBag.T3        = new SelectList(db.Task, "Id", "Question", exam.T3);
     ViewBag.T4        = new SelectList(db.Task, "Id", "Question", exam.T4);
     return(View(exam));
 }
예제 #5
0
 public static bool AddStudent(Student s)
 {
     using (ExamDBEntities db = new ExamDBEntities())
     {
         try
         {
             db.Entry(s).State = EntityState.Added;//也可以不加,因为Add时,会自动修改状态
             db.Students.Add(s);
             db.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
예제 #6
0
 public static bool DeleteStudentByID(int id)
 {
     try
     {
         //获取要删除的学生信息
         Student        s  = StudentServer.SelectStudentByID(id);
         ExamDBEntities db = new ExamDBEntities();
         //将要删除的学生对象状态,修改为删除。
         db.Entry(s).State = EntityState.Deleted;
         db.Students.Remove(s);//Remove删除
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }