|
|
@ -13,6 +13,9 @@ namespace Views
|
|
|
|
private Ingredient ingredient;
|
|
|
|
private Ingredient ingredient;
|
|
|
|
private PreparationStep preparationStep;
|
|
|
|
private PreparationStep preparationStep;
|
|
|
|
private string titleRecipe;
|
|
|
|
private string titleRecipe;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public FileResult ImageSource { get; private set; } = null;
|
|
|
|
|
|
|
|
public string? ImageSourcePath { get; private set; } = null;
|
|
|
|
public MasterManager Master => (Application.Current as App).Master;
|
|
|
|
public MasterManager Master => (Application.Current as App).Master;
|
|
|
|
public User CurrentUser => Master.User.CurrentConnected;
|
|
|
|
public User CurrentUser => Master.User.CurrentConnected;
|
|
|
|
public Recipe RecipeToAdd{ get=> recipeToAdd; set => recipeToAdd = value; }
|
|
|
|
public Recipe RecipeToAdd{ get=> recipeToAdd; set => recipeToAdd = value; }
|
|
|
@ -38,20 +41,30 @@ namespace Views
|
|
|
|
IngredientList = new List<Ingredient>();
|
|
|
|
IngredientList = new List<Ingredient>();
|
|
|
|
PreparationStepList = new List<PreparationStep>();
|
|
|
|
PreparationStepList = new List<PreparationStep>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void PickPhoto(object sender, EventArgs e)
|
|
|
|
private async void PickPhoto(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
MediaPicker.PickPhotoAsync();
|
|
|
|
ImageSource = await MediaPicker.Default.PickPhotoAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void AddRecipeValidation(object sender, EventArgs e)
|
|
|
|
private async void AddRecipeValidation(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(TitleRecipe))
|
|
|
|
if (string.IsNullOrWhiteSpace(TitleRecipe))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DisplayAlert("Erreur", "Entrez un nom de recette.", "Ok");
|
|
|
|
await DisplayAlert("Erreur", "Entrez un nom de recette.", "Ok");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ImageSource != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// save the file into local storage
|
|
|
|
|
|
|
|
ImageSourcePath = Path.Combine(FileSystem.Current.AppDataDirectory, $"{TitleRecipe}.{ImageSource.FileName}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using Stream sourceStream = await ImageSource.OpenReadAsync();
|
|
|
|
|
|
|
|
using FileStream localFileStream = File.OpenWrite(ImageSourcePath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await sourceStream.CopyToAsync(localFileStream);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RecipeType newRecipeType = GetSelectedRecipeType();
|
|
|
|
RecipeType newRecipeType = GetSelectedRecipeType();
|
|
|
|
Priority selectedPriority = GetSelectedPriority();
|
|
|
|
Priority selectedPriority = GetSelectedPriority();
|
|
|
|
string authorMail = CurrentUser.Mail;
|
|
|
|
string authorMail = CurrentUser.Mail;
|
|
|
@ -62,7 +75,8 @@ namespace Views
|
|
|
|
newRecipeType,
|
|
|
|
newRecipeType,
|
|
|
|
selectedPriority,
|
|
|
|
selectedPriority,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
authorMail
|
|
|
|
authorMail,
|
|
|
|
|
|
|
|
ImageSourcePath
|
|
|
|
);
|
|
|
|
);
|
|
|
|
newRecipe.PreparationSteps.AddRange(PreparationStepList);
|
|
|
|
newRecipe.PreparationSteps.AddRange(PreparationStepList);
|
|
|
|
newRecipe.Ingredients.AddRange(IngredientList);
|
|
|
|
newRecipe.Ingredients.AddRange(IngredientList);
|
|
|
@ -70,18 +84,18 @@ namespace Views
|
|
|
|
bool isRecipeSave = Master.Recipe.AddRecipeToData(newRecipe);
|
|
|
|
bool isRecipeSave = Master.Recipe.AddRecipeToData(newRecipe);
|
|
|
|
if (isRecipeSave)
|
|
|
|
if (isRecipeSave)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DisplayAlert("Succès", "La recette a été ajoutée avec succès", "OK");
|
|
|
|
await DisplayAlert("Succès", "La recette a été ajoutée avec succès", "OK");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DisplayAlert("Echec", "La recette n'a pas été ajoutée", "OK");
|
|
|
|
await DisplayAlert("Echec", "La recette n'a pas été ajoutée", "OK");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
newRecipe = new Recipe("Nouvelle Recette");
|
|
|
|
newRecipe = new Recipe("Nouvelle Recette");
|
|
|
|
|
|
|
|
|
|
|
|
PreparationStepList.Clear();
|
|
|
|
PreparationStepList.Clear();
|
|
|
|
IngredientList.Clear();
|
|
|
|
IngredientList.Clear();
|
|
|
|
Navigation.PopAsync();
|
|
|
|
await Navigation.PopAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void AddStepRecipe(object sender, EventArgs e)
|
|
|
|
private void AddStepRecipe(object sender, EventArgs e)
|
|
|
@ -115,6 +129,12 @@ namespace Views
|
|
|
|
|
|
|
|
|
|
|
|
private void AddIngredient(object sender, EventArgs e)
|
|
|
|
private void AddIngredient(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (nameIngredient.Text is null || quantityNumber.Text is null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DisplayAlert("Warning", "some values are null, please provide correct values.", "Ok");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string ingredientName = nameIngredient.Text;
|
|
|
|
string ingredientName = nameIngredient.Text;
|
|
|
|
int numberQuantity = Convert.ToInt32(quantityNumber.Text);
|
|
|
|
int numberQuantity = Convert.ToInt32(quantityNumber.Text);
|
|
|
|
Unit unitQuantity = (Unit)UnitPicker.SelectedItem;
|
|
|
|
Unit unitQuantity = (Unit)UnitPicker.SelectedItem;
|
|
|
|