//public SelectList InstructorsSelectList { get; set; } //the MultiSelectList is so uggly;syncfusion.com is beautyful but expensive // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { //codes below is for keeping the value unchanged when validation failed //when submit failed because of validation failed & binding mechanism, the instructors[i].name turn to Null, why ? //now it's InstructorsSelectList turn to Null VwCourse.InstructorsSelectList = new SelectList((await _StaffManager.GetAllAsync()).ToList(), nameof(Staff.Id), nameof(Staff.Name)); return(Page()); } //if (await TryUpdateModelAsync<Student>( //var instructorCourses = new HashSet<int>(instructor.CourseAssignments.Select(c => c.CourseID)); //_context.VwCourse.Add(VwCourse); //await _context.SaveChangesAsync(); //todo add the relative data such as courseAssigenment, enrollment // 明确的remove // VwCourse 不太需要,字段的组合,可以直接在pagemodel中实现,需要采用“bindproperty” // tenantId 有问题 // 很多命名一致性问题,ID/Id,等等 var course = new Course { Name = VwCourse.Name, IsCyclic = VwCourse.IsCyclic, StartTime = new DateTime(VwCourse.Date.Year, VwCourse.Date.Month, VwCourse.Date.Day, VwCourse.StartTime.Hour, VwCourse.StartTime.Minute, 0), EndTime = new DateTime(VwCourse.Date.Year, VwCourse.Date.Month, VwCourse.Date.Day, VwCourse.EndTime.Hour, VwCourse.EndTime.Minute, 0) }; course.CourseAssignments = new List <CourseAssignment>(); //todo should validation the multiple selected first, if no item selected //Checkboxes in a Razor Pages Form : https://www.learnrazorpages.com/razor-pages/forms/checkboxes //foreach (var instr in VwCourse.Instructors) //{ // if (instr.Checked) // { // var cor = new CourseAssignment { StaffId = instr.Id, CourseId = VwCourse.id }; // course.CourseAssignments.Add(cor); // } //} foreach (var i in VwCourse.InstructorsIdList) { var cor = new CourseAssignment { StaffId = i, CourseId = VwCourse.id }; course.CourseAssignments.Add(cor); } await _CourseManager.AddAsync(course); //Instructors.SelectMany<> return(RedirectToPage("./Index")); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } Course.TanentId = userManager.TenantId;//todo not sure this is ready //固定课、临时课(一次性课时),均保存课程设定,对于固定课,还需进行“重复” DateTime StartDate = DateTime.Now;//todo 按照实际业务完善 Course.StartTime = new DateTime(StartDate.Year, StartDate.Month, StartDate.Day, Course.StartTime.Hour, Course.StartTime.Minute, 0); Course.EndTime = new DateTime(StartDate.Year, StartDate.Month, StartDate.Day, Course.EndTime.Hour, Course.EndTime.Minute, 0); //todo core TempData for what???? //_context.Course.Add(Course); //await _context.SaveChangesAsync(); await _CourseMgr.AddAsync(Course); return(RedirectToPage("./Index")); }