Binding AddRecipe page finished, nedd to fix some navigation problems
continuous-integration/drone/push Build is passing Details

pull/65/head
Roxane 2 years ago
parent 14465aecfe
commit a7391af3e9

@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -11,10 +13,13 @@ namespace Model
/// Define a step of the preparation of a recipe. /// Define a step of the preparation of a recipe.
/// </summary> /// </summary>
[DataContract(Name = "preparation-step")] [DataContract(Name = "preparation-step")]
public class PreparationStep : IEquatable<PreparationStep> public class PreparationStep : IEquatable<PreparationStep> , INotifyPropertyChanged
{ {
#region Attributes #region Attributes
private string _description = ""; private string _description = "";
private int _order = 1;
public event PropertyChangedEventHandler? PropertyChanged;
#endregion #endregion
#region Properties #region Properties
@ -22,7 +27,15 @@ namespace Model
/// The order of this step in the preparation of the meal. /// The order of this step in the preparation of the meal.
/// </summary> /// </summary>
[DataMember(Name = "order")] [DataMember(Name = "order")]
public int Order { get; init; } public int Order
{
get { return _order; }
set
{
_order = value;
OnPropertyChanged();
}
}
/// <summary> /// <summary>
/// The description of the task the user need to do for this step of the preparation. <br/> /// The description of the task the user need to do for this step of the preparation. <br/>
@ -40,6 +53,12 @@ namespace Model
_description = value; _description = value;
} }
} }
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
if (PropertyChanged != null)
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion #endregion
#region Constructors #region Constructors

@ -56,7 +56,7 @@ namespace Views
InitializeComponent(); InitializeComponent();
UserAppTheme = AppTheme.Light; UserAppTheme = AppTheme.Light;
MainPage = new AddRecipe(); MainPage = new Home();
//MainPage = new MyPosts(); //MainPage = new MyPosts();
} }

@ -6,7 +6,7 @@
xmlns:local="clr-namespace:Views" xmlns:local="clr-namespace:Views"
x:Name="nAddRecipe"> x:Name="nAddRecipe">
<ScrollView> <ScrollView>
<VerticalStackLayout BindingContext="{Binding RecipeToAdd}"> <VerticalStackLayout>
<local:MiniHeader <local:MiniHeader
TitleMini="Ajouter une recette" TitleMini="Ajouter une recette"
NeedReturn="True" NeedReturn="True"
@ -18,7 +18,7 @@
<Entry Placeholder="Saisie du texte de la recette correspondante" <Entry Placeholder="Saisie du texte de la recette correspondante"
Grid.Row="1" Grid.Row="1"
Margin="10" Margin="10"
Text="{Binding Title}" Text="{Binding TitleRecipe, Mode=OneWayToSource}"
x:Name="RecipeName"/> x:Name="RecipeName"/>
<Label Text="Type de la recette" Grid.Row="2"/> <Label Text="Type de la recette" Grid.Row="2"/>
<RadioButton x:Name="CheckEntree" Grid.Row="3" Margin="10,0,20,0" /> <RadioButton x:Name="CheckEntree" Grid.Row="3" Margin="10,0,20,0" />
@ -60,9 +60,9 @@
MinimumWidthRequest="299" MinimumWidthRequest="299"
AutoSize="TextChanges"/> AutoSize="TextChanges"/>
<Entry Placeholder="N° Etape" <Entry Margin="12,0"
Margin="12,0" IsReadOnly="True"
Text ="{Binding Order}" Text ="{Binding PreparationStepOrder, Source={x:Reference nAddRecipe}}"
x:Name="PreparationOrder"/> x:Name="PreparationOrder"/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout Grid.Row="8" Margin="20"> <HorizontalStackLayout Grid.Row="8" Margin="20">
@ -72,11 +72,11 @@
<Label Text="Saisir les ingrédients de la recette (nom, quantité, unité)" Grid.Row="6" Grid.Column="1" Margin="50,15"/> <Label Text="Saisir les ingrédients de la recette (nom, quantité, unité)" Grid.Row="6" Grid.Column="1" Margin="50,15"/>
<HorizontalStackLayout Grid.Row="7" Grid.Column="1" BindingContext="{Binding Ingredient}"> <HorizontalStackLayout Grid.Row="7" Grid.Column="1" BindingContext="{Binding Ingredient}">
<Entry Placeholder="Nom de l'ingrédient" <Entry Placeholder="Nom de l'ingrédient"
Margin="12,0,0,0" WidthRequest="500" Margin="12,0,0,0" WidthRequest="500"
Text="{Binding Name, Mode=OneWayToSource}" Text="{Binding Name, Mode=OneWayToSource}"
x:Name="nameIngredient"/> x:Name="nameIngredient"/>
<Entry Placeholder="1" <Entry Placeholder="1"
Text="{Binding QuantityI.Number , Mode=OneWayToSource}" Text="{Binding QuantityI.Number , Mode=OneWayToSource}"
x:Name="quantityNumber"/> x:Name="quantityNumber"/>
<Picker ItemsSource= "{Binding UnitList, Source={x:Reference nAddRecipe}}" x:Name="UnitPicker"/> <Picker ItemsSource= "{Binding UnitList, Source={x:Reference nAddRecipe}}" x:Name="UnitPicker"/>

