void UpdateSubjects() { using (_ujc = new UniversityEntities()) { _subjects = (from subj in _ujc.University_Subject select subj).ToList(); RaisePropertyChanged("Subjects"); } }
private void DeleteStudentFromDB(University_Student obj) { _ujc = new UniversityEntities(); var removestud = _ujc.University_Student.Single((s) => s.Student_ID == SelectedStudent.Student_ID); _ujc.University_Student.Remove(removestud); _ujc.SaveChanges(); UpdateStudentsList(); }
private void UpdateStudent(object parameter) { using (_ujc = new UniversityEntities()) { //try { University_Student tmp = _ujc.University_Student.Single((st) => st.Student_ID == SelectedStudent.Student_ID); tmp.First_Name = StudentName; tmp.Last_Name = StudentLastName; tmp.Birthday = StudentBirthdate; tmp.Email = StudentEmail; if (StudentPhoto!=null) { tmp.Photo = ImageToByte(StudentPhoto); } else tmp.Photo = ImageToByte(new BitmapImage(new Uri(@"G:\Универ\GoogleDrive_oldan\Bionic Final Project\UniversityJournal\UniversityJournal\bin\Debug\no_img.jpg"))); _ujc.SaveChanges(); UpdateStudentsList(); CloseCommand(); } //catch { } } }
void GetCurrentSubjects(University_Group obj) { if (obj != null) { using (_ujc = new UniversityEntities()) { var _teach = _ujc.University_Group.Where(s => s.Group_ID == obj.Group_ID).FirstOrDefault(); CurrentSubjects = new ObservableCollection<University_Subject>(_teach.University_Subject.ToList()); } } }
void GetCurrentStudents(University_Group obj) { if (obj!=null) { using (_ujc = new UniversityEntities()) { var _studs = _ujc.University_Group.Where(gr => gr.Group_ID == obj.Group_ID).FirstOrDefault(); Students = new ObservableCollection<University_Student>(_studs.University_Student.ToList()); } } }
private void AddSubjectFromList(University_Subject obj) { using (_ujc = new UniversityEntities()) { var currsubj = _ujc.University_Subject.Where(s => s.Subject_ID == obj.Subject_ID).FirstOrDefault(); var currgroup = _ujc.University_Group.Where(t => t.Group_ID == SelectedGroup.Group_ID).FirstOrDefault(); currgroup.University_Subject.Add(currsubj); _ujc.SaveChanges(); GetCurrentSubjects(SelectedGroup); GetAllSubjects(); } }
private void RemoveStudentFromGroup(University_Student obj) { using (_ujc = new UniversityEntities()) { var currstud = _ujc.University_Student.Where(s => s.Student_ID == obj.Student_ID).FirstOrDefault(); var currgroup = _ujc.University_Group.Where(t => t.Group_ID == SelectedGroup.Group_ID).FirstOrDefault(); currgroup.University_Student.Remove(currstud); _ujc.SaveChanges(); GetAllStudents(); GetCurrentStudents(SelectedGroup); } }
private void UpdateSchedule() { using (_ujc=new UniversityEntities()) { UpdateDaySchedule("Monday", ref _mondayLessons); UpdateDaySchedule("Tuesday", ref _tuesdayLessons); UpdateDaySchedule("Wednesday", ref _wednesdayLessons); UpdateDaySchedule("Thursday", ref _thursdayLessons); UpdateDaySchedule("Friday", ref _fridayLessons); RaisePropertyChanged("MondayLessons"); RaisePropertyChanged("TuesdayLessons"); RaisePropertyChanged("WednesdayLessons"); RaisePropertyChanged("ThursdayLessons"); RaisePropertyChanged("FridayLessons"); } }
public void Refresh() { FilterList = new ObservableCollection<University_Group>(); FilterList.Add(new University_Group() { Group_Name = "ALL", Group_ID = 65536 }); using (_ujc = new UniversityEntities()) { foreach (var gr in _ujc.University_Group.Select(s => s).ToList()) { FilterList.Add(gr); } SelectedFilter = FilterList[0]; } UpdateSchedule(); }
private void DeleteLessonFromSchedule(Schedule parameter) { using (_ujc = new UniversityEntities()) { var _delLes = _ujc.University_Schedule.Where(s => s.Lesson_ID == parameter.Lesson_ID).FirstOrDefault(); _ujc.University_Schedule.Remove(_delLes); _ujc.SaveChanges(); } UpdateSchedule(); }
private void AddLessonToSchedule(object parameter) { using (_ujc = new UniversityEntities()) { var _newLes = new University_Schedule(); _newLes.Day_of_week = SelectedDay; _newLes.LessonNo = SelectedLessonNo; _newLes.Group_ID = SelectedGroup.Group_ID; _newLes.Subject_ID = SelectedSubject.Subject_ID; _newLes.Teacher_ID = SelectedTeacher.Teacher_ID; _ujc.University_Schedule.Add(_newLes); _ujc.SaveChanges(); } SelectedLessonNo = 0; RaisePropertyChanged("SelecteLessonNo"); SelectedDay = null; OnSelectedLessonNo(); UpdateSchedule(); }
private void OnSelectedSubject() { if (!string.IsNullOrEmpty(SelectedDay) && SelectedLessonNo > 0 && SelectedLessonNo < 5 && SelectedGroup != null&& SelectedSubject!=null) { using (_ujc = new UniversityEntities()) { var _ss = _ujc.University_Subject.Where(s => s.Subject_ID == SelectedSubject.Subject_ID).FirstOrDefault(); var _exclTchrID = _ujc.University_Schedule .Where(s=>s.Day_of_week==SelectedDay) .Where(s=>s.LessonNo==SelectedLessonNo) .Select(s => s.Teacher_ID); var _possTchrID = _ss.University_Teacher.Select(s => s.Teacher_ID); var _availTchrID = _possTchrID.Except(_exclTchrID); Teachers = new ObservableCollection<University_Teacher>(); foreach (var id in _availTchrID) { Teachers.Add(_ujc.University_Teacher.Where(tch => tch.Teacher_ID == id).FirstOrDefault()); } } } }
private void OnSelectedGroup() { if (!string.IsNullOrEmpty(SelectedDay) && SelectedLessonNo > 0 && SelectedLessonNo < 5 && SelectedGroup != null) { using (_ujc = new UniversityEntities()) { var _selgr = _ujc.University_Group .Where(s => s.Group_ID == SelectedGroup.Group_ID).FirstOrDefault(); var _subjs = _selgr.University_Subject.ToList(); GroupSubjects = new ObservableCollection<University_Subject>(_subjs); } } }
private void OnSelectedLessonNo() { if (!string.IsNullOrEmpty(SelectedDay)&&SelectedLessonNo>0&&SelectedLessonNo<5) { using (_ujc = new UniversityEntities()) { AvailableGroups = new ObservableCollection<University_Group>(); var _exclgrID = _ujc.University_Schedule .Where(s=>s.Day_of_week.Equals(SelectedDay)) .Where(s=>s.LessonNo==SelectedLessonNo) .Select(s=>s.Group_ID); var _allgrID = _ujc.University_Group .Select(s=>s.Group_ID); var _availgrID = _allgrID.Except(_exclgrID); foreach (var id in _availgrID) { AvailableGroups.Add(_ujc.University_Group.Where(gr => gr.Group_ID == id).FirstOrDefault()); } } } }
private void EditGroupFromDB(University_Group obj) { try { using (_ujc = new UniversityEntities()) { var _group = _ujc.University_Group.Where(s => s.Group_ID == obj.Group_ID).FirstOrDefault(); _group.Group_Name = GroupNameEdit; _ujc.SaveChanges(); } } catch { } finally { RefreshIt(); } }
private void SaveNewTeacherToDB(object obj) { try { using (_ujc = new UniversityEntities()) { University_Teacher _teach = new University_Teacher(); _teach.First_Name = Tname; _teach.Last_Name = Tlname; _teach.Birthday = Tbdate; _teach.Email = Temail; if (Tphoto != null) { _teach.Photo = ImageToByte(Tphoto); } _teach.Login = Tlogin; _teach.Password = Tpwd; _ujc.University_Teacher.Add(_teach); _ujc.SaveChanges(); } } catch { } finally { EditEnabled = false; AddButtonName = "Add New..."; _addNewTeacher = new Command<object>(AddNewTeacherToDB); RaisePropertyChanged("AddNewTeacher"); BlockGrid = true; RefreshIt(); } }
private void AddNewGroupToDB(string obj) { try { using (_ujc = new UniversityEntities()) { University_Group _group = new University_Group(); _group.Group_Name = obj; _ujc.University_Group.Add(_group); _ujc.SaveChanges(); } } catch { } finally { RefreshIt(); } }
private void SaveEditedTeacherToDB(University_Teacher obj) { try { using (_ujc = new UniversityEntities()) { var _teach = _ujc.University_Teacher.Where(s => s.Teacher_ID == SelectedTeacher.Teacher_ID).Single(); _teach.First_Name = Tname; _teach.Last_Name = Tlname; _teach.Birthday = Tbdate; _teach.Email = Temail; if (Tphoto != null) { _teach.Photo = ImageToByte(Tphoto); } _teach.Login = Tlogin; _teach.Password = Tpwd; _ujc.SaveChanges(); } } finally { EditEnabled = false; EditButtonName = "Edit"; _editTeacher = new Command<University_Teacher>(EditTeacherFromDB, (S) => SelectedTeacher != null); RaisePropertyChanged("EditTeacher"); AllowAddButton = true; BlockGrid = true; RefreshIt(); } }
private void AddStudentToGroup (University_Student parameter) { using (_ujc = new UniversityEntities()) { var _selstud = _ujc.University_Student.Where(s=>s.Student_ID == parameter.Student_ID).FirstOrDefault(); var _group = _ujc.University_Group.Where(gr => gr.Group_ID == SelectedGroup.Group_ID).FirstOrDefault(); _group.University_Student.Add(_selstud); _ujc.SaveChanges(); } GetAllStudents(); GetCurrentStudents(SelectedGroup); }
private void DeleteTeacherFromDB(University_Teacher obj) { try { using (_ujc = new UniversityEntities()) { var _teach = _ujc.University_Teacher.Where(s => s.Teacher_ID == obj.Teacher_ID).FirstOrDefault(); _ujc.University_Teacher.Remove(_teach); _ujc.SaveChanges(); } } finally { RefreshIt(); } }
private void UpdateGroupList() { using (_ujc = new UniversityEntities()) { var tmp = (from gr in _ujc.University_Group select gr).ToList(); _groups = new ObservableCollection<University_Group>(tmp); RaisePropertyChanged("Groups"); } }
private void RemoveSubjectFromList(University_Subject obj) { using (_ujc = new UniversityEntities()) { var currsubj = _ujc.University_Subject.Where(s => s.Subject_ID == obj.Subject_ID).FirstOrDefault(); var currteach = _ujc.University_Teacher.Where(t => t.Teacher_ID == SelectedTeacher.Teacher_ID).FirstOrDefault(); currteach.University_Subject.Remove(currsubj); _ujc.SaveChanges(); GetCurrentSubjects(SelectedTeacher); GetAllSubjects(); } }
void GetAllSubjects() { using (_ujc = new UniversityEntities()) { if (CurrentSubjects != null && SelectedGroup != null) { var tmpData = _ujc.University_Subject.ToList(); var teach = _ujc.University_Group.Where(e => e.Group_ID == SelectedGroup.Group_ID).FirstOrDefault(); var exclData = teach.University_Subject.ToList(); var res = tmpData.Except(exclData).ToList(); AllSubjects = new ObservableCollection<University_Subject>(res); } } }
void UpdateTeachersList() { using (_ujc = new UniversityEntities()) { _teachers = (from teac in _ujc.University_Teacher select teac).ToList(); RaisePropertyChanged("Teachers"); } }
private void GetAllStudents() { AllAvailableStudents = new ObservableCollection<University_Student>(); using(_ujc = new UniversityEntities()) { var _allStuds = _ujc.University_Student.Select(s => s); foreach(var stud in _allStuds) { if (stud.University_Group.Count==0) { AllAvailableStudents.Add(stud); } } } }
//CONSTRUCTOR public GroupVM() { _deleteGroup = new Command<University_Group>(DeleteGroupFromDB, s => s != null); _editGroup = new Command<University_Group>(EditGroupFromDB, s => s != null && !string.IsNullOrWhiteSpace(GroupNameEdit)); _addNewGroup = new Command<string>(AddNewGroupToDB, s => { if (!string.IsNullOrWhiteSpace(s)) using(_ujc=new UniversityEntities()) { var cnt=_ujc.University_Group.Where(gr => gr.Group_Name == s).ToList().Count; return !(cnt > 0); } return false; }); _addSubject = new Command<University_Subject>(AddSubjectFromList, s => SelectedGroup != null && s != null ); _removeSubject = new Command<University_Subject>(RemoveSubjectFromList, s => SelectedGroup != null && s != null); _addStudents = new Command<University_Student>(AddStudentToGroup, s => SelectedGroup != null && s != null); _removeStudents = new Command<University_Student>(RemoveStudentFromGroup, s => SelectedGroup != null && s != null); RefreshIt(); }
void UpdateStudentsList() { using (_ujc = new UniversityEntities()) { if (!string.IsNullOrEmpty(SearchString)) { _students = new List<University_Student>(); Regex _sp = new Regex(SearchString+"{1}",RegexOptions.IgnoreCase); var _tmp = _ujc.University_Student.Select(s => s); foreach (var it in _tmp) { if (_sp.IsMatch(it.Last_Name)||_sp.IsMatch(it.First_Name)) { _students.Add(it); } } } else { //_students = new List<University_Student>(); _students = _ujc.University_Student // .Where(s => s.Last_Name.Contains(SearchString)) .Select(s => s) .ToList(); } //_students.AddRange( // _ujc.University_Student // .Where(s => s.First_Name.Contains(SearchString)) // .ToList() // ); //(from stud in _ujc.University_Student // select stud).ToList(); RaisePropertyChanged("Students"); } }
//Command Methods private void DeleteGroupFromDB(University_Group obj) { try { using (_ujc = new UniversityEntities()) { var _group = _ujc.University_Group.Where(s => s.Group_ID == obj.Group_ID).FirstOrDefault(); _ujc.University_Group.Remove(_group); _ujc.SaveChanges(); } } finally { RefreshIt(); } }
private void AddStudent(object parameter) { using (_ujc = new UniversityEntities()) { try { University_Student tmp = new University_Student(); tmp.First_Name = StudentName; tmp.Last_Name = StudentLastName; tmp.Birthday = StudentBirthdate; tmp.Email = StudentEmail; if (StudentPhoto == null) tmp.Photo = null; else tmp.Photo = ImageToByte(StudentPhoto); _ujc.University_Student.Add(tmp); _ujc.SaveChanges(); UpdateStudentsList(); CloseCommand(); } catch { } } }
private void EditSubjectFromDB(University_Subject obj) { using (_ujc = new UniversityEntities()) { var subj = _ujc.University_Subject.Where(s => s.Subject_ID == obj.Subject_ID).FirstOrDefault(); if (subj != null) { subj.Subject_Name = CurrentSubject; _ujc.SaveChanges(); } UpdateSubjects(); } }