AddEditPage.xaml.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.Navigation;
  14. using System.Windows.Shapes;
  15. namespace Khaustov_ProbniyDE
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для AddEditPage.xaml
  19. /// </summary>
  20. public partial class AddEditPage : Page
  21. {
  22. private Service _currentService = new Service();
  23. public AddEditPage(Service service)
  24. {
  25. InitializeComponent();
  26. if (service != null)
  27. _currentService = service;
  28. DataContext = _currentService;
  29. }
  30. private void BtnSave_Click(object sender, RoutedEventArgs e)
  31. {
  32. StringBuilder errors = new StringBuilder();
  33. if (string.IsNullOrWhiteSpace(_currentService.Наименование_услуги))
  34. errors.AppendLine("Укажите название услуги");
  35. if (_currentService.Главное_изображение==null)
  36. errors.AppendLine("Укажите изображение");
  37. if (_currentService.Длительность == null)
  38. errors.AppendLine("Укажите длительность");
  39. if (_currentService.Стоимость == null)
  40. errors.AppendLine("Укажите стоимость");
  41. if (_currentService.Действующая_скидка==null)
  42. errors.AppendLine("Укажите скидку");
  43. if (errors.Length > 0)
  44. {
  45. MessageBox.Show(errors.ToString());
  46. return;
  47. }
  48. if (_currentService.ID == 0)
  49. Хаустов_ПробныйДЭEntities.GetContext().Service.Add(_currentService);
  50. try
  51. {
  52. Хаустов_ПробныйДЭEntities.GetContext().SaveChanges();
  53. MessageBox.Show("Информация сохранена");
  54. }
  55. catch (Exception ex)
  56. {
  57. MessageBox.Show(ex.Message.ToString());
  58. }
  59. }
  60. }
  61. }