HegreHotel/Views/Chambre/ModifierChambrePage.xaml.cs
2025-03-13 17:49:25 +01:00

35 lines
1.3 KiB
C#

using HegreHotel.Models;
using Microsoft.Maui.Controls;
using System.IO;
using Microsoft.Maui.Storage;
namespace HegreHotel.Views.Chambre
{
public partial class ModifierChambrePage : ContentPage
{
Models.Chambre _chambre;
public ModifierChambrePage(Models.Chambre chambre)
{
InitializeComponent();
_chambre = chambre;
// Préremplissage des champs
EntryNom.Text = _chambre.Nom;
EntryDescription.Text = _chambre.Description;
EntryTarif.Text = _chambre.Tarif.ToString();
EntryNbPersonne.Text = _chambre.NbPersonne.ToString();
}
private async void OnEnregistrerClicked(object sender, EventArgs e)
{
_chambre.Nom = EntryNom.Text;
_chambre.Description = EntryDescription.Text;
_chambre.Tarif = decimal.TryParse(EntryTarif.Text, out decimal tarif) ? tarif : _chambre.Tarif;
_chambre.NbPersonne = int.TryParse(EntryNbPersonne.Text, out int nb) ? nb : _chambre.NbPersonne;
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3");
var db = SingletonConnection.GetInstance(dbPath);
await db.UpdateAsync(_chambre);
await Navigation.PopAsync();
}
}
}