zprp/Models/Product.cs

89 lines
1.8 KiB
C#
Raw Normal View History

2018-12-01 14:28:52 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
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 Product
{
[JsonProperty]
public string Name
{
get; protected set;
}
[JsonProperty]
public double Cost
{
get; protected set;
}
[JsonProperty]
public int Kcal
{
get; protected set;
}
[JsonProperty]
public double Fat
{
get; protected set;
}
[JsonProperty]
public double Carbs
{
get; protected set;
}
[JsonProperty]
public double Protein
{
get; protected set;
}
// Make sure they are always written in lowercase
[JsonProperty]
public List<string> Tags
{
get; protected set;
} = new List<string>();
public Product()
{
Name = "Unknown";
}
public Product(string name, double cost, double fat, double carbs, double protein, List<string> tags)
{
Name = name;
Cost = cost;
Kcal = Convert.ToInt32((fat * 9) + (carbs * 4) + (protein * 4));
Fat = fat;
Carbs = carbs;
Protein = protein;
Tags = tags;
}
public string Serialize()
{
return JsonConvert.SerializeObject(this);
}
public virtual void CalculateElements()
{
throw new Exception("Don't call this method from object of class Product");
}
}
}