2013-03-11 24 views
0

我有很多代码为其执行条件计算。用户可以在UI上进行选择(下拉菜单,单选按钮等),根据选择我会为他们计算结果。以前,我会使用ViewBag在视图上显示计算结果。但是现在我想用NHibernate存储这些数据,并且很难将其转换为存储计算结果的数据。我希望这不需要全部重写。试图将条件计算转换为存储到NHibernate中

下面是我在做什么之前的例子(一个条件的例子 - 注意:PriceQuote.cs只抱值)在Calculate.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; 
} 

正如你所看到的,我已经添加了所有其他条件来显示我有什么 - 这只是一个Total,我有几十个(每个有几十个条件)。

任何人都可以提供关于如何我想这个转换一些示例代码,因为我做这样的事情努力get/set

public virtual decimal SpouseFilingChapter7 
{ 
    get 
    { 
     return decSpouseFilingChapter7; 
    } 
    set 
    { 
     decSpouseFilingChapter7 = value; 
    } 
} 

,这样我可能会做这样的事情:

public virtual decimal TotalChapter7 
{ 
    get 
    { 
     return SpouseFilingChapter7 + ...; 
    } 
} 

但这显然是错误的。

感谢您的任何帮助。

回答

0

,目前还不清楚是什么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; 
     } 
    } 
}