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

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

@ -6,7 +6,7 @@
xmlns:local="clr-namespace:Views"
x:Name="nAddRecipe">
<ScrollView>
<VerticalStackLayout BindingContext="{Binding RecipeToAdd}">
<VerticalStackLayout>
<local:MiniHeader
TitleMini="Ajouter une recette"
NeedReturn="True"
@ -18,7 +18,7 @@
<Entry Placeholder="Saisie du texte de la recette correspondante"
Grid.Row="1"
Margin="10"
Text="{Binding Title}"
Text="{Binding TitleRecipe, Mode=OneWayToSource}"
x:Name="RecipeName"/>
<Label Text="Type de la recette" Grid.Row="2"/>
<RadioButton x:Name="CheckEntree" Grid.Row="3" Margin="10,0,20,0" />
@ -60,9 +60,9 @@
MinimumWidthRequest="299"
AutoSize="TextChanges"/>
<Entry Placeholder="N° Etape"
Margin="12,0"
Text ="{Binding Order}"
<Entry Margin="12,0"
IsReadOnly="True"
Text ="{Binding PreparationStepOrder, Source={x:Reference nAddRecipe}}"
x:Name="PreparationOrder"/>
</HorizontalStackLayout>
<HorizontalStackLayout Grid.Row="8" Margin="20">

@ -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

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

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

Loading…
Cancel
Save