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

57 lines
1.6 KiB
C#
Raw Normal View History

2022-08-13 05:32:57 +03:00
using System;
using System.ComponentModel.DataAnnotations;
namespace BlueWest.Data;
public class MathOperation
{
[Key] public TimeSpan CreationDate { get; set; }
public MathOperationType MathOperationType { get; }
public double LeftAmount { get; }
public double RightAmount { get; }
public string MathOperationDescription { get; }
private bool _isCalculated = false;
private double _resultingAmount;
public double ResultingAmount
{
get
{
if (_isCalculated) return _resultingAmount;
return 0;
}
}
public MathOperation() { }
public MathOperation(MathOperationType mathOperationType, double leftAmount, double rightAmount, string mathOperationDescription)
{
MathOperationType = mathOperationType;
LeftAmount = leftAmount;
RightAmount = rightAmount;
MathOperationDescription = mathOperationDescription;
}
public void Calculate()
{
_isCalculated = true;
switch (MathOperationType)
{
case MathOperationType.Add:
_resultingAmount = LeftAmount + RightAmount;
return;
case MathOperationType.Div:
_resultingAmount = LeftAmount / RightAmount;
return;
case MathOperationType.Mul:
_resultingAmount = LeftAmount * RightAmount;
return;
case MathOperationType.Sub:
_resultingAmount = LeftAmount - RightAmount;
return;
}
}
}