add button all recipes, supp search button
continuous-integration/drone/push Build is passing Details

pull/65/head
Alexandre AGOSTINHO 2 years ago
parent 596e699382
commit 4b1a597f9b

@ -1,110 +1,110 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace Model
{
/// <summary>
/// Define a collection of <see cref="Recipe"/>.
/// <br/>This class is derived from <see cref="ObservableCollection{Recipe}"/>
/// and implement <see cref="IEquatable{RecipeCollection}"/> and <see cref="ICloneable"/>.
/// </summary>
public class RecipeCollection : ObservableCollection<Recipe>, IEquatable<RecipeCollection>, ICloneable
{
#region Attributes
private string _description = "";
#endregion
#region Properties
/// <summary>
/// A short description of what this collection contain. <br/>
/// Set to "No description." when the value passed is null, empty or contain white spaces.
/// </summary>
public string Description
{
get => _description;
set
{
if (string.IsNullOrWhiteSpace(value))
_description = "No description.";
else
_description = value;
}
}
#endregion
#region Constructors
/// <summary>
/// Construct a new collection of _recipes.
/// </summary>
/// <param _name="description">A short description of what this list will contain</param>
/// <param _name="recipes">Recipes to add in this new collection</param>
public RecipeCollection(string description, params Recipe[] recipes)
: base(recipes)
{
Description = description;
}
#endregion
#region Methods
/// <summary>
/// Find a recipe in this list by giving the id.
/// </summary>
/// <param _name="id">The id of the list we are looking for</param>
/// <returns>The recipe of the id given</returns>
/// <exception cref="ArgumentException"/>
public Recipe? GetRecipeById(int id)
{
Recipe? recipe = this.ToList().Find(r => r.Id == id);
if (recipe == null) throw new ArgumentException("No _recipes match the given id.");
return recipe;
}
/// <summary>
/// Utility to find a recipe by his _name.
/// </summary>
/// <param _name="str">The string for the search</param>
/// <returns>A collection of Recipe where their Title contain the string.</returns>
public RecipeCollection ResearchByName(string str)
{
if (string.IsNullOrEmpty(str))
return this;
return new RecipeCollection(
description: $"Results of the research: {str}",
recipes: this.ToList().FindAll(x => x.Title.ToLower().Contains(str.ToLower())).ToArray());
}
public virtual bool Equals(RecipeCollection? other)
{
if (other == null) return false;
if (other == this) return true;
return this.Description.Equals(other.Description);
}
public override bool Equals(object? obj)
{
var item = obj as RecipeCollection;
if (item == null) return false;
return Equals(obj);
}
public override int GetHashCode()
{
return Description.GetHashCode();
}
public override string ToString()
{
StringBuilder sb = new StringBuilder($"[RecipeCollection] - {Description}:\n");
foreach (Recipe r in this)
{
sb.AppendFormat("\t - {0}\n", r.ToString());
}
return sb.ToString();
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace Model
{
/// <summary>
/// Define a collection of <see cref="Recipe"/>.
/// <br/>This class is derived from <see cref="ObservableCollection{Recipe}"/>
/// and implement <see cref="IEquatable{RecipeCollection}"/> and <see cref="ICloneable"/>.
/// </summary>
public class RecipeCollection : ObservableCollection<Recipe>, IEquatable<RecipeCollection>, ICloneable
{
#region Attributes
private string _description = "";
#endregion
#region Properties
/// <summary>
/// A short description of what this collection contain. <br/>
/// Set to "No description." when the value passed is null, empty or contain white spaces.
/// </summary>
public string Description
{
get => _description;
set
{
if (string.IsNullOrWhiteSpace(value))
_description = "No description.";
else
_description = value;
}
}
#endregion
#region Constructors
/// <summary>
/// Construct a new collection of _recipes.
/// </summary>
/// <param _name="description">A short description of what this list will contain</param>
/// <param _name="recipes">Recipes to add in this new collection</param>
public RecipeCollection(string description, params Recipe[] recipes)
: base(recipes)
{
Description = description;
}
#endregion
#region Methods
/// <summary>
/// Find a recipe in this list by giving the id.
/// </summary>
/// <param _name="id">The id of the list we are looking for</param>
/// <returns>The recipe of the id given</returns>
/// <exception cref="ArgumentException"/>
public Recipe? GetRecipeById(int id)
{
Recipe? recipe = this.ToList().Find(r => r.Id == id);
if (recipe == null) throw new ArgumentException("No _recipes match the given id.");
return recipe;
}
/// <summary>
/// Utility to find a recipe by his _name.
/// </summary>
/// <param _name="str">The string for the search</param>
/// <returns>A collection of Recipe where their Title contain the string.</returns>
public RecipeCollection ResearchByName(string str)
{
if (string.IsNullOrEmpty(str))
return this;
return new RecipeCollection(
description: $"Results of the research: {str}",
recipes: this.ToList().FindAll(x => x.Title.ToLower().Contains(str.ToLower())).ToArray());
}
public virtual bool Equals(RecipeCollection? other)
{
if (other == null) return false;
if (other == this) return true;
return this.Description.Equals(other.Description);
}
public override bool Equals(object? obj)
{
var item = obj as RecipeCollection;
if (item == null) return false;
return Equals(obj);
}
public override int GetHashCode()
{
return Description.GetHashCode();
}
public override string ToString()
{
StringBuilder sb = new StringBuilder($"[RecipeCollection] - {Description}:\n");
foreach (Recipe r in this)
{
sb.AppendFormat("\t - {0}\n", r.ToString());
}
return sb.ToString();
}
public object Clone()
@ -113,6 +113,6 @@ namespace Model
description: this.Description,
recipes: this.ToArray());
}
#endregion
}
}
#endregion
}
}

