diff --git a/MCTG/Model/Recipes/Ingredient/Ingredient.cs b/MCTG/Model/Recipes/Ingredient/Ingredient.cs
index c8452d8..7fed257 100644
--- a/MCTG/Model/Recipes/Ingredient/Ingredient.cs
+++ b/MCTG/Model/Recipes/Ingredient/Ingredient.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
@@ -8,7 +10,7 @@ using System.Threading.Tasks;
namespace Model
{
[DataContract(Name = "ingredient")]
- public class Ingredient
+ public class Ingredient : INotifyPropertyChanged
{
#region Attributes
[DataMember(Name = "id")]
@@ -17,6 +19,7 @@ namespace Model
[DataMember(Name = "quantity")]
private Quantity _quantity = new Quantity(1, Unit.unit);
+ public event PropertyChangedEventHandler? PropertyChanged;
#endregion
#region Properties
@@ -33,6 +36,7 @@ namespace Model
throw new ArgumentNullException("Impossible de ne pas avoir de nom pour l'ingrédient");
}
_name = value;
+ OnPropertyChanged();
}
}
@@ -41,8 +45,12 @@ namespace Model
///
public Quantity QuantityI
{
- get => _quantity;
- set => _quantity = value;
+ get { return _quantity; }
+ set
+ {
+ _quantity = value;
+ OnPropertyChanged();
+ }
}
@@ -62,6 +70,12 @@ namespace Model
Name = name;
QuantityI = quantity;
}
+ protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
+ {
+ if (PropertyChanged != null)
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+
#endregion
public override string ToString()
diff --git a/MCTG/Model/Recipes/Recipe.cs b/MCTG/Model/Recipes/Recipe.cs
index 9c48274..5697148 100644
--- a/MCTG/Model/Recipes/Recipe.cs
+++ b/MCTG/Model/Recipes/Recipe.cs
@@ -56,7 +56,7 @@ namespace Model
/// Priority of this recipe.
///
[DataMember(Name = "priority")]
- public Priority Priority { get; private set; }
+ public Priority Priority { get; set; }
///
/// The Title of the recipe.
@@ -107,7 +107,7 @@ namespace Model
/// The type of recipe.
///
[DataMember(Name = "type")]
- public RecipeType Type { get; private set; }
+ public RecipeType Type { get; set; }
#endregion
#region Constructors
diff --git a/MCTG/Views/ContentPages/AddRecipe.xaml b/MCTG/Views/ContentPages/AddRecipe.xaml
index b8ddf9c..bae9437 100644
--- a/MCTG/Views/ContentPages/AddRecipe.xaml
+++ b/MCTG/Views/ContentPages/AddRecipe.xaml
@@ -3,68 +3,91 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Views.AddRecipe"
Title="AddRecipe"
- xmlns:local="clr-namespace:Views">
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/MCTG/Views/ContentPages/AddRecipe.xaml.cs b/MCTG/Views/ContentPages/AddRecipe.xaml.cs
index 7cacef2..80ce6ba 100644
--- a/MCTG/Views/ContentPages/AddRecipe.xaml.cs
+++ b/MCTG/Views/ContentPages/AddRecipe.xaml.cs
@@ -1,6 +1,7 @@
using Model;
using System.Diagnostics;
using Microsoft.Maui.Media;
+using Microsoft.Maui.Controls;
namespace Views
{
@@ -8,28 +9,24 @@ namespace Views
{
private List ingredientList;
private List 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 UnitList { get; set; } = new List { Unit.unit, Unit.kG, Unit.mG, Unit.G, Unit.L, Unit.cL, Unit.mL };
public List IngredientList { get => ingredientList; set => ingredientList = value; }
public List PreparationStepList { get => preparationStepList; set => preparationStepList = value; }
- public AddRecipe(List preparationStepList)
- {
- PreparationStepList = preparationStepList;
- }
-
- public AddRecipe(List ingredientList)
- {
- IngredientList = ingredientList;
- }
-
- public bool IsCaptureSupported => throw new NotImplementedException();
-
+ 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();
+ PreparationStepList = new List();
}
private void PickPhoto(object sender, EventArgs e)
{
@@ -38,21 +35,118 @@ namespace Views
private void AddRecipeValidation(object sender, EventArgs e)
{
- if (IsCaptureSupported)
- {
-
- }
+
}
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'étape de la recette est effectuée avec succès", "Ok");
+ }
+ else
+ {
+ DisplayAlert("Liste d'étape vide", "Suppression impossible car la liste des é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édient est effectuée avec succès", "Ok");
+ }
+ else
+ {
+ DisplayAlert("Liste d'ingrédient vide", "Suppression impossible car la liste des ingré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;
+ }
}
}
}
\ No newline at end of file
diff --git a/MCTG/Views/ContentPages/ViewRecette.xaml b/MCTG/Views/ContentPages/ViewRecette.xaml
index c763e19..431105b 100644
--- a/MCTG/Views/ContentPages/ViewRecette.xaml
+++ b/MCTG/Views/ContentPages/ViewRecette.xaml
@@ -5,65 +5,61 @@
xmlns:local="clr-namespace:Views"
Title="ViewRecette"
x:Name="nrecipe">
-
-
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file