Добавить и редактировать
8 декабря 2020 г. в 01:08
в файле для добавления и редактирования это
private Hotel _currentHotel = new Hotel();
public AddEditPage(Hotel selectedHotel)
{
if(selectedHotel != null)
{
_currentHotel = selectedHotel;
}
InitializeComponent();
DataContext = _currentHotel;
ComboCountries.ItemsSource = Home.GetContext().Country.ToList();
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
StringBuilder errors = new StringBuilder();
if (string.IsNullOrWhiteSpace(_currentHotel.Name))
errors.AppendLine("Введите название отеля");
if (_currentHotel.CountOfStars < 1 || _currentHotel.CountOfStars > 5)
errors.AppendLine("Введите число от 1 до 5");
if (_currentHotel.Country == null)
errors.AppendLine("Выберите страну");
if (errors.Length>0)
{
MessageBox.Show(errors.ToString());return;
}
if (_currentHotel.Id == 0)
Home.GetContext().Hotel.Add(_currentHotel);
try
{
Home.GetContext().SaveChanges();
MessageBox.Show("Информация успешно сохранена");
Manager.MainFrame.GoBack();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
далее это для логический в текстовый(пишем в класс этой таблицы)
<TextBlock Text="{Binding ActualText}"/>
public string ActualText
{
get
{
return (IsActual) ? "Актуален" : "Завершен";
}
}