You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
888 B
33 lines
888 B
using Models;
|
|
|
|
namespace ShoopNCook.Views;
|
|
|
|
// Classe représentant une entrée d'ingrédient
|
|
public partial class IngredientEntry : ContentView
|
|
{
|
|
|
|
public string QuantityText { get; set; }
|
|
public string NameText { get; set; }
|
|
|
|
public IngredientEntry()
|
|
{
|
|
BindingContext = this;
|
|
InitializeComponent();
|
|
}
|
|
|
|
// Renvoie une nouvelle instance de Ingredient à partir des informations entrées par l'utilisateur
|
|
public Ingredient? MakeValue()
|
|
{
|
|
float quantity;
|
|
|
|
// Tente de convertir la quantité en float, sinon, attribue une valeur par défaut de 0
|
|
if (!float.TryParse(QuantityText, out quantity) || quantity < 0)
|
|
{
|
|
UserNotifier.Error("La quantité doit être un nombre positif");
|
|
return null;
|
|
}
|
|
|
|
return new Ingredient(NameText, quantity, UnitPicker.SelectedItem as string);
|
|
}
|
|
}
|