试图将存储的条件计算转换为NHibernate
本文关键字:计算 转换 NHibernate 条件 存储 | 更新日期: 2023-09-27 18:03:16
我有很多执行条件计算的代码。用户将在UI上做出选择(下拉菜单、单选按钮等),我将根据这些选择为他们计算结果。以前,我会使用ViewBag在视图上显示计算结果。但是现在我想使用NHibernate存储这些,并且很难将其转换为存储计算结果的东西。我希望这不会需要完全重写。
这是我之前在Calculate.cs:
中所做的一个例子(一个条件的例子-注意:pricequotes .cs只是保存值):public decimal decSpouseFilingChapter7(QuoteViewModel quoteData)
{
if (quoteData.QuotePartRecord.MaritalStatusDropDown ==
MaritalStatus.Yes &&
quoteData.QuotePartRecord.SpouseFilingRadioButton ==
SpouseFiling.No)
return PriceQuote.priceNoSpouseFilingChapter7; // see below
else if (quoteData.QuotePartRecord.MaritalStatusDropDown ==
MaritalStatus.Yes &&
quoteData.QuotePartRecord.SpouseFilingRadioButton ==
SpouseFiling.Yes)
return PriceQuote.priceSpouseFilingChapter7; // see below
else
return 0;
}
pricequotes .cs会有这个(只显示两个,它包含超过100多个金额):
public static decimal priceNoSpouseFilingChapter7 { get { return 100; } }
public static decimal priceSpouseFilingChapter7 { get { return 300; } }
进一步在Calculate.cs中,在一系列条件之后,我会这样做以得出计算结果:
public decimal TotalChapter7(QuoteViewModel quoteData)
{
decimal total = PriceQuote.priceChapter7;
total += this.decSpouseFilingChapter7(quoteData);
total += this.decPaymentPlanChapter7(quoteData);
total += this.decProcessingChapter7(quoteData);
total += this.decSubmissionChapter7(quoteData);
total += this.decDistrictChapter7(quoteData);
total += this.decUnsecuredCreditor(quoteData);
total += this.decGarnishment(quoteData);
total += this.decTaxLiability(quoteData);
total += this.decRentalEviction(quoteData);
total += this.decRealEstateChapter7(quoteData);
total += this.decRealEstateIntention(quoteData);
total += this.decVehicleChapter7(quoteData);
total += this.decVehicleIntention(quoteData);
total += this.decOtherAssetChapter7(quoteData);
total += this.decOtherAssetIntention(quoteData);
total += this.decFinancialAccount(quoteData);
total += this.decMeansTestAnalysisChapter7(quoteData);
return total;
}
正如您所看到的,我已经添加了所有其他条件来显示我所拥有的长度—这只是一个Total,我还有几十个(每个都有几十个条件)。
谁能提供一些示例代码关于我如何转换这个,因为我试图通过这样做的get/set
:
public virtual decimal SpouseFilingChapter7
{
get
{
return decSpouseFilingChapter7;
}
set
{
decSpouseFilingChapter7 = value;
}
}
这样我就可以这样做:
public virtual decimal TotalChapter7
{
get
{
return SpouseFilingChapter7 + ...;
}
}
但这显然是错误的。
谢谢你的帮助
目前还不清楚NHibernate与此有什么关系,但这里有一个可能的重构
class Calculate
{
private QuoteViewModel _quoteData;
private PriceQuote _prices;
public Calculate(QuoteViewModel quoteData, PriceQuote prices)
{
_quoteData = quoteData;
_prices = prices;
}
public decimal SpouseFilingChapter7
{
get
{
if (_quoteData.QuotePartRecord.MaritalStatusDropDown == MaritalStatus.Yes)
{
return _quoteData.QuotePartRecord.SpouseFilingRadioButton == SpouseFiling.Yes ?
_prices.priceSpouseFilingChapter7 :
_prices.priceNoSpouseFilingChapter7;
}
else
return 0;
}
}
public decimal TotalChapter7
{
get
{
return _prices.priceChapter7 +
SpouseFilingChapter7 +
PaymentPlanChapter7 +
ProcessingChapter7 +
SubmissionChapter7 +
DistrictChapter7 +
UnsecuredCreditor +
Garnishment +
TaxLiability +
RentalEviction +
RealEstateChapter7 +
RealEstateIntention +
VehicleChapter7 +
VehicleIntention +
OtherAssetChapter7 +
OtherAssetIntention +
FinancialAccount +
MeansTestAnalysisChapter7;
}
}
}