|
|
|
@ -12,19 +12,29 @@ namespace Views
|
|
|
|
|
private Recipe recipeToAdd;
|
|
|
|
|
private Ingredient ingredient;
|
|
|
|
|
private PreparationStep preparationStep;
|
|
|
|
|
private string titleRecipe;
|
|
|
|
|
public MasterManager Master => (Application.Current as App).Master;
|
|
|
|
|
public User CurrentUser => Master.User.CurrentConnected;
|
|
|
|
|
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 string TitleRecipe { get=> titleRecipe; set => titleRecipe = value; }
|
|
|
|
|
public PreparationStep PreparationStepAdd { get => preparationStep; set => preparationStep = value; }
|
|
|
|
|
public static readonly BindableProperty PreparationStepOrderProperty =
|
|
|
|
|
BindableProperty.Create(nameof(PreparationStepOrder), typeof(int), typeof(Entry), 1);
|
|
|
|
|
|
|
|
|
|
public int PreparationStepOrder
|
|
|
|
|
{
|
|
|
|
|
get => (int)GetValue(PreparationStepOrderProperty);
|
|
|
|
|
set => SetValue(PreparationStepOrderProperty, value);
|
|
|
|
|
}
|
|
|
|
|
public AddRecipe()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
BindingContext = this;
|
|
|
|
|
|
|
|
|
|
RecipeToAdd = new Recipe("Nouvelle Recette");
|
|
|
|
|
IngredientList = new List<Ingredient>();
|
|
|
|
|
PreparationStepList = new List<PreparationStep>();
|
|
|
|
|
}
|
|
|
|
@ -36,23 +46,57 @@ namespace Views
|
|
|
|
|
private void AddRecipeValidation(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(TitleRecipe))
|
|
|
|
|
{
|
|
|
|
|
DisplayAlert("Erreur", "Entrez un nom de recette.", "Ok");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RecipeType newRecipeType = GetSelectedRecipeType();
|
|
|
|
|
Priority selectedPriority = GetSelectedPriority();
|
|
|
|
|
string authorMail = CurrentUser.Mail;
|
|
|
|
|
|
|
|
|
|
Recipe newRecipe = new Recipe
|
|
|
|
|
(
|
|
|
|
|
TitleRecipe,
|
|
|
|
|
newRecipeType,
|
|
|
|
|
selectedPriority,
|
|
|
|
|
null,
|
|
|
|
|
authorMail
|
|
|
|
|
);
|
|
|
|
|
newRecipe.PreparationSteps.AddRange(PreparationStepList);
|
|
|
|
|
newRecipe.Ingredients.AddRange(IngredientList);
|
|
|
|
|
|
|
|
|
|
bool isRecipeSave = Master.Recipe.AddRecipeToData(newRecipe);
|
|
|
|
|
if (isRecipeSave)
|
|
|
|
|
{
|
|
|
|
|
DisplayAlert("Succès", "La recette a été ajoutée avec succès", "OK");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DisplayAlert("Echec", "La recette n'a pas été ajoutée", "OK");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newRecipe = new Recipe("Nouvelle Recette");
|
|
|
|
|
|
|
|
|
|
PreparationStepList.Clear();
|
|
|
|
|
IngredientList.Clear();
|
|
|
|
|
Navigation.PopAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddStepRecipe(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string description = PreparationDescription.Text;
|
|
|
|
|
int order = Convert.ToInt32(PreparationOrder.Text);
|
|
|
|
|
|
|
|
|
|
PreparationStep PreparationStepAdd = new PreparationStep
|
|
|
|
|
(
|
|
|
|
|
order,
|
|
|
|
|
PreparationStepOrder,
|
|
|
|
|
description
|
|
|
|
|
);
|
|
|
|
|
PreparationStepList.Add( PreparationStepAdd );
|
|
|
|
|
|
|
|
|
|
PreparationStepOrder++;
|
|
|
|
|
PreparationDescription.Text = string.Empty;
|
|
|
|
|
PreparationOrder.Text = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveStepRecipe(object sender, EventArgs e)
|
|
|
|
@ -60,6 +104,7 @@ namespace Views
|
|
|
|
|
if (PreparationStepList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
PreparationStepList.RemoveAt(PreparationStepList.Count - 1);
|
|
|
|
|
PreparationStepOrder--;
|
|
|
|
|
DisplayAlert("Suppression", "La suppression de l'étape de la recette est effectuée avec succès", "Ok");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|