@ -12,19 +12,29 @@ namespace Views
private Recipe recipeToAdd; private Recipe recipeToAdd;
private Ingredient ingredient; private Ingredient ingredient;
private PreparationStep preparationStep; private PreparationStep preparationStep;
private string titleRecipe;
public MasterManager Master => (Application.Current as App).Master; public MasterManager Master => (Application.Current as App).Master;
public User CurrentUser => Master.User.CurrentConnected;
public Recipe RecipeToAdd{ get=> recipeToAdd; set => recipeToAdd = value; } 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<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<Ingredient> IngredientList { get => ingredientList; set => ingredientList = value; }
public List<PreparationStep> PreparationStepList { get => preparationStepList; set => preparationStepList = value; } public List<PreparationStep> PreparationStepList { get => preparationStepList; set => preparationStepList = value; }
public Ingredient Ingredient { get => ingredient; set => ingredient = 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 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() public AddRecipe()
{ {
InitializeComponent(); InitializeComponent();
BindingContext = this; BindingContext = this;
RecipeToAdd = new Recipe("Nouvelle Recette");
IngredientList = new List<Ingredient>(); IngredientList = new List<Ingredient>();
PreparationStepList = new List<PreparationStep>(); PreparationStepList = new List<PreparationStep>();
} }
@ -35,24 +45,58 @@ namespace Views
private void AddRecipeValidation(object sender, EventArgs e) 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) private void AddStepRecipe(object sender, EventArgs e)
{ {
string description = PreparationDescription.Text; string description = PreparationDescription.Text;
int order = Convert.ToInt32(PreparationOrder.Text);
PreparationStep PreparationStepAdd = new PreparationStep PreparationStep PreparationStepAdd = new PreparationStep
( (
order, PreparationStepOrder,
description description
); );
PreparationStepList.Add( PreparationStepAdd ); PreparationStepList.Add( PreparationStepAdd );
PreparationStepOrder++;
PreparationDescription.Text = string.Empty; PreparationDescription.Text = string.Empty;
PreparationOrder.Text = string.Empty;
} }
private void RemoveStepRecipe(object sender, EventArgs e) private void RemoveStepRecipe(object sender, EventArgs e)
@ -60,6 +104,7 @@ namespace Views
if (PreparationStepList.Count > 0) if (PreparationStepList.Count > 0)
{ {
PreparationStepList.RemoveAt(PreparationStepList.Count - 1); PreparationStepList.RemoveAt(PreparationStepList.Count - 1);
PreparationStepOrder--;
DisplayAlert("Suppression", "La suppression de l'étape de la recette est effectuée avec succès", "Ok"); DisplayAlert("Suppression", "La suppression de l'étape de la recette est effectuée avec succès", "Ok");
} }
else else

@ -9,9 +9,8 @@
<local:EnumToValuesConverter x:Key="musicTypeToValueConverter" <local:EnumToValuesConverter x:Key="musicTypeToValueConverter"
x:TypeArguments="model:Priority"/> x:TypeArguments="model:Priority"/>
</ContentPage.Resources> </ContentPage.Resources>
<local:ContainerBase <local:ContainerBase>
NeedReturn="True"> <local:ContainerBase.MyFlyoutContent NeedReturn="True">
<local:ContainerBase.MyFlyoutContent>
<Grid RowDefinitions="250, *, *" VerticalOptions="Fill"> <Grid RowDefinitions="250, *, *" VerticalOptions="Fill">
<VerticalStackLayout Grid.Row="1"> <VerticalStackLayout Grid.Row="1">
<Button Text="Mes Recettes" <Button Text="Mes Recettes"

@ -48,5 +48,6 @@ public partial class ContainerFlyout : ContentView
public void Logout_Clicked(object sender, EventArgs e) public void Logout_Clicked(object sender, EventArgs e)
{ {
Master.User.LogOut(); Master.User.LogOut();
Navigation.PopModalAsync();
} }
} }

Loading…
Cancel
Save