public ActionResult VerifyClass(string name) { IClassInfoService classInfoService = StructureMap.ObjectFactory.GetInstance <IClassInfoService>(); bool vaild = classInfoService.GetObject(x => x.SchoolId == Account.SchoolId && x.ClassName == name) != null; return(Content(vaild ? "success" : "failed")); }
public ActionResult Add() { if (Account.UserType != 3) { return(Content("您没有执行本操作的权限")); } try { if (Request.Form["Id"].IsNullOrEmpty()) { Course course = new Course() { SchoolId = Account.SchoolId.Value, TeacherId = Account.Id, Title = Request.Form["Title"], SemesterStart = DateTime.Parse(Request.Form["SemesterStart"]), Weeks = (from week in Request.Form["Weeks"].Split(',') select Byte.Parse(week)).ToArray(), IsSelectableCourse = Boolean.Parse(Request.Form["IsSelective"]), }; service.SaveObject(course); ICourseClassRepository courseClassRepository = StructureMap.ObjectFactory.GetInstance <ICourseClassRepository>(); IClassInfoService classInfoService = StructureMap.ObjectFactory.GetInstance <IClassInfoService>(); foreach (string clazz in Request.Form["Classes"].Split(',')) { if (!clazz.IsNullOrEmpty()) { var clas = classInfoService.GetObject(x => x.SchoolId == Account.SchoolId && x.ClassName == clazz); courseClassRepository.Add(new CourseClass() { Classes_Id = clas.Id, Courses_Id = course.Id }); } } courseClassRepository.SaveChanges(); ICourseTimeRepository courseTimeRepository = StructureMap.ObjectFactory.GetInstance <ICourseTimeRepository>(); int i = 1; while (true) { if (!Request.Form.AllKeys.Contains("Weekday_" + i)) { break; } var weekday = Request.Form["Weekday_" + i]; var start = Request.Form["StartTime_" + i]; var end = Request.Form["EndTime_" + i]; var classroom = Request.Form["Classroom_" + i]; courseTimeRepository.Save(new CourseTime() { CourseId = course.Id, Classroom = classroom, Weekday = Byte.Parse(weekday), EndTime = TimeSpan.Parse(end), StartTime = TimeSpan.Parse(start) }); i++; } courseTimeRepository.SaveChanges(); return(Content("success")); } else { Course course = service.GetObject(Int64.Parse(Request.Form["Id"])); course.Classes.Clear(); ICourseClassRepository courseClassRepository = StructureMap.ObjectFactory.GetInstance <ICourseClassRepository>(); IClassInfoService classInfoService = StructureMap.ObjectFactory.GetInstance <IClassInfoService>(); foreach (string clazz in Request.Form["Classes"].Split(',')) { if (!clazz.IsNullOrEmpty()) { var clas = classInfoService.GetObject(x => x.SchoolId == Account.SchoolId && x.ClassName == clazz); courseClassRepository.Add(new CourseClass() { Classes_Id = clas.Id, Courses_Id = course.Id }); } } courseClassRepository.SaveChanges(); course.Title = Request.Form["Title"]; //course.StartTime = TimeSpan.Parse(model.StartTime); //course.EndTime = TimeSpan.Parse(model.EndTime); course.SemesterStart = DateTime.Parse(Request.Form["SemesterStart"]); //course.Weekday = Byte.Parse(model.Weekday); course.Weeks = (from week in Request.Form["Weeks"].Split(',') select Byte.Parse(week)).ToArray(); course.IsSelectableCourse = Boolean.Parse(Request.Form["IsSelective"]); service.SaveObject(course); course.CourseTimes.Clear(); int i = 1; while (true) { if (Request.Form["Weekday_" + i].IsNullOrEmpty()) { break; } var weekday = Request.Form["Weekday_" + i]; var start = Request.Form["StartTime_" + i]; var end = Request.Form["EndTime_" + i]; var classroom = Request.Form["Classroom_" + i]; course.CourseTimes.Add(new CourseTime() { CourseId = course.Id, Classroom = classroom, Weekday = Byte.Parse(weekday), EndTime = TimeSpan.Parse(end), StartTime = TimeSpan.Parse(start) }); } service.SaveObject(course); return(Content("success")); } } catch (Exception e) { return(Content(e.Message)); } }