using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace AutoservisDrive.Pages { /// /// Логика взаимодействия для ServicePage.xaml /// public partial class ServicePage : Page { public ServicePage() { InitializeComponent(); if (App.CurrentUser.RoleId ==1) { BtnAddService.Visibility = Visibility.Visible; } else { BtnAddService.Visibility= Visibility.Collapsed; } ComboDiscount.SelectedIndex = 0; ComboSortBy.SelectedIndex = 0; UpdateServices(); LViewServices.ItemsSource = App.Context.Services.ToList(); } private void BtnAddService_Click(object sender, RoutedEventArgs e) { NavigationService.Navigate(new AddEditPage()); } private void BtnEdit_Click(object sender, RoutedEventArgs e) { var currentService = (sender as Button).DataContext as Entities.Service; NavigationService.Navigate(new AddEditPage(currentService)); } private void BtnDelete_Click(object sender, RoutedEventArgs e) { var currentService = (sender as Button).DataContext as Entities.Service; if (MessageBox.Show($"Вы уверены, что хотите удалить услугу: " + $"{currentService.Title}?", "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { App.Context.Services.Remove(currentService); App.Context.SaveChanges(); UpdateServices(); } } private void ComboDiscount_SelectionChanged(object sender, SelectionChangedEventArgs e) { UpdateServices(); } private void ComboSortBy_SelectionChanged(object sender, SelectionChangedEventArgs e) { UpdateServices(); } private void TBoxSearch_TextChanged(object sender, TextChangedEventArgs e) { UpdateServices(); } private void UpdateServices() { var services = App.Context.Services.ToList(); //Сортировка по цене if (ComboSortBy.SelectedIndex == 0) services = services.OrderBy(p => p.CostWithDiscount).ToList(); else services = services.OrderByDescending(p => p.CostWithDiscount).ToList(); //Фильтрация по размеру скидки if (ComboDiscount.SelectedIndex == 1) services = services.Where(p => p.Discount >= 0 && p.Discount < 0.05).ToList(); if (ComboDiscount.SelectedIndex == 2) services = services.Where(p => p.Discount >= 0.05 && p.Discount < 0.15).ToList(); if (ComboDiscount.SelectedIndex == 3) services = services.Where(p => p.Discount >= 0.15 && p.Discount < 0.3).ToList(); if (ComboDiscount.SelectedIndex == 4) services = services.Where(p => p.Discount >= 0.3 && p.Discount < 0.7).ToList(); if (ComboDiscount.SelectedIndex == 5) services = services.Where(p => p.Discount >= 0.7 && p.Discount < 1).ToList(); //Поиск по названию services = services.Where(p => p.Title.ToLower().Contains(TBoxSearch.Text.ToLower())).ToList(); LViewServices.ItemsSource = services; } private void Page_Loaded(object sender, RoutedEventArgs e) { UpdateServices(); } } }