@ -15,11 +15,9 @@
<local:ContainerBase.MyFlyoutContent>
<VerticalStackLayout Grid.Row="1">
<!-- Research -->
<Button
Text="Recherche"
ImageSource="search_icon.png"
MaximumHeightRequest="20"
Style="{StaticResource button1}"/>
<Label
Text="Recherche de recettes :" FontSize="14"
Margin="20, 10, 15, 0"/>
<SearchBar
Placeholder="Mots-clés (ex.: rapide, fromage)"
FontAttributes="Italic" TextColor="Black"
@ -28,6 +26,11 @@
SearchButtonPressed="SearchBar_SearchButtonPressed"/>
<!-- Direct research -->
<Button
Text="Toutes les recettes"
ImageSource="home_icon.png"
Style="{StaticResource button1}"
Clicked="AllRecipes_Clicked"/>
<Button
Text="Entrées"
ImageSource="flatware_icon.png"
@ -36,11 +39,13 @@
<Button
Text="Plats"
ImageSource="room_service_icon.png"
Style="{StaticResource button1}"/>
Style="{StaticResource button1}"
Clicked="Plats_Clicked"/>
<Button
Text="Desserts"
ImageSource="coffee_icon.png"
Style="{StaticResource button1}"/>
Style="{StaticResource button1}"
Clicked="Desserts_Clicked"/>
</VerticalStackLayout>
</local:ContainerBase.MyFlyoutContent>

@ -57,6 +57,7 @@ namespace Views
private void ModifyRecipesDisplayed(RecipeCollection recipes)
{
_recipesDisplayed.Clear();
_recipesDisplayed.Description = recipes.Description;
foreach (Recipe recipe in recipes)
{
_recipesDisplayed.Add(recipe);
@ -76,7 +77,22 @@ namespace Views
private void Entrees_Clicked(object sender, EventArgs e)
{
return;
ModifyRecipesDisplayed(new RecipeCollection("Entrées", AllRecipe.ToList().FindAll(r => r.Type == RecipeType.Starter).ToArray()));
}
private void Plats_Clicked(object sender, EventArgs e)
{
ModifyRecipesDisplayed(new RecipeCollection("Plats", AllRecipe.ToList().FindAll(r => r.Type == RecipeType.Dish).ToArray()));
}
private void Desserts_Clicked(object sender, EventArgs e)
{
ModifyRecipesDisplayed(new RecipeCollection("Desserts", AllRecipe.ToList().FindAll(r => r.Type == RecipeType.Dessert).ToArray()));
}
private void AllRecipes_Clicked(object sender, EventArgs e)
{
ModifyRecipesDisplayed(AllRecipe);
}
}
}

Loading…
Cancel
Save