private void SetResearcherHandlers() { FirstNameBox.ItemsSource = unitOfWork.Researchers.GetAll() .Select(item => item.FirstName).Distinct().ToList(); MiddleNameBox.ItemsSource = unitOfWork.Researchers.GetAll() .Select(item => item.MiddleName).Distinct().ToList(); LastNameBox.ItemsSource = unitOfWork.Researchers.GetAll() .Select(item => item.LastName).Distinct().ToList(); SearchButton.Click += (object sender, RoutedEventArgs e) => { var query = unitOfWork.Researchers.Find(item => item.FirstName.Contains(FirstNameBox.Text) && item.MiddleName.Contains(MiddleNameBox.Text) && item.LastName.Contains(LastNameBox.Text)); ListBoxResearcher.ItemsSource = query.Select(item => new WebLibrary.Entities.FullResearcher(item, unitOfWork)); }; ResearcherCreateButton.Click += (object sender, RoutedEventArgs e) => { var researcher = new Researcher(); ResearcherWindow researcherWindow = new ResearcherWindow(researcher, ActionType.Create) { Owner = this }; researcherWindow.ShowDialog(); ChairUpdate(); }; }
private void SetChairHandlers() { ChairBox.ItemsSource = unitOfWork.Chairs.GetAll().ToList(); ChairBox.SelectionChanged += (object sender, SelectionChangedEventArgs args) => { var chair = ChairBox.SelectedItem as Chair; if (chair != null) { LocalChair = chair; ListBoxChairResearcher.ItemsSource = unitOfWork.Researchers .Find(item => item.ChairId == LocalChair.ChairId) .Select(item => new WebLibrary.Entities.FullResearcher(item, unitOfWork)); } }; ChairBox.SelectedIndex = 0; ChairCreateButton.Click += (object sender, RoutedEventArgs e) => { var chair = new Chair(); ChairWindow chairWindow = new ChairWindow(chair, ActionType.Create) { Owner = this }; chairWindow.ShowDialog(); ChairUpdate(); }; ChairEditButton.Click += (object sender, RoutedEventArgs e) => { var chair = ChairBox.SelectedItem as Chair; ChairWindow chairWindow = new ChairWindow(chair, ActionType.Create) { Owner = this }; chairWindow.ShowDialog(); ChairUpdate(); }; ChairDeleteButton.Click += (object sender, RoutedEventArgs e) => { var chairToDelete = ChairBox.SelectedItem as Chair; string message = "Ви впевнені що хочете видалити дані про кафедру " + chairToDelete.ChairName + " та всіх викладачів цієї кафедри?"; DialogWindow dialogWindow = new DialogWindow(message); bool? dialogResult = dialogWindow.ShowDialog(); if (dialogResult != true) { return; } unitOfWork.Chairs.Delete(chairToDelete.ChairId); unitOfWork.Save(); ChairUpdate(); }; ResearcherChairCreateButton.Click += (object sender, RoutedEventArgs e) => { var researcher = new Researcher(); researcher.Chair = ChairBox.SelectedItem as Chair; ResearcherWindow researcherWindow = new ResearcherWindow(researcher, ActionType.Create) { Owner = this }; researcherWindow.ShowDialog(); ChairUpdate(); }; }