|
|
using Model;
|
|
|
using System.Diagnostics;
|
|
|
using Microsoft.Maui.Media;
|
|
|
using Microsoft.Maui.Controls;
|
|
|
|
|
|
namespace Views
|
|
|
{
|
|
|
public partial class AddRecipe : ContentPage
|
|
|
{
|
|
|
private List<Ingredient> ingredientList;
|
|
|
private List<PreparationStep> preparationStepList;
|
|
|
private Recipe recipeToAdd;
|
|
|
private Ingredient ingredient;
|
|
|
private PreparationStep preparationStep;
|
|
|
public MasterManager Master => (Application.Current as App).Master;
|
|
|
public Recipe RecipeToAdd{ get=> recipeToAdd; set => recipeToAdd = value; }
|
|
|
public List<Unit> UnitList { get; set; } = new List<Unit> { Unit.unit, Unit.kG, Unit.mG, Unit.G, Unit.L, Unit.cL, Unit.mL };
|
|
|
public List<Ingredient> IngredientList { get => ingredientList; set => ingredientList = value; }
|
|
|
public List<PreparationStep> PreparationStepList { get => preparationStepList; set => preparationStepList = value; }
|
|
|
public Ingredient Ingredient { get => ingredient; set => ingredient = value ; }
|
|
|
public PreparationStep PreparationStepAdd { get => preparationStep; set => preparationStep = value; }
|
|
|
public AddRecipe()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
BindingContext = this;
|
|
|
|
|
|
RecipeToAdd = new Recipe("Nouvelle Recette");
|
|
|
IngredientList = new List<Ingredient>();
|
|
|
PreparationStepList = new List<PreparationStep>();
|
|
|
}
|
|
|
private void PickPhoto(object sender, EventArgs e)
|
|
|
{
|
|
|
MediaPicker.PickPhotoAsync();
|
|
|
}
|
|
|
|
|
|
private void AddRecipeValidation(object sender, EventArgs e)
|
|
|
{
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private void AddStepRecipe(object sender, EventArgs e)
|
|
|
{
|
|
|
string description = PreparationDescription.Text;
|
|
|
int order = Convert.ToInt32(PreparationOrder.Text);
|
|
|
|
|
|
PreparationStep PreparationStepAdd = new PreparationStep
|
|
|
(
|
|
|
order,
|
|
|
description
|
|
|
);
|
|
|
PreparationStepList.Add( PreparationStepAdd );
|
|
|
|
|
|
PreparationDescription.Text = string.Empty;
|
|
|
PreparationOrder.Text = string.Empty;
|
|
|
}
|
|
|
|
|
|
private void RemoveStepRecipe(object sender, EventArgs e)
|
|
|
{
|
|
|
if (PreparationStepList.Count > 0)
|
|
|
{
|
|
|
PreparationStepList.RemoveAt(PreparationStepList.Count - 1);
|
|
|
DisplayAlert("Suppression", "La suppression de l'<27>tape de la recette est effectu<74>e avec succ<63>s", "Ok");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
DisplayAlert("Liste d'<27>tape vide", "Suppression impossible car la liste des <20>tapes de description est vide.", "Ok");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void AddIngredient(object sender, EventArgs e)
|
|
|
{
|
|
|
string ingredientName = nameIngredient.Text;
|
|
|
int numberQuantity = Convert.ToInt32(quantityNumber.Text);
|
|
|
Unit unitQuantity = (Unit)UnitPicker.SelectedItem;
|
|
|
|
|
|
Ingredient newIngredient = new Ingredient
|
|
|
(
|
|
|
ingredientName,
|
|
|
new Quantity
|
|
|
(
|
|
|
numberQuantity,
|
|
|
unitQuantity
|
|
|
)
|
|
|
);
|
|
|
IngredientList.Add( newIngredient );
|
|
|
|
|
|
nameIngredient.Text = string.Empty;
|
|
|
quantityNumber.Text = string.Empty;
|
|
|
UnitPicker.SelectedItem = null;
|
|
|
}
|
|
|
|
|
|
private void RemoveIngredient(object sender, EventArgs e)
|
|
|
{
|
|
|
if (IngredientList.Count > 0)
|
|
|
{
|
|
|
IngredientList.RemoveAt(IngredientList.Count - 1);
|
|
|
DisplayAlert("Suppression", "La suppression de l'ingr<67>dient est effectu<74>e avec succ<63>s", "Ok");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
DisplayAlert("Liste d'ingr<67>dient vide", "Suppression impossible car la liste des ingr<67>dients est vide.", "Ok");
|
|
|
}
|
|
|
}
|
|
|
private RecipeType GetSelectedRecipeType()
|
|
|
{
|
|
|
if (CheckEntree.IsChecked)
|
|
|
{
|
|
|
return RecipeType.Starter;
|
|
|
}
|
|
|
else if (CheckPlat.IsChecked)
|
|
|
{
|
|
|
return RecipeType.Dish;
|
|
|
}
|
|
|
else if (CheckDessert.IsChecked)
|
|
|
{
|
|
|
return RecipeType.Dessert;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return RecipeType.Unspecified;
|
|
|
}
|
|
|
}
|
|
|
private Priority GetSelectedPriority()
|
|
|
{
|
|
|
if (checkEconomique.IsChecked)
|
|
|
{
|
|
|
return Priority.Economic;
|
|
|
}
|
|
|
else if (checkFast.IsChecked)
|
|
|
{
|
|
|
return Priority.Fast;
|
|
|
}
|
|
|
else if (checkEasy.IsChecked)
|
|
|
{
|
|
|
return Priority.Easy;
|
|
|
}
|
|
|
else if (checkLight.IsChecked)
|
|
|
{
|
|
|
return Priority.Light;
|
|
|
}
|
|
|
else if (checkGourmet.IsChecked)
|
|
|
{
|
|
|
return Priority.Gourmet;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return Priority.Gourmet;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} |