/// 学生按班级id选择班级.成功返回选课记录id 失败返回0 public long InsertCourseSelectionById(long userId, long classId) { try { //_userService.GetUserByUserId(userId); ClassInfo classinfo = GetClassByClassId(classId); //找到该班级所属课程下的所有班级 IList <ClassInfo> classList = ListClassByCourseId(classinfo.Course.Id); foreach (ClassInfo c in classList) { if (_classDao.GetSelection(userId, c.Id) != 0)//学生已选同课程下其他班级 { return(0); } } CourseSelection coursesele = new CourseSelection(); UserInfo student = _userService.GetUserByUserId(userId); coursesele.Student = student; coursesele.ClassInfo = classinfo; return(_classDao.InsertSelection(coursesele)); } catch (UserNotFoundException eu) { throw eu; } catch (ClassNotFoundException ec) { throw ec; } }
public async Task <ActionResult> Default(CourseSelection courseSelection) { Application application = await _applicationService.GetCurrentApplication(_ctx); if (ModelState.IsValid) { courseSelection.Application = application; CourseSelection currentSelection = await _applicationService.GetCourses(_ctx); if (currentSelection != null) { courseSelection.Id = currentSelection.Id; } _ctx.CourseSelections.AddOrUpdate(c => c.Id, courseSelection); await _ctx.SaveChangesAsync(); return(RedirectToAction("Manage", "Applications")); } SetupViewbag(); return(View(courseSelection)); }
public async Task CreateGame(InitiateDots newGame) { AddNewGroup(newGame.PlayerName, newGame.GolfRoundType, newGame.NineType); Game.Name = newGame.GameName.Trim(); Game.Password = newGame.Password; Game.DotTypes = newGame.DotTypes; Game.GolfRoundType = newGame.GolfRoundType; Game.NineType = newGame.NineType; if (!string.IsNullOrWhiteSpace(newGame.CourseName)) { Game.Groups.ForEach(g => g.CourseName = newGame.CourseName); if (string.IsNullOrWhiteSpace(newGame.CourseTeeBox)) { var course = CourseSelection.SelectCourse(newGame.CourseName); newGame.CourseTeeBox = course.CourseHoles.First().Tees.First().Color; } Game.Groups.ForEach(g => g.CourseTeeBox = newGame.CourseTeeBox); } await Save(); }
public async Task <IActionResult> Create([Bind("StudentID,CourseID,Paid,Active")] CourseSelection courseSelection) { if (ModelState.IsValid) { // Define an object of CourseSelectionOwing and set the details CourseSelectionOwing courseSelectionOwing = new CourseSelectionOwing(); courseSelectionOwing.StudentID = courseSelection.StudentID; courseSelectionOwing.CourseID = courseSelection.CourseID; courseSelectionOwing.Active = true; var course = await _context.Courses.FindAsync(courseSelection.CourseID); if (course == null) { courseSelectionOwing.Owing = 0; } else { courseSelectionOwing.Owing = course.Cost; } // Add entry for course selection _context.Add(courseSelection); // Add entry for course selection owing _context.Add(courseSelectionOwing); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Create), courseSelection.StudentID)); } if (courseSelection.StudentID == 0) { return(NotFound()); } var student = await GetStudentWithCourseSelections(courseSelection.StudentID); if (student == null) { return(NotFound()); } var allCourses = await _context.Courses.Where(m => m.Active == true).ToListAsync(); var availableCourses = new List <Course>(); // Get available courses for enrollment foreach (var course in allCourses) { if (!student.CourseSelections.Any(m => (m.CourseID == course.CourseID && m.Active))) { availableCourses.Add(course); } } ViewData["CourseID"] = new SelectList(availableCourses, "CourseID", "CourseName"); return(View(new CourseSelection { Student = student })); }
/// 学生按班级id选择班级.成功返回选课记录id 失败返回0 public async Task <long> InsertCourseSelectionByIdAsync(long userId, long classId) { //_userService.GetUserByUserIdAsync(userId); var classinfo = await GetClassByClassIdAsync(classId); //找到该班级所属课程下的所有班级 var classList = await ListClassByCourseIdAsync(classinfo.Course.Id); foreach (var c in classList) { if (_classDao.GetSelection(userId, c.Id) != 0) //学生已选同课程下其他班级 { return(0); } } var coursesele = new CourseSelection(); var student = await _userService.GetUserByUserIdAsync(userId); coursesele.Student = student; coursesele.ClassInfo = classinfo; return(_classDao.InsertSelection(coursesele)); }
//根据班级id/学生id删除学生选课表 public void DeleteSelection(long userId, long classId) { if (userId != 0)//单个学生取消选课 { using (var scope = _db.Database.BeginTransaction()) { try { CourseSelection c = _db.CourseSelection.SingleOrDefault <CourseSelection>(u => u.Student.Id == userId && u.ClassInfo.Id == classId); _db.CourseSelection.Attach(c); _db.CourseSelection.Remove(c); _db.SaveChanges(); scope.Commit(); } catch { scope.Rollback(); } } } else //删除班级时 批量删除 { List <CourseSelection> t1 = _db.CourseSelection.Where(t => t.ClassInfo.Id == classId).ToList <CourseSelection>(); foreach (CourseSelection t in t1) { _db.CourseSelection.Remove(t); } _db.SaveChanges(); } }
public IActionResult UpdateDesiredCourses(CourseSelection model) { if (ModelState.IsValid) { foreach (var item in model.DesiredCourses) { if (context.DesiredCourses .Where(i => i.InstructorID == item.InstructorID) != null) { if (!context.DesiredCourses .Where(i => i.InstructorID == item.InstructorID) .Select(c => c.CourseID) .Contains(item.CourseID)) { if (item.IsDesired) { desiredCourseRepository.SaveDesiredCourse(item); } } else { if (!item.IsDesired) { desiredCourseRepository.DeleteCourse(context.DesiredCourses .FirstOrDefault(i => (i.CourseID == item.CourseID) && (i.InstructorID == item.InstructorID)) .DesiredCourseID); } } } } } return(RedirectToAction("Index")); }
public async Task <ViewResult> SelectCourses() { var user = await userManager.GetUserAsync(User); var department = context.Departments.FirstOrDefault(d => d.DepartmentCode == user.Department); CourseSelection courseSelection = new CourseSelection { Courses = context.Courses.Where(c => c.DepartmentID == department.DepartmentID), DesiredCourses = new List <DesiredCourse>() }; foreach (var c in courseSelection.Courses) { if (context.DesiredCourses.FirstOrDefault(d => (d.CourseID == c.CourseID) && (d.InstructorID == user.Id)) != null) { courseSelection.DesiredCourses.Add( new DesiredCourse { CourseID = c.CourseID, IsDesired = true, InstructorID = user.Id }); } else { courseSelection.DesiredCourses.Add( new DesiredCourse { CourseID = c.CourseID, IsDesired = false, InstructorID = user.Id }); } } return(View(courseSelection)); }
public int createCourseSelectRecording(CourseSelection courseSelection) { using (var context = new HaermsEntities()) { CourseSelection cs = context.CourseSelection.Add((CourseSelection)courseSelection); context.SaveChanges(); return(cs.CourseSelectionId); } }
//查询学生选课表的记录 public int GetSelection(long userId, long classId) { CourseSelection courseSelection = _db.CourseSelection.Where(u => u.ClassInfo.Id == classId && u.Student.Id == userId).SingleOrDefault <CourseSelection>(); if (courseSelection != null) { return(1); //找到记录 } return(0); }
public async Task <ActionResult> Default(int?id) { CourseSelection courseSelection = await _applicationService.GetCourses(_ctx) ?? new CourseSelection(); courseSelection = await TryPreseletCourse(courseSelection); SetupViewbag(); return(View(courseSelection)); }
public async Task <IActionResult> Pay(int id, [Bind("ID,StudentID,CourseID,Paid,Active")] CourseSelection courseSelection) { if (id != courseSelection.ID) { return(NotFound()); } // Get the object of CourseSelection to be updated var courseSelectionToBeUpdated = await _context.CourseSelections.FindAsync(id); // Get the object of CourseSelectionOwing to be updated var courseSelectionOwingToBeUpdated = _context.CourseSelectionOwings.FirstOrDefault(m => m.CourseID == courseSelection.CourseID && m.StudentID == courseSelection.StudentID && m.Active == true); if (ModelState.IsValid) { courseSelectionToBeUpdated.Paid += courseSelection.Paid; courseSelectionOwingToBeUpdated.Owing -= courseSelection.Paid; try { // Update the entry of course selection _context.Update(courseSelectionToBeUpdated); // Update the entry of course selection owing _context.Update(courseSelectionOwingToBeUpdated); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseSelectionExists(courseSelection.ID)) { return(NotFound()); } else { throw; } } } var student = await GetStudentWithCourseSelections(courseSelectionToBeUpdated.StudentID); if (student == null) { return(NotFound()); } return(View(new CourseSelection { Student = student })); }
public IActionResult UpdateDesiredCourses(CourseSelection model) { if (ModelState.IsValid) { try { foreach (var item in model.DesiredCourses) { desiredCourseRepository.SaveDesiredCourse(item); } } catch { } } return(RedirectToAction("Index")); }
private async Task <CourseSelection> TryPreseletCourse(CourseSelection courseSelection) { // Pre-select the users first choice course based on the course they chose to apply for. if (courseSelection.FirstChoice == 0 && Session["CourseId"] != null) { string courseCode = (string)Session["CourseId"]; Course course = await _ctx.Courses.FirstOrDefaultAsync(c => c.Code == courseCode); if (course != null) { courseSelection.FirstChoice = course.Id; } } return(courseSelection); }
//添加学生选课表返回id public long InsertSelection(CourseSelection t) { using (var scope = _db.Database.BeginTransaction()) { try { _db.CourseSelection.Add(t); _db.SaveChanges(); scope.Commit(); return(t.Id); } catch { scope.Rollback(); throw; } } }
public void LoadTest() { string classnumber = "201925665"; CourseSelection course = new CourseSelection(); course.GetCourse(); Console.WriteLine("test"); string temp = ""; temp = course.CourseInfo.Items[0].ToString(); temp = System.Text.RegularExpressions.Regex.Replace(temp, @"[^0-9]+", ""); Console.WriteLine(temp); if (temp != classnumber) { Assert.Fail(); } }
public static void Initialize(AccountingContext context) { context.Database.EnsureCreated(); // Look for any students if (context.Students.Any()) { return; // DB has been seeded } var students = new Student[] { new Student { Name = "Guobin Li", Age = 31, Active = true }, new Student { Name = "John", Age = 32, Active = true }, new Student { Name = "Alex", Age = 18, Active = true }, }; foreach (Student s in students) { context.Students.Add(s); } context.SaveChanges(); var courses = new Course[] { new Course { CourseName = "Math", Cost = 1000.00, Active = true }, new Course { CourseName = "Internet and Website Design", Cost = 860.00, Active = true }, new Course { CourseName = "Web Application Development", Cost = 1000.00, Active = true }, new Course { CourseName = "Database Design and Development", Cost = 1200.00, Active = true }, new Course { CourseName = "Advanced Program Development", Cost = 1400.00, Active = true }, new Course { CourseName = "Network Programming", Cost = 1600.00, Active = true }, }; foreach (Course c in courses) { context.Courses.Add(c); } context.SaveChanges(); var courseSelections = new CourseSelection[] { new CourseSelection { StudentID = 1, CourseID = 2, Paid = 860.00, Active = true }, new CourseSelection { StudentID = 1, CourseID = 3, Paid = 1000.00, Active = true }, new CourseSelection { StudentID = 1, CourseID = 4, Paid = 1200.00, Active = true }, new CourseSelection { StudentID = 1, CourseID = 5, Paid = 1400.00, Active = true }, new CourseSelection { StudentID = 1, CourseID = 6, Paid = 1600.00, Active = true }, new CourseSelection { StudentID = 2, CourseID = 1, Paid = 800.00, Active = true }, new CourseSelection { StudentID = 2, CourseID = 2, Paid = 860.00, Active = true }, new CourseSelection { StudentID = 3, CourseID = 3, Paid = 0.00, Active = true }, new CourseSelection { StudentID = 3, CourseID = 5, Paid = 0.00, Active = true }, new CourseSelection { StudentID = 3, CourseID = 4, Paid = 1500.00, Active = true }, }; foreach (CourseSelection c in courseSelections) { context.CourseSelections.Add(c); } context.SaveChanges(); var courseSelectionOwings = new CourseSelectionOwing[] { new CourseSelectionOwing { StudentID = 1, CourseID = 2, Owing = 0, Active = true }, new CourseSelectionOwing { StudentID = 1, CourseID = 3, Owing = 0, Active = true }, new CourseSelectionOwing { StudentID = 1, CourseID = 4, Owing = 0, Active = true }, new CourseSelectionOwing { StudentID = 1, CourseID = 5, Owing = 0, Active = true }, new CourseSelectionOwing { StudentID = 1, CourseID = 6, Owing = 0, Active = true }, new CourseSelectionOwing { StudentID = 2, CourseID = 1, Owing = 200.00, Active = true }, new CourseSelectionOwing { StudentID = 2, CourseID = 2, Owing = 0, Active = true }, new CourseSelectionOwing { StudentID = 3, CourseID = 5, Owing = 1400.00, Active = true }, new CourseSelectionOwing { StudentID = 3, CourseID = 3, Owing = 1000.00, Active = true }, new CourseSelectionOwing { StudentID = 3, CourseID = 4, Owing = -300.00, Active = true }, }; foreach (CourseSelectionOwing c in courseSelectionOwings) { context.CourseSelectionOwings.Add(c); } context.SaveChanges(); }
public int CreateCourseSelectRecording(CourseSelection courseSelection) { return(_courseSelectionDal.createCourseSelectRecording(courseSelection)); }