fix merge conflict + build issues

pull/48/head
Alexandre AGOSTINHO 2 years ago
commit 41689ae1f5

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;CI</Configurations>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DataPersistence\DataPersistence.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -5,12 +5,11 @@
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Configurations>Debug;Release;CI</Configurations>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\DataPersistence\DataPersistence.csproj" /> <ProjectReference Include="..\DataPersistence\DataPersistence.csproj" />
<ProjectReference Include="..\Model\Model.csproj" /> <ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -41,6 +41,7 @@ namespace ConsoleApp.Menu
title: title, title: title,
id: null, id: null,
authorMail: MasterManager.CurrentConnectedUser?.Mail, authorMail: MasterManager.CurrentConnectedUser?.Mail,
picture: "",
ingredients: new List<Ingredient>(), ingredients: new List<Ingredient>(),
preparationSteps: steps.ToArray() preparationSteps: steps.ToArray()
); );

@ -23,6 +23,7 @@ else
masterMgr = new MasterManager(dataManager); masterMgr = new MasterManager(dataManager);
} }
MenuManager menuMgr = new MenuManager(masterMgr); MenuManager menuMgr = new MenuManager(masterMgr);
menuMgr.Loop(); menuMgr.Loop();

@ -1,104 +1,108 @@
using Model; using Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace DataPersistence namespace DataPersistence
{ {
/// <summary> /// <summary>
/// The subs class is a group of prefabricated object that can only be loaded. It only use is for testing. /// The subs class is a group of prefabricated object that can only be loaded. It only use is for testing.
/// </summary> /// </summary>
public class Stubs : IDataManager public class Stubs : IDataManager
{ {
public Dictionary<string, List<object>> Load() public Dictionary<string, List<object>> Load()
{ {
Dictionary<string, List<object>> data = new Dictionary<string, List<object>> Dictionary<string, List<object>> data = new Dictionary<string, List<object>>
{ {
{ {
#region Data: Recipes #region Data: Recipes
nameof(Recipe), nameof(Recipe),
new List<object>(new[] new List<object>(new[]
{ {
new Recipe( new Recipe(
title: "Cookies classiques", id: null, title: "Cookies classiques",
authorMail: "admin@mctg.fr", id: 50,
ingredients: new List<Ingredient>(new[] authorMail: "admin@mctg.fr",
picture : "room_service_icon.png",
ingredients: new List<Ingredient>(new[]
{ {
new Ingredient("Patates", new Quantity(23, Unit.unit)), new Ingredient("Patates", new Quantity(23, Unit.unit)),
new Ingredient("Farine", new Quantity(23, Unit.G)) new Ingredient("Farine", new Quantity(23, Unit.G))
}), }),
preparationSteps: new[] preparationSteps: new[]
{ {
new PreparationStep(1, "Faire cuire."), new PreparationStep(1, "Faire cuire."),
new PreparationStep(2, "Manger.") new PreparationStep(2, "Manger.")
}), }),
new Recipe( new Recipe(
authorMail: "admin@mctg.fr", authorMail: "admin@mctg.fr",
title: "Cookies au chocolat", id: null, title: "Cookies au chocolat", id: null,
preparationSteps: new[] preparationSteps: new[]
{ {
new PreparationStep(1, "Moulinez la pâte."), new PreparationStep(1, "Moulinez la pâte."),
new PreparationStep(2, "Faire cuire pendant une bonne heure."), new PreparationStep(2, "Faire cuire pendant une bonne heure."),
new PreparationStep(3, "Sortir du four et mettre dans un plat.") new PreparationStep(3, "Sortir du four et mettre dans un plat.")
}), }),
new Recipe( new Recipe(
title: "Gateau nature", id: null, title: "Gateau nature", id: null,
authorMail: "admin@mctg.fr", authorMail: "admin@mctg.fr",
preparationSteps: new[] preparationSteps: new[]
{ {
new PreparationStep(1, "Achetez les ingrédients."), new PreparationStep(1, "Achetez les ingrédients."),
new PreparationStep(2, "Préparez le matériel. Ustensiles et tout."), new PreparationStep(2, "Préparez le matériel. Ustensiles et tout."),
new PreparationStep(3, "Pleurez.") new PreparationStep(3, "Pleurez.")
}), }),
new Recipe( new Recipe(
title: "Gateau au pommes", id: null, title: "Gateau au pommes", id: null,
authorMail: "admin@mctg.fr", authorMail: "admin@mctg.fr",
preparationSteps: new[] preparationSteps: new[]
{ {
new PreparationStep(1, "Achetez les légumes."), new PreparationStep(1, "Achetez les légumes."),
new PreparationStep(2, "Préparez le plat. Ustensiles et préchauffez le four."), new PreparationStep(2, "Préparez le plat. Ustensiles et préchauffez le four."),
new PreparationStep(3, "Coupez les pommes en morceaux et disposez-les sur le plat."), new PreparationStep(3, "Coupez les pommes en morceaux et disposez-les sur le plat."),
new PreparationStep(4, "Mettez enfin le plat au four, puis une fois cuit, dégustez !") new PreparationStep(4, "Mettez enfin le plat au four, puis une fois cuit, dégustez !")
}), }),
new Recipe( new Recipe(
title: "Gateau au chocolat", id: null, title: "Gateau au chocolat", id: null,
authorMail: "pedrosamigos@hotmail.com", authorMail: "pedrosamigos@hotmail.com",
preparationSteps: new[] preparationSteps: new[]
{ {
new PreparationStep(1, "Ajouter les oeufs."), new PreparationStep(1, "Ajouter les oeufs."),
new PreparationStep(2, "Ajouter la farine."), new PreparationStep(2, "Ajouter la farine."),
new PreparationStep(3, "Ajouter 100g de chocolat fondu."), new PreparationStep(3, "Ajouter 100g de chocolat fondu."),
new PreparationStep(4, "Mélanger le tout."), new PreparationStep(4, "Mélanger le tout."),
new PreparationStep(5, "Faire cuire 45h au four traditionnel.") new PreparationStep(5, "Faire cuire 45h au four traditionnel.")
}), }),
new Recipe( new Recipe(
title: "Dinde au jambon", id: null, title: "Dinde au jambon",
authorMail: "pedrosamigos@hotmail.com", id: null,
preparationSteps: new[] authorMail: "pedrosamigos@hotmail.com",
{ preparationSteps: new[]
new PreparationStep(1, "Faire une cuisson bien sec de la dinde à la poêle"), {
new PreparationStep(2, "Mettre la dinde au frigo."), new PreparationStep(1, "Faire une cuisson bien sec de la dinde à la poêle"),
new PreparationStep(3, "Mettre le jambon dans le micro-onde."), new PreparationStep(2, "Mettre la dinde au frigo."),
new PreparationStep(4, "Faire chauffer 3min."), new PreparationStep(3, "Mettre le jambon dans le micro-onde."),
new PreparationStep(5, "Présentez sur un plat la dinde et le jambon : Miam !") new PreparationStep(4, "Faire chauffer 3min."),
}), new PreparationStep(5, "Présentez sur un plat la dinde et le jambon : Miam !")
new Recipe( }),
title: "Poulet au curry", id: null, new Recipe(
authorMail: "pedrosamigos@hotmail.com", title: "Poulet au curry", id: null,
preparationSteps: new[] authorMail: "pedrosamigos@hotmail.com",
{ preparationSteps: new[]
new PreparationStep(1, "Trouvez des épices de curry."), {
new PreparationStep(2, "Trouvez maintenant du poulet."), new PreparationStep(1, "Trouvez des épices de curry."),
new PreparationStep(3, "Coupez la tête du poulet et posez-la dans un plat."), new PreparationStep(2, "Trouvez maintenant du poulet."),
new PreparationStep(4, "Parsemez d'épices curry la tête de la poule."), new PreparationStep(3, "Coupez la tête du poulet et posez-la dans un plat."),
new PreparationStep(5, "Mettre le tout au four traditionnel 30min."), new PreparationStep(4, "Parsemez d'épices curry la tête de la poule."),
new PreparationStep(6, "Dégustez en famille !") new PreparationStep(5, "Mettre le tout au four traditionnel 30min."),
}) new PreparationStep(6, "Dégustez en famille !")
}) })
#endregion })
#endregion
}, },
{ {
#region Data: User #region Data: User
nameof(User), nameof(User),

@ -1,105 +1,105 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Model namespace Model
{ {
/// <summary> /// <summary>
/// Define the manager of the data. This is where all the data are put, and where we call the loading and the saving of them. /// Define the manager of the data. This is where all the data are put, and where we call the loading and the saving of them.
/// </summary> /// </summary>
public class DataManager public class DataManager
{ {
#region Attributes & Properties #region Attributes & Properties
/// <summary> /// <summary>
/// The data manager injected that know how to serialize the data. /// The data manager injected that know how to serialize the data.
/// <br/><remarks><i>The setter is actually public for testing purpose. It will be private after.</i></remarks> /// <br/><remarks><i>The setter is actually public for testing purpose. It will be private after.</i></remarks>
/// <br/>See: <see cref="IDataManager"/> /// <br/>See: <see cref="IDataManager"/>
/// </summary> /// </summary>
public IDataManager Serializer { get; set; } public IDataManager Serializer { get; set; }
/// <summary> /// <summary>
/// The collection of all data. Each line of this dictionary has the type of the data as it key and the data for values. /// The collection of all data. Each line of this dictionary has the type of the data as it key and the data for values.
/// </summary> /// </summary>
public Dictionary<string, List<object>> Data { get; private set; } public Dictionary<string, List<object>> Data { get; private set; }
#endregion #endregion
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Constructor of the DataManager class. Take a IDataManager that will provide methods for the serialisation of the data. /// Constructor of the DataManager class. Take a IDataManager that will provide methods for the serialisation of the data.
/// </summary> /// </summary>
/// <param name="dataMgr">The data manager that know how to serialize a file.</param> /// <param name="dataMgr">The data manager that know how to serialize a file.</param>
public DataManager(IDataManager dataMgr) public DataManager(IDataManager dataMgr)
{ {
Serializer = dataMgr; Serializer = dataMgr;
Data = Serializer.Load(); Data = Serializer.Load();
} }
#endregion #endregion
#region Methods #region Methods
/// <summary> /// <summary>
/// Reload the data. Useful to update new data written in the save file. /// Reload the data. Useful to update new data written in the save file.
/// <br/>See: <see cref="IDataManager.Load"/> /// <br/>See: <see cref="IDataManager.Load"/>
/// </summary> /// </summary>
public void Reload() public void Reload()
=> Data = Serializer.Load(); => Data = Serializer.Load();
/// <summary> /// <summary>
/// Save the data. Call the Save method of the serializer. /// Save the data. Call the Save method of the serializer.
/// <br/>See: <see cref="IDataManager.Save(Dictionary{string, List{object}})"/> /// <br/>See: <see cref="IDataManager.Save(Dictionary{string, List{object}})"/>
/// </summary> /// </summary>
public void Save() public void Save()
=> Serializer.Save(Data); => Serializer.Save(Data);
/// <summary> /// <summary>
/// Import data from a file. /// Import data from a file.
/// <br/>See: <see cref="IDataManager.Import{T}(string)"/> /// <br/>See: <see cref="IDataManager.Import{T}(string)"/>
/// </summary> /// </summary>
/// <typeparam name="T">The type of data to import.</typeparam> /// <typeparam name="T">The type of data to import.</typeparam>
/// <param name="pathOfTheFile">The path containing the name of the file created.</param> /// <param name="pathOfTheFile">The path containing the name of the file created.</param>
public void Import<T>(string pathOfTheFile) public void Import<T>(string pathOfTheFile)
where T : class where T : class
{ {
KeyValuePair<string, T> import = Serializer.Import<T>(pathOfTheFile); KeyValuePair<string, T> import = Serializer.Import<T>(pathOfTheFile);
Data[import.Key].Add(import.Value); Data[import.Key].Add(import.Value);
} }
/// <summary> /// <summary>
/// Export the data from the collection of data. /// Export the data from the collection of data.
/// <br/>See: <see cref="IDataManager.Export{T}(T, string)"/> /// <br/>See: <see cref="IDataManager.Export{T}(T, string)"/>
/// </summary> /// </summary>
/// <typeparam name="T">The type of data to export</typeparam> /// <typeparam name="T">The type of data to export</typeparam>
/// <param name="obj">The object to export</param> /// <param name="obj">The object to export</param>
/// <param name="pathToExport">The path containing the name of the file created.</param> /// <param name="pathToExport">The path containing the name of the file created.</param>
public void Export<T>(T obj, string pathToExport) public void Export<T>(T obj, string pathToExport)
where T : class where T : class
=> Serializer.Export<T>(obj, pathToExport); => Serializer.Export<T>(obj, pathToExport);
/// <summary> /// <summary>
/// Get all the recipe from the data. /// Get all the recipe from the data.
/// </summary> /// </summary>
/// <param name="rcTitle">The title to give for the Recipe Collection</param> /// <param name="rcTitle">The title to give for the Recipe Collection</param>
/// <returns>A RecipeCollection that contain all the recipe in the data.</returns> /// <returns>A RecipeCollection that contain all the recipe in the data.</returns>
public RecipeCollection GetRecipes(string rcTitle = "default") public RecipeCollection GetRecipes(string rcTitle = "default")
=> new RecipeCollection(rcTitle, Data[nameof(Recipe)].Cast<Recipe>().ToArray()); => new RecipeCollection(rcTitle, Data[nameof(Recipe)].Cast<Recipe>().ToArray());
/// <summary> /// <summary>
/// Get all the Users from the data. /// Get all the Users from the data.
/// </summary> /// </summary>
/// <returns>A list of all Users.</returns> /// <returns>A list of all Users.</returns>
public List<User> GetUsers() public List<User> GetUsers()
=> new List<User>(Data[nameof(User)].Cast<User>()); => new List<User>(Data[nameof(User)].Cast<User>());
/// <summary> /// <summary>
/// Get a list of an item in the data. /// Get a list of an item in the data.
/// </summary> /// </summary>
/// <typeparam name="T">The type of the item</typeparam> /// <typeparam name="T">The type of the item</typeparam>
/// <returns>The list of all the item found in the data.</returns> /// <returns>The list of all the item found in the data.</returns>
public ICollection<T> GetFromData<T>() where T : class public ICollection<T> GetFromData<T>() where T : class
=> new List<T>(Data[typeof(T).Name].Cast<T>()); => new List<T>(Data[typeof(T).Name].Cast<T>());
#endregion #endregion
} }
} }

@ -16,6 +16,9 @@ namespace Model
#region Attributes #region Attributes
[DataMember(Name = "title")] [DataMember(Name = "title")]
private string _title = ""; private string _title = "";
[DataMember(Name = "image")]
private string _image = "";
#endregion #endregion
#region Properties #region Properties
@ -54,11 +57,26 @@ namespace Model
} }
/// <summary> /// <summary>
/// The image of the recipe. <br/>
/// Set to "room_service_icon.png" when the value passed is null, empty or contain white space.
/// </summary>
public string? Image
{
get => _image;
set
{
if (!string.IsNullOrWhiteSpace(value))
_image = "room_service_icon.png";
_image = value;
}
}
/// The list of ingredients. /// The list of ingredients.
/// </summary> /// </summary>
[DataMember(Name = "ingredient")] [DataMember(Name = "ingredient")]
public List<Ingredient> Ingredients { get; set; } public List<Ingredient> Ingredients { get; set; }
/// <summary> /// <summary>
/// The steps of the preparation. See: <see cref="PreparationStep"/>. /// The steps of the preparation. See: <see cref="PreparationStep"/>.
/// </summary> /// </summary>
@ -72,14 +90,17 @@ namespace Model
/// </summary> /// </summary>
/// <param _name="title">The title of the recipe</param> /// <param _name="title">The title of the recipe</param>
/// <param _name="id">The id of the recipe. If not given, get a new id.</param> /// <param _name="id">The id of the recipe. If not given, get a new id.</param>
/// <param _name="authorMail">The name of the user that create this recipe.</param>
/// <param _name="picture"> The image that represent the recipe</param>
/// <param _name="reviews">Thr list of reviews.</param> /// <param _name="reviews">Thr list of reviews.</param>
/// <param _name="ingredients">Thr list of ingredients.</param> /// <param _name="ingredients">Thr list of ingredients.</param>
/// <param _name="preparationSteps">The steps of the preparation of the meal</param> /// <param _name="preparationSteps">The steps of the preparation of the meal</param>
public Recipe(string title, int? id, string? authorMail, public Recipe(string title, int? id, string? authorMail, string? picture,
List<Review> reviews, List<Ingredient> ingredients, List<Review> reviews, List<Ingredient> ingredients,
params PreparationStep[] preparationSteps) params PreparationStep[] preparationSteps)
{ {
Title = title; Title = title;
Image = picture;
PreparationSteps = new List<PreparationStep>(preparationSteps); PreparationSteps = new List<PreparationStep>(preparationSteps);
Ingredients = ingredients; Ingredients = ingredients;
Reviews = reviews; Reviews = reviews;
@ -95,47 +116,18 @@ namespace Model
else Id = (int)id; else Id = (int)id;
} }
/// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary>
/// <param _name="title">The title of the recipe.</param>
public Recipe(string title)
: this(title, null, null, new List<Review>(), new List<Ingredient>())
{
}
/// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary>
/// <param _name="title">The title of the recipe.</param>
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, params PreparationStep[] preparationSteps)
: this(title, null, null, new List<Review>(), new List<Ingredient>(), preparationSteps)
{
}
/// <summary> /// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/> /// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary> /// </summary>
/// <param _name="title">The title of the recipe.</param> /// <param _name="title">The title of the recipe.</param>
/// <param _name="id">The id of the recipe. If not given, get a new id.</param> /// <param _name="id">The id of the recipe. If not given, get a new id.</param>
/// <param _name="authorMail">Mail of the user that create the recipe</param>
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param> /// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, int? id, params PreparationStep[] preparationSteps) public Recipe(string title, int? id, string? authorMail, params PreparationStep[] preparationSteps)
: this(title, id, null, new List<Review>(), new List<Ingredient>(), preparationSteps) : this(title, id, authorMail, null, new List<Review>(), new List<Ingredient>(), preparationSteps)
{ {
}
/// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary>
/// <param _name="title">The title of the recipe.</param>
/// <param _name="id">The id of the recipe. If not given, get a new id.</param>
/// <param _name="ingredients">Thr list of ingredients.</param>
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, int? id, List<Ingredient> ingredients,
params PreparationStep[] preparationSteps)
: this(title, id, null, new List<Review>(), ingredients, preparationSteps)
{
} }
/// <summary> /// <summary>
@ -143,22 +135,27 @@ namespace Model
/// </summary> /// </summary>
/// <param _name="title">The title of the recipe.</param> /// <param _name="title">The title of the recipe.</param>
/// <param _name="id">The id of the recipe. If not given, get a new id.</param> /// <param _name="id">The id of the recipe. If not given, get a new id.</param>
/// <param _name="authorMail">Mail of the user that create the recipe</param>
/// <param _name="picture">Mail of the user that create the recipe</param>
/// <param _name="ingredients">List of ingredients that compose the recipe. </param>
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param> /// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
public Recipe(string title, int? id, string? authorMail, List<Ingredient> ingredients, params PreparationStep[] preparationSteps) public Recipe(string title, int? id, string? authorMail, string? picture, List<Ingredient> ingredients, params PreparationStep[] preparationSteps)
: this(title, id, authorMail, new List<Review>(), ingredients, preparationSteps) : this(title, id, authorMail, picture, new List<Review>(), ingredients, preparationSteps)
{ {
} }
/// <summary> ///// <summary>
/// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/> ///// <inheritdoc cref="Recipe.Recipe(string, int?, List{Review}, PreparationStep[])"/>
/// </summary> ///// </summary>
/// <param _name="title">The title of the recipe.</param> ///// <param _name="title">The title of the recipe.</param>
/// <param _name="id">The id of the recipe. If not given, get a new id.</param> ///// <param _name="id">The id of the recipe. If not given, get a new id.</param>
/// <param _name="preparationSteps">The steps of the preparation of the meal.</param> ///// <param _name="picture">Image that reppresent the recipe.</param>
public Recipe(string title, int? id, string? authorMail, params PreparationStep[] preparationSteps) ///// <param _name="preparationSteps">The steps of the preparation of the meal.</param>
: this(title, id, authorMail, new List<Review>(), new List<Ingredient>(), preparationSteps) //public Recipe(string title, int? id, string picture, params PreparationStep[] preparationSteps)
{ // : this(title, id, null, picture, new List<Review>(), new List<Ingredient>(), preparationSteps)
} //{
//}
#endregion #endregion
#region Methods #region Methods

@ -3,8 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using DataPersistence;
using Model; using Model;
using Model.Managers;
namespace Model_UnitTests namespace Model_UnitTests
{ {
@ -13,18 +14,12 @@ namespace Model_UnitTests
[Fact] [Fact]
public void TestResearchByName() public void TestResearchByName()
{ {
RecipeCollection recipes = new RecipeCollection( MasterManager masterManager = new MasterManager(new Stubs());
description: "test recipe", RecipeCollection recipes = masterManager.DataMgr.GetRecipes("test rc");
recipes: new[]
{
new Recipe(title: "Gateau à la crème"),
new Recipe(title: "Gateau au chocolat"),
new Recipe(title: "Gateau aux cerises")
});
Recipe? search_result = recipes.ResearchByName("chocolat").FirstOrDefault(); Recipe? search_result = recipes.ResearchByName("chocolat").FirstOrDefault();
Assert.NotNull(search_result); Assert.NotNull(search_result);
Assert.Equal("Gateau au chocolat", search_result.Title); Assert.Equal("Cookies au chocolat", search_result.Title);
} }
} }
} }

@ -7,7 +7,10 @@ namespace Model_UnitTests
[Fact] [Fact]
public void TestVoidConstructor() public void TestVoidConstructor()
{ {
Recipe r = new Recipe(""); // id is given to avoid tests errors with the static atrribute 'idCreator'. Recipe r = new Recipe(
title: "test recipe",
id: null,
authorMail: "test@test.fr");
Assert.NotNull(r.Title); Assert.NotNull(r.Title);
} }
} }

@ -0,0 +1,80 @@
<?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"
x:Class="Views.AddRecipe"
Title="AddRecipe"
xmlns:local="clr-namespace:Views">
<VerticalStackLayout>
<local:MiniHeader
TitleMini="Ajouter une recette"
NeedReturn="True"
HeightRequest="100"/>
<Grid ColumnDefinitions="auto, *"
RowDefinitions="auto,auto,auto,auto,auto,auto, auto, auto, auto"
Margin="50,20,20,20">
<Label Text="Titre de la recette :"/>
<Entry Placeholder="Saisie du texte de la recette correspondante"
Grid.Row="1"
Margin="10"/>
<Label Text="Type de la recette" Grid.Row="2"/>
<CheckBox x:Name="CheckEntree" Grid.Row="3" Margin="10,0,20,0" />
<Label Text="Entrée" Grid.Row="3" Margin="40,20"/>
<CheckBox x:Name="CheckPlat" Grid.Row="3" Margin="90,0" />
<Label Text="Plat" Grid.Row="3" Margin="120,20"/>
<CheckBox x:Name="CheckDessert" Grid.Row="3" Margin="155,0" />
<Label Text="Dessert" Grid.Row="3" Margin="185,20"/>
<Label Text="Type de priorité" Grid.Row="4"/>
<Grid BackgroundColor="#D1E8E2"
MinimumHeightRequest="100"
MaximumWidthRequest="300"
Padding="20"
Grid.Row="5">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Text="Recettes économiques" Grid.Row="0" Padding="5,0,0,0"/>
<BoxView Color="Black" HeightRequest="1" Margin="10,10,10,10" Grid.Row="1" />
<Label Text="Recettes rapides" Grid.Row="2"/>
<BoxView Color="Black" HeightRequest="1" Margin="10,10,10,10" Grid.Row="3" />
<Label Text="Recettes simples" Grid.Row="4"/>
<BoxView Color="Black" HeightRequest="1" Margin="10,10,10,10" Grid.Row="5" />
<Label Text="Recettes légères" Grid.Row="6"/>
<BoxView Color="Black" HeightRequest="1" Margin="10,10,10,10" Grid.Row="7" />
<Label Text="Recettes gourmandes" Grid.Row="8"/>
</Grid>
<Label Text="Saisir les étapes de la recette " Grid.Row="6" Margin="0,15"/>
<Entry Placeholder="Etape de la recette" Grid.Row="7" Margin="12,0"/>
<HorizontalStackLayout Grid.Row="8" Margin="20">
<Button WidthRequest="100" Text="Précédent" TextColor="Black" Margin="20,0,20,0"/>
<Button WidthRequest="100" Text="Ajouter" TextColor="Black" Margin="20,0"/>
</HorizontalStackLayout>
<Label Text="Saisir les ingrédients de la recette" Grid.Row="6" Grid.Column="1" Margin="50,15"/>
<HorizontalStackLayout Grid.Row="7" Grid.Column="1">
<Entry Placeholder="Nom de l'ingrédient" Margin="12,0,50,0" WidthRequest="500"/>
<Picker Title="Unité">
</Picker>
</HorizontalStackLayout>
<HorizontalStackLayout Grid.Row="8" Grid.Column="1" Margin="20">
<Button WidthRequest="100" Text="Précédent" TextColor="Black" Margin="20,0,20,0"/>
<Button WidthRequest="100" Text="Ajouter" TextColor="Black" Margin="20,0"/>
</HorizontalStackLayout>
</Grid>
</VerticalStackLayout>
</ContentPage>

@ -0,0 +1,18 @@
using CommunityToolkit.Maui.Behaviors;
using DataPersistence;
using Model;
using Model.Managers;
using System.Diagnostics;
namespace Views
{
public partial class AddRecipe : ContentPage
{
public MasterManager MasterMgr => (App.Current as App).MasterMgr;
public AddRecipe()
{
InitializeComponent();
}
}
}

@ -1,7 +1,7 @@
<?xml version = "1.0" encoding = "UTF-8" ?> <?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Vue" xmlns:local="clr-namespace:Views"
x:Class="Views.App"> x:Class="Views.App">
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>

@ -6,38 +6,49 @@ using Windows.Graphics;
using DataPersistence; using DataPersistence;
using Model; using Model;
using System.Collections.ObjectModel;
using Model.Managers;
namespace Views namespace Views
{ {
public partial class App : Application public partial class App : Application
{ {
public DataManager DataMgr { get; private set; } = new DataManager(new Stubs()); //Point d'entrée de l'application
public User user { get; set; } public MasterManager MasterMgr { get; private set; } = new MasterManager(new Stubs());
const int WindowWidth = 1200;
const int WindowHeight = 800; //L'utilisateur courant de l'application
public User CurrentUser { get; set; }
//collection de recette de l'application
public RecipeCollection AllRecipes { get; set; }
//const int WindowWidth = 1200;
//const int WindowHeight = 800;
public App() public App()
{ {
user = DataMgr.Data[nameof(User)].Cast<User>().Last(); CurrentUser = MasterMgr.DataMgr.GetUsers().Last();
AllRecipes = MasterMgr.DataMgr.GetRecipes("All recipes");
InitializeComponent(); InitializeComponent();
Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) => // Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>
{ // {
#if WINDOWS //#if WINDOWS
var mauiWindow = handler.VirtualView; // var mauiWindow = handler.VirtualView;
var nativeWindow = handler.PlatformView; // var nativeWindow = handler.PlatformView;
nativeWindow.Activate(); // nativeWindow.Activate();
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(nativeWindow); // IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(nativeWindow);
WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle); // WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId); // AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
appWindow.Resize(new SizeInt32(WindowWidth, WindowHeight)); // appWindow.Resize(new SizeInt32(WindowWidth, WindowHeight));
#endif //#endif
}); // });
/* - Comment(ctrl-k + ctrl-c)/Uncomment(ctrl-k + ctrl-u) to change page - */ /* - Comment(ctrl-k + ctrl-c)/Uncomment(ctrl-k + ctrl-u) to change page - */
UserAppTheme = AppTheme.Light; UserAppTheme = AppTheme.Light;
MainPage = new AddRecipe(); MainPage = new Home();
//MainPage = new MyPosts(); //MainPage = new MyPosts();
} }
} }

@ -1,13 +1,13 @@
using DataPersistence; using DataPersistence;
using Model; using Model;
using Model.Managers;
namespace Views; namespace Views;
public partial class ContainerFlyout : ContentView public partial class ContainerFlyout : ContentView
{ {
public DataManager DataMgr => (App.Current as App).DataMgr; public MasterManager MasterMgr => (App.Current as App).MasterMgr;
public User user => (App.Current as App).user; public User user => (App.Current as App).CurrentUser;
public ContainerFlyout() public ContainerFlyout()
{ {

@ -1,66 +1,107 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:local="clr-namespace:Views" xmlns:local="clr-namespace:Views"
x:Class="Views.Home"> xmlns:model="clr-namespace:Model;assembly=Model"
x:Class="Views.Home">
<local:ContainerBase
IsNotConnected="True"> <local:ContainerBase
IsNotConnected="True">
<!-- Flyout -->
<local:ContainerBase.MyFlyoutContent> <!-- Flyout -->
<VerticalStackLayout Grid.Row="1"> <local:ContainerBase.MyFlyoutContent>
<!-- Research --> <VerticalStackLayout Grid.Row="1">
<Button Text="Recherche" ImageSource="search_icon.png" <!-- Research -->
MaximumHeightRequest="20" <Button
Style="{StaticResource button1}"/> Text="Recherche"
<SearchBar Placeholder="Mots-clés (ex.: rapide, fromage)" FontAttributes="Italic" TextColor="Black" ImageSource="search_icon.png"
BackgroundColor="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Gray300}}" MaximumHeightRequest="20"
Margin="15, 10, 15, 40"/> Style="{StaticResource button1}"/>
<SearchBar
<!-- Direct research --> Placeholder="Mots-clés (ex.: rapide, fromage)"
<Button Text="Entrées" ImageSource="flatware_icon.png" FontAttributes="Italic" TextColor="Black"
Style="{StaticResource button1}"/> BackgroundColor="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Gray300}}"
<Button Text="Plats" ImageSource="room_service_icon.png" Margin="15, 10, 15, 40"/>
Style="{StaticResource button1}"/>
<Button Text="Desserts" ImageSource="coffee_icon.png" <!-- Direct research -->
Style="{StaticResource button1}"/> <Button
</VerticalStackLayout> Text="Entrées"
</local:ContainerBase.MyFlyoutContent> ImageSource="flatware_icon.png"
Style="{StaticResource button1}"/>
<!-- Master --> <Button
<local:ContainerBase.MyContent> Text="Plats"
<ScrollView> ImageSource="room_service_icon.png"
<StackLayout> Style="{StaticResource button1}"/>
<Label Text="Suggestions" TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource Gray100}}" <Button
FontSize="24" Padding="15"/> Text="Desserts"
ImageSource="coffee_icon.png"
<FlexLayout Style="{StaticResource button1}"/>
Margin="0, 15" </VerticalStackLayout>
Wrap="Wrap" </local:ContainerBase.MyFlyoutContent>
JustifyContent="Start"
AlignItems="Center" <!-- Master -->
AlignContent="SpaceEvenly" <local:ContainerBase.MyContent>
HorizontalOptions="Center"> <ScrollView>
<StackLayout BindingContext="{Binding AllRecipes}" MinimumWidthRequest="400">
<local:RecipeCase CaseImageSource="room_service_icon.png"/> <!--Modification du prof apportée sur le stacklayout pour empecher l'affichage d'une seule case recipe-->
<local:RecipeCase CaseImageSource="room_service_icon.png"/> <Label
<local:RecipeCase CaseImageSource="room_service_icon.png"/> Text="{Binding Description}"
<local:RecipeCase CaseImageSource="room_service_icon.png"/> TextColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource Gray100}}"
<local:RecipeCase CaseImageSource="room_service_icon.png"/> FontSize="24"
<local:RecipeCase CaseImageSource="room_service_icon.png"/> Padding="15"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/> <FlexLayout
<local:RecipeCase CaseImageSource="room_service_icon.png"/> Margin="0, 15"
<local:RecipeCase CaseImageSource="room_service_icon.png"/> Wrap="Wrap"
<local:RecipeCase CaseImageSource="room_service_icon.png"/> JustifyContent="Start"
AlignItems="Center"
</FlexLayout> AlignContent="SpaceEvenly"
</StackLayout> HorizontalOptions="Center"
</ScrollView> BindableLayout.ItemsSource="{Binding}">
</local:ContainerBase.MyContent>
<BindableLayout.ItemTemplate>
</local:ContainerBase> <DataTemplate x:DataType="model:Recipe">
<Border Style="{StaticResource recipeCase}">
</ContentPage> <Grid RowDefinitions="*, 40">
<!--<local:RecipeCase
CaseImageSource="room_service_icon.png"
Title="{Binding Title}"/>-->
<Image
Grid.Row="0" VerticalOptions="Fill"
Source="{Binding Image}"/>
<Label
Text="{Binding Title}" FontSize="18"
Grid.Row="1" HorizontalOptions="Center"/>
</Grid>
</Border>
</DataTemplate>
</BindableLayout.ItemTemplate>
<!--<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"/>
<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"/>
<local:RecipeCase CaseImageSource="room_service_icon.png"/>-->
</FlexLayout>
</StackLayout>
</ScrollView>
</local:ContainerBase.MyContent>
</local:ContainerBase>
</ContentPage>

@ -1,10 +1,22 @@
namespace Views using DataPersistence;
{ using Model;
public partial class Home : ContentPage using Model.Managers;
{
public Home() namespace Views
{ {
InitializeComponent(); public partial class Home : ContentPage
} {
} public MasterManager MasterMgr => (App.Current as App).MasterMgr;
} public User user => (App.Current as App).CurrentUser;
public RecipeCollection AllRecipes => (App.Current as App).AllRecipes;
public Home()
{
//DataMgr = new DataManager(new Stubs());
//AllRecipes = new RecipeCollection("Toutes les recettes", DataMgr.Data[nameof(Recipe)].Cast<Recipe>().ToArray());
InitializeComponent();
BindingContext = this;
}
}
}

@ -38,26 +38,20 @@
FontSize="18"/> FontSize="18"/>
<Entry BackgroundColor="#D1E8E2" <Entry BackgroundColor="#D1E8E2"
Margin="50,10,0,20" Margin="50,10,0,20"
Text="{Binding userBis.Name}"/> Text="{Binding CurrentUser.Name}"/>
<Label Text="Prénom :" <Label Text="Prénom :"
Padding="50,0,0,0" Padding="50,0,0,0"
FontSize="18"/> FontSize="18"/>
<Entry BackgroundColor="#D1E8E2" <Entry BackgroundColor="#D1E8E2"
Margin="50,10,0,20" Margin="50,10,0,20"
Text="{Binding userBis.Surname} "/> Text="{Binding CurrentUser.Surname} "/>
<Label Text="Mail :" <Label Text="Mail :"
Padding="50,0,0,0" Padding="50,0,0,0"
FontSize="18"/> FontSize="18"/>
<Entry BackgroundColor="#D1E8E2" <Entry BackgroundColor="#D1E8E2"
Margin="50,10,0,20" Margin="50,10,0,20"
IsEnabled="False" IsEnabled="False"
Text="{Binding user.Mail}"/> Text="{Binding CurrentUser.Mail}"/>
<Button BackgroundColor="#bdf5bd"
Text="Modifier"
Margin="40,0,0,0"
TextColor="Black"
MaximumWidthRequest="100"
Clicked="Validation_Click"/>
<!--liste drag and drop--> <!--liste drag and drop-->
</VerticalStackLayout> </VerticalStackLayout>
<VerticalStackLayout Padding="100,0,0,0"> <VerticalStackLayout Padding="100,0,0,0">

@ -1,31 +1,20 @@
using CommunityToolkit.Maui.Behaviors; using CommunityToolkit.Maui.Behaviors;
using DataPersistence; using DataPersistence;
using Model; using Model;
using Model.Managers;
using System.Diagnostics; using System.Diagnostics;
namespace Views; namespace Views;
public partial class MyProfil : ContentPage public partial class MyProfil : ContentPage
{ {
public DataManager DataMgr => (App.Current as App).DataMgr; public MasterManager MasterMgr => (App.Current as App).MasterMgr;
public User user => (App.Current as App).user; public User user => (App.Current as App).CurrentUser;
public User userBis {get; set; }
public MyProfil() public MyProfil()
{ {
userBis = new User(user);
InitializeComponent(); InitializeComponent();
BindingContext = this; BindingContext = this;
} }
public void Validation_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(userBis.Name) || String.IsNullOrEmpty(userBis.Surname)){
return;
}
user.Name = userBis.Name;
user.Surname = userBis.Surname;
}
} }
Loading…
Cancel
Save