/// <summary>
 /// Выполняет сохранение списка студентов в базу данных
 /// </summary>
 protected void SaveStudents()
 {
     try
     {
         foreach (StudentViewModel student in StudentsList)
         {
             context.Students.Add(new Student
             {
                 StudentId   = 0,
                 Name        = student.Name,
                 Phone       = student.Phone,
                 Description = student.Description,
                 Group       = context.Groups.Where(p => p.GroupName == student.GroupName).FirstOrDefault()
             });
         }
         context.SaveChanges();
         StudentsList.Clear();
         OnPropertyChanged(nameof(StudentsList));
         FileName     = string.Empty;
         ErrorMessage = string.Empty;
     }
     catch (Exception)
     {
         ErrorMessage = "Произошла ошибка при сохранении.";
     }
 }
        private void Deportaments_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            var txt = SearchText.Text.Trim();

            if (String.IsNullOrEmpty(txt))
            {
                //отобразить список полностью
                StudentsList.Clear();
                _tempStudents.ToList().ForEach(StudentsList.Add);
                return;
            }

            var list = StudentsList.Where(s => s.LastName.StartsWith(txt)).ToList();

            StudentsList.Clear();
            list.ForEach(StudentsList.Add);
        }
Ejemplo n.º 3
0
        public override void RefreshData()
        {
            var currentSchool     = GetCurrentSchool();
            var students          = MembersRealm.GetAll(x => x.School == currentSchool).ToList();
            var studentsContainer = new List <ViewModels.Controls.PrettyListViewItems.Student>();

            var currentProfile = GetCurrentUser().Profile;
            var currentMember  = MembersRealm.Get(x => x.Profile == currentProfile);

            students.Remove(currentMember);

            foreach (var studentsModel in students)
            {
                studentsContainer.Add(new ViewModels.Controls.PrettyListViewItems.Student(studentsModel.Profile));
            }
            StudentsList.Clear();
            StudentsList.AddRange(studentsContainer);
        }