/// <summary>
        /// 直接输入课程名称并创建
        /// </summary>
        /// <returns></returns>
        public ActionResult CreateCourse()
        {
            var vm = new Models.ElectiveApply.CourseEdit();

            using (var db = new XkSystem.Models.DbContext())
            {
                if (vm.ElectiveId == 0)
                {
                    vm.IsError = true;
                    return(View(vm));
                }

                vm.ApplyCourse.CourseName = vm.CourseName;
                vm.CourseSubjectList      = ElectiveSubjectController.SelectSubjectList(vm.ElectiveId);
                vm.CourseTypeList         = Course.Controllers.CourseTypeController.SelectList();
                vm.CourseDomainList       = Course.Controllers.CourseDomainController.SelectList();
                vm.CourseGroupList        = Course.Controllers.CourseGroupController.SelectList();
            }
            return(View(vm));
        }
        public ActionResult Edit(int id = 0, int courseId = 0, int electiveId = 0)
        {
            var vm = new Models.ElectiveApply.Edit();


            using (var db = new XkSystem.Models.DbContext())
            {
                if (id == 0)
                {
                    //vm.CourseList = Course.Controllers.CourseController.SelectList();
                }
                else
                {
                    var tb = (from p in db.Table <Entity.tbElectiveApply>()
                              where p.Id == id
                              select new Dto.ElectiveApply.Edit()
                    {
                        Id = p.Id,
                        ElectiveId = p.tbElective.Id,
                        CourseId = p.tbCourse.Id,
                        Hour = p.Hour,
                        Point = p.tbCourse.Point,
                        TeachPlan = p.TeachPlan,
                        StudyTarger = p.StudyTarger,
                        MaxStudent = p.MaxStudent,
                        RoomId = p.tbRoom.Id,
                        SubjectId = p.tbCourse.tbSubject.Id,
                        TeacherId = p.tbSysUser.Id,
                        CheckOpinion = p.CheckOpinion,
                        CheckStatus = p.CheckStatus,
                        tbElectiveApplySchedule = db.Set <Entity.tbElectiveApplySchedule>().Where(c => c.tbElectiveApply.Id == p.Id).Select(c => new Dto.ElectiveApplySchedule.List()
                        {
                            WeekId = c.tbWeek.Id,
                            WeekName = c.tbWeek.WeekName,
                            PeriodId = c.tbPeriod.Id,
                            PeriodName = c.tbPeriod.PeriodName
                        }).ToList(),
                        tbElectiveApplyFile = db.Set <Entity.tbElectiveApplyFile>().Where(c => c.tbElectiveApply.Id == p.Id).Select(c => new Dto.ElectiveApplyFile.List()
                        {
                            FileName = c.FileName,
                            FileTitle = c.FileTitle
                        }).ToList()
                    }).FirstOrDefault();
                    vm.ElectiveApplyEdit = tb;

                    courseId   = courseId == 0 ? tb.CourseId : courseId;
                    electiveId = electiveId == 0 ? tb.ElectiveId : electiveId;
                }

                vm.ElectiveApplyEdit.CourseId   = courseId;
                vm.ElectiveApplyEdit.ElectiveId = electiveId;

                if (courseId > 0 && electiveId > 0)
                {
                    var tbCourse = (from p in db.Table <Course.Entity.tbCourse>()
                                    where p.Id == courseId
                                    select new
                    {
                        SubjectId = p.tbSubject.Id,
                        SubjectName = p.tbSubject.SubjectName,
                        CourseId = p.Id,
                        CourseName = p.CourseName,
                        Hour = p.Hour,
                        Point = p.Point
                    }).FirstOrDefault();
                    vm.ElectiveApplyEdit.SubjectId = tbCourse.SubjectId;
                    //vm.CourseList = new List<SelectListItem>() {
                    //    new SelectListItem() { Text=tbCourse.CourseName,Value=tbCourse.CourseId.ConvertToString() }
                    //};
                    //vm.CourseSubject = new List<SelectListItem>() {
                    //    new SelectListItem() { Text=tbCourse.SubjectName,Value=tbCourse.SubjectId.ToString() }
                    //};
                    vm.ElectiveApplyEdit.Hour  = tbCourse.Hour;
                    vm.ElectiveApplyEdit.Point = tbCourse.Point;

                    var tbElective = (from p in db.Table <Entity.tbElective>()
                                      where p.Id == vm.ElectiveApplyEdit.ElectiveId
                                      select new
                    {
                        Id = p.Id,
                        Name = p.ElectiveName,
                        ElectiveType = p.tbElectiveType.ElectiveTypeCode
                    }).FirstOrDefault();
                    if (tbElective == null)
                    {
                        return(Code.MvcHelper.Post(new List <string>()
                        {
                            Resources.LocalizedText.MsgNotFound
                        }));
                    }
                    //vm.ElectiveList = new List<SelectListItem>() { new SelectListItem() { Value = tbElective.Id.ToString(), Text = tbElective.Name } };
                    vm.IsWeekPeriod = tbElective.ElectiveType == Code.EnumHelper.ElectiveType.WeekPeriod;
                }
                else
                {
                    //electiveId = vm.ElectiveList[0].Value.ConvertToInt();
                }

                vm.ElectiveList  = ElectiveController.SelectList();
                vm.RoomList      = Basis.Controllers.RoomController.SelectList();
                vm.CourseSubject = ElectiveSubjectController.SelectSubjectList(electiveId);
                vm.CourseList    = Course.Controllers.CourseController.SelectList(vm.ElectiveApplyEdit.SubjectId > 0 ? vm.ElectiveApplyEdit.SubjectId : vm.CourseSubject[0].Value.ConvertToInt());

                //if (vm.IsWeekPeriod)
                //{
                vm.PeriodList = Basis.Controllers.PeriodController.SelectList();
                vm.WeekList   = Basis.Controllers.WeekController.SelectList();
                //}
            }
            return(View(vm));
        }