Ejemplo n.º 1
0
 public virtual bool AddClass(String classname, String teacherNum)
 {
     var classInfo = GetClassInfoByAbbreviation(classname);
     if (classInfo != null) return true;
     var str = classname.Split('-');
     var classNumStr = str[1];
     var gradeStr = str[0].Substring(str[0].Length - 2, 2);
     var majorStr = str[0].Substring(0, str[0].Length - 2);
     var major = MajorDao.GetMajorByAbbreviation(majorStr);
     if (major == null) return false;
     var instructor = TeacherDao.GetTeacherByNum(teacherNum);
     //if (instructor == null) return false;
     classInfo = new ClassInfo
     {
         Name = classNumStr,
         Major = major,
         Grade = "20" + gradeStr,
         Abbreviation = classname,
         Instructor = instructor,
         IsStop = 0
     };
     Db.ClassInfos.Add(classInfo);
     Db.SaveChanges();
     return true;
 }
Ejemplo n.º 2
0
        public ActionResult Create(ClassInfo classinfo)
        {
            if (ModelState.IsValid)
            {
                Db.ClassInfos.Add(classinfo);
                Db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(classinfo);
        }
 public void When调用AddClass方法()
 {
     var scope = new TransactionScope();
     var context = new DormManageMvcContext();
     var classInfoDao = new ClassInfoDao(context);
     _result = classInfoDao.AddClass(_className, _teacherNum).ToString();
     _classInfo = classInfoDao.Db.ClassInfos.Include("Major").Include("Instructor").FirstOrDefault(p => p.Abbreviation == _className);
     scope.Dispose();
 }
Ejemplo n.º 4
0
 public ActionResult Edit(ClassInfo classinfo)
 {
     if (ModelState.IsValid)
     {
         Db.Entry(classinfo).State = EntityState.Modified;
         Db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(classinfo);
 }
Ejemplo n.º 5
0
        public ActionResult GetClassInfoByMajorAndAll(string major, string grade)
        {
            var list = new List<ClassInfo>();
            if (!String.IsNullOrEmpty(major) && grade == "全部")
            {
                list = Db.ClassInfos.Where(u => u.Major.Name == major).ToList();
            }
            else
            {
                list = Db.ClassInfos.Where(u => u.Major.Name == major && u.Grade == grade).ToList();
            }

            var all = new ClassInfo() { Abbreviation = "全部", Id = 0, IsStop = 0, Name = "全部" };
            list.Insert(0, all);
            return Json(list);
        }