You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.2 KiB
81 lines
2.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
|
|
namespace Model
|
|
{
|
|
|
|
public class Recipe : IEquatable<Recipe>
|
|
{
|
|
#region Attributes
|
|
private static int idCreator = 0;
|
|
private string? _title;
|
|
private string? _description;
|
|
#endregion
|
|
|
|
#region Properties
|
|
public int Id { get; init; }
|
|
public string? Title
|
|
{
|
|
get => _title;
|
|
set
|
|
{
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
_title = "No title.";
|
|
else
|
|
_title = value;
|
|
}
|
|
}
|
|
public string? Description
|
|
{
|
|
get => _description;
|
|
set
|
|
{
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
_description = "No description.";
|
|
else
|
|
_description = value;
|
|
}
|
|
}
|
|
public List<PreparationStep>? PreparationSteps { get; private set; }
|
|
#endregion
|
|
|
|
#region Constructors
|
|
public Recipe(string? title = null, string? description = null, int? id = null,
|
|
params PreparationStep[] preparationSteps)
|
|
{
|
|
if (id == null) Id = idCreator++;
|
|
else Id = (int)id;
|
|
Title = title;
|
|
Description = description;
|
|
PreparationSteps = new List<PreparationStep>(preparationSteps);
|
|
}
|
|
#endregion
|
|
|
|
#region Methods
|
|
public bool Equals(Recipe? other)
|
|
{
|
|
if (other == null) return false;
|
|
if (other == this) return true;
|
|
return Title.Equals(other.Title) && Description.Equals(other.Description);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return Id.GetHashCode();
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
StringBuilder sb = new StringBuilder($"[Recipe] - {Title}: {Description}\n");
|
|
foreach (PreparationStep ps in PreparationSteps)
|
|
{
|
|
sb.AppendFormat("\t* {0}\n", ps.ToString());
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|