CodeLiturgy.Dashboard/BlueWest.Data/Finance/MathOperation.cs

38 lines
843 B
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using SimpleExpressionEvaluator;
namespace BlueWest.Data;
public class MathOperation
{
[Key] public TimeSpan CreationDate { get; set; }
private bool _isCalculated = false;
private string _expression;
private decimal _resultingAmount;
private ExpressionEvaluator _expressionEvaluator = new ExpressionEvaluator();
public decimal ResultingAmount
{
get
{
if (_isCalculated) return _resultingAmount;
return 0;
}
}
public MathOperation() { }
public MathOperation(string expression, Dictionary<string, decimal> letters)
{
_resultingAmount = _expressionEvaluator.Evaluate(expression, letters);
_isCalculated = true;
}
}