78 lines
1.9 KiB
C#
78 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
using Android.App;
|
|
using Android.Content;
|
|
using Android.OS;
|
|
using Android.Runtime;
|
|
using Android.Views;
|
|
using Android.Widget;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Eat.Models
|
|
{
|
|
class Meal : Product
|
|
{
|
|
[JsonProperty]
|
|
internal List<Tuple<Product, double>> Products { get; private set; } = new List<Tuple<Product, double>>();
|
|
[JsonProperty]
|
|
public int PrepTime
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
public Meal(string name, int prepTime)
|
|
{
|
|
Name = name;
|
|
PrepTime = prepTime;
|
|
}
|
|
|
|
public Meal(string name, int prepTime, List<Tuple<Product, double>> products)
|
|
{
|
|
Name = name;
|
|
PrepTime = prepTime;
|
|
Products = products;
|
|
}
|
|
|
|
public void AddProduct(Product product)
|
|
{
|
|
Products.Add(new Tuple<Product, double>(product, 1.0f));
|
|
}
|
|
|
|
public void AddProduct(Product product, double ratio)
|
|
{
|
|
Products.Add(new Tuple<Product, double>(product, ratio));
|
|
}
|
|
|
|
public override void CalculateElements()
|
|
{
|
|
Cost = 0.0;
|
|
Kcal = 0;
|
|
Fat = Carbs = Protein = 0.0;
|
|
|
|
foreach (var product in Products)
|
|
{
|
|
Cost += product.Item1.Cost;
|
|
Kcal += Convert.ToInt32(product.Item1.Kcal * product.Item2);
|
|
Fat += product.Item1.Fat * product.Item2;
|
|
Carbs += product.Item1.Carbs * product.Item2;
|
|
Protein += product.Item1.Protein * product.Item2;
|
|
}
|
|
}
|
|
|
|
public string GetProducts()
|
|
{
|
|
string result = "";
|
|
foreach (var product in Products)
|
|
{
|
|
result += product.Item1.Name + " ";
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
} |