UpdateWindow.xaml.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. namespace Eight
  15. {
  16. /// <summary>
  17. /// Логика взаимодействия для UpdateWindow.xaml
  18. /// </summary>
  19. public partial class UpdateWindow : Window
  20. {
  21. private List<Product> _products;
  22. public UpdateWindow(List<Product> products)
  23. {
  24. InitializeComponent();
  25. _products = products;
  26. TbCost.Text = _products.Select(x => x.MinCostForAgent).Average().ToString();
  27. }
  28. private void BtnSubmit_Click(object sender, RoutedEventArgs e)
  29. {
  30. if (decimal.TryParse(TbCost.Text, out decimal cost))
  31. {
  32. foreach (var product in _products)
  33. {
  34. product.MinCostForAgent = cost;
  35. }
  36. Helper.GetContext().SaveChanges();
  37. MessageBox.Show("Стоимость для агентов изменена.", "Инфо", MessageBoxButton.OK, MessageBoxImage.Information);
  38. }
  39. Close();
  40. }
  41. }
  42. }