Example #1
0
        private void _F_DeleteStudent(StudentInfoViewModel s)
        {
            if (s == null)
            {
                return;
            }

            _StudentInfoDal.Remove(s.StudentInfo);
            var target = (from item in Relation where item.StudentId == s.ID select item).ToList();

            if (target != null || target.Count > 0)
            {
                foreach (var ritem in target)
                {
                    _RelationShipDal.Remove(ritem);
                }
                _StudentInfoDal.Save();
                StudentList.Remove(s);
            }
        }
Example #2
0
        private void _F_UpdateStudent(StudentInfoViewModel s)
        {
            var sInstance = ServiceLocator.Current.GetInstance <StudentModifyViewModel>();

            sInstance.studentInfo = s.StudentInfo;
            sInstance.Title       = "修改学生信息";
            sInstance.classInfo   = (from citem in _EFDataContext.classes
                                     from item in _EFDataContext.relations
                                     where item.StudentId == s.ID && item.ClassId == citem.ID
                                     select citem).ToList()?.FirstOrDefault();

            StudentInfoWindow studentInfoWindow = new StudentInfoWindow();

            studentInfoWindow.ShowDialog();
            if (studentInfoWindow.DialogResult == true)
            {
                _StudentInfoDal.Update(s.StudentInfo);
                var target = (from item in Relation where item.StudentId == s.ID select item).ToList();
                if (target != null && target.Count > 0)
                {
                    target[0].ClassId = sInstance.classInfo.ID;
                    _RelationShipDal.Update(target[0]);
                }
                else
                {
                    _RelationShipDal.Insert(new Student_Class_Relation()
                    {
                        StudentId = s.ID, ClassId = sInstance.classInfo.ID
                    });
                }

                _StudentInfoDal.Save();
                _RelationShipDal.Save();

                s.Update();
                //RefreshData();
                //RaisePropertyChanged("Students");
            }
        }