我有很多代码可以执行条件计算。用户将在 UI 上做出选择(下拉菜单、单选按钮等),并根据这些选择为他们计算结果。以前,我会使用 ViewBag 在视图上显示计算结果。但是现在我想使用 NHibernate 存储这些,并且很难将其转换为可以存储计算结果的东西。我希望这不需要完全重写。
这是我之前在 Calculate.cs 中所做的示例(一个条件示例 - 注意:PriceQuote.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;
}
PriceQuote.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;
}
正如你所看到的,我已经添加了所有其他条件来显示我所拥有的长度 - 这只是一个总计,我还有几十个(每个都有几十个条件)。
任何人都可以提供一些关于如何转换它的示例代码,因为我正在尝试get/set
这样做:
public virtual decimal SpouseFilingChapter7
{
get
{
return decSpouseFilingChapter7;
}
set
{
decSpouseFilingChapter7 = value;
}
}
这样我就可以做类似的事情:
public virtual decimal TotalChapter7
{
get
{
return SpouseFilingChapter7 + ...;
}
}
但这显然是错误的。
谢谢你的帮助。