public void UpdateStudents(Student[] students) { using (ClassAdministrationEntityContext context = new ClassAdministrationEntityContext(BUTEClassAdministrationService.Properties.Resources.connectionString)) { foreach (var student in students) { context.StudentSet.ApplyChanges(student); } context.SaveChanges(); } }
public StudentViewModel(Semester selectedSemester, Course selectedCourse) { modify = false; _student = new Student(); Name = ""; Neptun = ""; Semester = selectedSemester; Course = selectedCourse; insertStudentWindow = new InsertStudentWindow(); insertStudentWindow.DataContext = this; insertStudentWindow.ShowDialog(); }
public void CreateStudents(Student[] students) { using (ClassAdministrationEntityContext context = new ClassAdministrationEntityContext(BUTEClassAdministrationService.Properties.Resources.connectionString)) { foreach (var student in students) { // skip duplicates if (context.StudentSet.Where(Student => Student.Neptun == student.Neptun).Any()) { continue; }; context.StudentSet.ApplyChanges(student); } context.SaveChanges(); } }
public StudentViewModel(Student selectedStudent, Semester selectedSemester, Course selectedCourse) { modify = true; ModifyableStudent = selectedStudent; _student = new Student(); _student.clone(selectedStudent); Semester = selectedSemester; Course = selectedCourse; insertStudentWindow = new InsertStudentWindow(); insertStudentWindow.DataContext = this; insertStudentWindow.ShowDialog(); }
public static IEnumerable<Student> ImportFromExcel(string filename, Semester semester) { const String nameColumnName = "név"; const String neptunColumnName = "neptun kód"; int? nameColumnIndex = null; int? neptunColumnIndex = null; // open an Excel application Excel.Application excelApp = new Excel.Application(); excelApp.Visible = false; // open the workbook in read-only mode Excel.Workbook workbook = excelApp.Workbooks.Open(filename, Type.Missing, true); Excel.Worksheet worksheet = excelApp.ActiveSheet; Excel.Range usedRange = worksheet.UsedRange; // scan through the first row to get the column indices for (int j = 1; j <= worksheet.UsedRange.Columns.Count; j++) { Excel.Range cell = usedRange.Cells[1, j]; if (cell.Value != null) { String cellValue = cell.Value.ToString(); if (cellValue.ToLower() == nameColumnName.ToLower()) { nameColumnIndex = j; } if (cellValue.ToLower() == neptunColumnName.ToLower()) { neptunColumnIndex = j; } } } // throw exception if a required a column does not exist if (nameColumnIndex == null || neptunColumnIndex == null) { throw new BUTEClassAdministrationException("Nem találhatók a szükséges oszlopok."); } // use List as an IEnumerable implementation List<Student> students = new List<Student>(); // scan through the rows from the second row // instantiate new student entities for (int i = 2; i <= usedRange.Rows.Count; i++) { string name = usedRange.Cells[i, nameColumnIndex].Value.ToString(); string neptun = usedRange.Cells[i, neptunColumnIndex].Value.ToString(); Student student = new Student(); student.Name = name; student.Neptun = neptun; student.Semester = semester; students.Add(student); } excelApp.Quit(); return students; }
public void clone(Student source) { this.Name = source.Name; this.Neptun = source.Neptun; }