add images work !

pull/66/head
Alexandre AGOSTINHO 2 years ago
parent c27eb0ea73
commit f955fd809f

@ -13,6 +13,9 @@ namespace Views
private Ingredient ingredient;
private PreparationStep preparationStep;
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 User CurrentUser => Master.User.CurrentConnected;
public Recipe RecipeToAdd{ get=> recipeToAdd; set => recipeToAdd = value; }
@ -38,20 +41,30 @@ namespace Views
IngredientList = new List<Ingredient>();
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))
{
DisplayAlert("Erreur", "Entrez un nom de recette.", "Ok");
await DisplayAlert("Erreur", "Entrez un nom de recette.", "Ok");
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();
Priority selectedPriority = GetSelectedPriority();
string authorMail = CurrentUser.Mail;
@ -62,7 +75,8 @@ namespace Views
newRecipeType,
selectedPriority,
null,
authorMail
authorMail,
ImageSourcePath
);
newRecipe.PreparationSteps.AddRange(PreparationStepList);
newRecipe.Ingredients.AddRange(IngredientList);
@ -70,18 +84,18 @@ namespace Views
bool isRecipeSave = Master.Recipe.AddRecipeToData(newRecipe);
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
{
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");
PreparationStepList.Clear();
IngredientList.Clear();
Navigation.PopAsync();
await Navigation.PopAsync();
}
private void AddStepRecipe(object sender, EventArgs e)
@ -115,6 +129,12 @@ namespace Views
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;
int numberQuantity = Convert.ToInt32(quantityNumber.Text);
Unit unitQuantity = (Unit)UnitPicker.SelectedItem;

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:model="clr-namespace:Model;assembly=Model"
xmlns:local="clr-namespace:Views"
x:Class="Views.MyPosts"
Title="MyPosts">
@ -8,45 +9,59 @@
<local:ContainerBase
NeedReturn="True">
<!-- Flyout -->
<local:ContainerBase.MyFlyoutContent>
<Grid RowDefinitions="250, *, *" VerticalOptions="Fill">
<Grid RowDefinitions="Auto, *, *" VerticalOptions="Center">
<VerticalStackLayout Grid.Row="1">
<Button Text="Mes informations" ImageSource="person_default.png" Style="{StaticResource button1}" Grid.Row="1"/>
<Button Text="Modifier" ImageSource="settings_icon.png" Style="{StaticResource button1}" Grid.Row="2"/>
<Button Text="Mes informations"
ImageSource="person_default.png"
Style="{StaticResource button1}"
Grid.Row="1"
Clicked="MyInformations_Clicked"/>
<Button Text="Ajouter une recette"
ImageSource="add_icon.png"
Style="{StaticResource button1}"
Grid.Row="2"
Clicked="AddRecipe_Clicked"/>
</VerticalStackLayout>
</Grid>
</local:ContainerBase.MyFlyoutContent>
<!-- Master -->
<local:ContainerBase.MyContent>
<ScrollView>
<StackLayout>
<Label Text="Mon profil" TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource Gray100}}"
FontAttributes="Bold"
FontSize="24" Padding="15, 15, 20, 5"/>
<Label Text="Mes publications" TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource Gray100}}"
FontSize="20" Padding="15"/>
<StackLayout MinimumWidthRequest="400">
<Label
Text="{Binding RecipesDisplayed.Description}"
TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource Gray100}}"
FontSize="24"
Padding="15"/>
<FlexLayout
Margin="0, 15"
Wrap="Wrap"
JustifyContent="Start"
AlignItems="Center"
AlignContent="SpaceEvenly"
HorizontalOptions="Center">
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
Margin="0, 15"
Wrap="Wrap"
JustifyContent="Start"
AlignItems="Center"
AlignContent="SpaceEvenly"
HorizontalOptions="Center"
BindableLayout.ItemsSource="{Binding RecipesDisplayed}">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="model:Recipe">
<local:RecipeCase
CaseImageSource="{Binding Image}"
RecipeTitle="{Binding Title}"/>
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
</StackLayout>
</ScrollView>
</local:ContainerBase.MyContent>
</local:ContainerBase>

@ -1,9 +1,34 @@
using Model;
namespace Views;
public partial class MyPosts : ContentPage
{
public MyPosts()
public MasterManager Master => (Application.Current as App).Master;
private readonly RecipeCollection _recipesDisplayed;
public ReadOnlyObservableRecipeCollection RecipesDisplayed { get; private set; }
public Recipe Recipe => Master.Recipe.CurrentSelected;
public MyPosts()
{
InitializeComponent();
}
}
_recipesDisplayed = Master.Recipe.GetRecipeByAuthor(Master.User.CurrentConnected.Mail);
RecipesDisplayed = new ReadOnlyObservableRecipeCollection(_recipesDisplayed);
InitializeComponent();
BindingContext = this;
}
private void MyInformations_Clicked(object sender, EventArgs e)
{
Navigation.PopModalAsync();
}
private void AddRecipe_Clicked(object sender, EventArgs e)
{
Navigation.PushModalAsync(new AddRecipe());
}
}

@ -18,8 +18,8 @@
Style="{StaticResource button1}"
Grid.Row="1"
Clicked="OnMyRecipeClicked"/>
<Button Text="Ajouter Recette"
ImageSource="settings_icon.png"
<Button Text="Ajouter une recette"
ImageSource="add_icon.png"
Style="{StaticResource button1}"
Grid.Row="2"
Clicked="OnAddRecipeClicked"/>

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 -960 960 960" width="48"><path d="M450-200v-250H200v-60h250v-250h60v250h250v60H510v250h-60Z"/></svg>

After

Width:  |  Height:  |  Size: 163 B

Loading…
Cancel
Save