CodeLiturgy.Dashboard/BlueWest.Data.Capital/Transaction/MathOperation.cs

38 lines
843 B
C#
Raw Normal View History

2022-08-13 05:32:57 +03:00
using System;
2022-08-13 05:59:37 +03:00
using System.Collections.Generic;
2022-08-13 05:32:57 +03:00
using System.ComponentModel.DataAnnotations;
2022-08-13 05:59:37 +03:00
using SimpleExpressionEvaluator;
2022-08-13 05:32:57 +03:00
namespace BlueWest.Data;
public class MathOperation
{
[Key] public TimeSpan CreationDate { get; set; }
private bool _isCalculated = false;
2022-08-13 05:59:37 +03:00
private string _expression;
private decimal _resultingAmount;
private ExpressionEvaluator _expressionEvaluator = new ExpressionEvaluator();
2022-08-13 05:32:57 +03:00
2022-08-13 05:59:37 +03:00
public decimal ResultingAmount
2022-08-13 05:32:57 +03:00
{
get
{
if (_isCalculated) return _resultingAmount;
return 0;
}
}
public MathOperation() { }
2022-08-13 05:59:37 +03:00
public MathOperation(string expression, Dictionary<string, decimal> letters)
2022-08-13 05:32:57 +03:00
{
2022-08-13 05:59:37 +03:00
_resultingAmount = _expressionEvaluator.Evaluate(expression, letters);
2022-08-13 05:32:57 +03:00
_isCalculated = true;
}
2022-08-13 05:59:37 +03:00
2022-08-13 05:32:57 +03:00
}