public StudentDetailsViewModel(Student student, List <SubjectGraph> subjectGraphs)
 {
     ActualStudent = student;
     AllSubjects   = subjectGraphs.ToList();
     if (student.ActualSubject == null)
     {
         SelectedSubject = AllSubjects.First().Name;
     }
     else
     {
         SelectedSubject = student.ActualSubject.Name;
     }
 }
        private void AddSubject()
        {
            if (EditBox == "")
            {
                return;
            }
            SchoolObjContext Context = new SchoolObjContext();
            var subject = new Subject()
            {
                Name = EditBox, StandardId = SelectedStandard.StandardId, Standard = null
            };

            Context.Subjects.Add(subject);
            if (Context.SaveChanges() > 0)
            {
                //MessageBox.Show("Subject Added Successfully", "Success !", MessageBoxButton.OK, MessageBoxImage.Information);
                AllSubjects.Add(subject);
                EditBox = "";
                MainViewModel.RefreshView("Subjects");
            }
        }
        private void RemoveSubject()
        {
            if (SelectedGridItem == null)
            {
                return;
            }


            dynamic tmp = SelectedGridItem;
            int     id  = tmp.Id;

            SchoolObjContext Context = new SchoolObjContext();
            var obj = Context.Subjects.Where(s => s.Id == id).FirstOrDefault();

            Context.Subjects.Remove(obj);
            if (Context.SaveChanges() > 0)
            {
                MainViewModel.RefreshView("Subjects");
                MessageBox.Show("Subject Deleted Successfully", "Success !", MessageBoxButton.OK, MessageBoxImage.Information);
                AllSubjects.Remove(SelectedGridItem);
                EditBox = "";
            }
        }
Пример #4
0
 public static Subject GetSubjectById(int id)
 {
     return(AllSubjects.First(x => x.SubjectID == id));
 }