| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- namespace practiceApplicaiton;
- public partial class RoomsPage : ContentPage
- {
- private Room? _selected;
- public RoomsPage() => InitializeComponent();
- protected override async void OnAppearing()
- {
- base.OnAppearing();
- await LoadAsync();
- }
- private async Task LoadAsync()
- {
- try { RoomsList.ItemsSource = await Repository.GetRoomsAsync(); }
- catch (Exception ex) { await DisplayAlertAsync("Ошибка", ex.Message, "OK"); }
- }
- private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- _selected = e.CurrentSelection.FirstOrDefault() as Room;
- EditRatingButton.IsEnabled = _selected != null;
- }
- private async void OnEditRatingClicked(object sender, EventArgs e)
- {
- if (_selected == null) return;
- var result = await DisplayPromptAsync(
- "Рейтинг комнаты",
- $"Введите новый рейтинг для комнаты №{_selected.RoomNumber} (0.0 — 5.0):",
- initialValue: _selected.Rating.ToString("F1"),
- keyboard: Keyboard.Numeric);
- if (result == null) return;
- if (!decimal.TryParse(result.Replace(',', '.'),
- System.Globalization.NumberStyles.Any,
- System.Globalization.CultureInfo.InvariantCulture, out var rating)
- || rating < 0 || rating > 5)
- {
- await DisplayAlertAsync("Ошибка", "Рейтинг должен быть от 0.0 до 5.0", "OK");
- return;
- }
- try
- {
- await Repository.UpdateRoomRatingAsync(_selected.RoomId, rating);
- await LoadAsync();
- }
- catch (Exception ex) { await DisplayAlertAsync("Ошибка", ex.Message, "OK"); }
- }
- }
|