123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 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 Khaustov_ProbniyDE
- {
- /// <summary>
- /// Логика взаимодействия для AddEditPage.xaml
- /// </summary>
- public partial class AddEditPage : Page
- {
- private Service _currentService = new Service();
- public AddEditPage(Service service)
- {
- InitializeComponent();
- if (service != null)
- _currentService = service;
- DataContext = _currentService;
- }
- private void BtnSave_Click(object sender, RoutedEventArgs e)
- {
- StringBuilder errors = new StringBuilder();
- if (string.IsNullOrWhiteSpace(_currentService.Наименование_услуги))
- errors.AppendLine("Укажите название услуги");
- if (_currentService.Главное_изображение==null)
- errors.AppendLine("Укажите изображение");
- if (_currentService.Длительность == null)
- errors.AppendLine("Укажите длительность");
- if (_currentService.Стоимость == null)
- errors.AppendLine("Укажите стоимость");
- if (_currentService.Действующая_скидка==null)
- errors.AppendLine("Укажите скидку");
- if (errors.Length > 0)
- {
- MessageBox.Show(errors.ToString());
- return;
- }
- if (_currentService.ID == 0)
- Хаустов_ПробныйДЭEntities.GetContext().Service.Add(_currentService);
- try
- {
- Хаустов_ПробныйДЭEntities.GetContext().SaveChanges();
- MessageBox.Show("Информация сохранена");
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString());
- }
- }
- }
- }
|