2017-09-15 49 views
0
<td> 
    <strong> 
     Rs @(Model.lstItem.Sum(c => c._product.option != null 
       ? (c._product.option.Price * c.Quantity) 
       : (c._product.product.Price * c.Quantity)) 
      - (Model.coupon != null ? (int)Model.coupon.Discount : 0)) 
    </strong> 
</td> 

首先讓我告訴你,我在asp.net mvc的全新.. 現在我的問題是我上面的查詢其在將價格和數量相乘後正在返回總計。現在我想的是,我想增加價格量的6%的價格控管數量..我想的6%的增量來自查詢添加到返回的結果

最終的結果會是怎樣(價格*數量)*價格控管數量的+ 6%..

我希望你們明白我的問題

+2

簡單的數學。 '1.06 *價格*數量'。 – Amy

回答

0

你不應該保持在View這些constants。如果你在多個地方進行了這些計算,並且你希望在未來將這一比例調整到7%,那麼你就不得不在任何地方進行調整。所以,它應該來自你的數據庫,或者一個配置文件或者一個常量類。

因此,最簡單的方法是在Common文件夾或Utility文件夾中創建一個名爲ApplicationConstants的靜態類。

public static class ApplicationConstants 
{ 
    public const int ProfitPercentage = 6; 
} 

然後在你的View

@using YourAppName.Common 

<td> 
    <strong> 
     Rs @( 
      (1 + ApplicationConstants.ProfitPercentage/100) * 
      (Model.lstItem.Sum(c => c._product.option != null 
       ? (c._product.option.Price * c.Quantity) 
       : (c._product.product.Price * c.Quantity))) 
      - (Model.coupon != null ? (int)Model.coupon.Discount : 0)) 
    </strong> 
</td> 
0

你可以只是這樣做:

(price * quantity) + (((price * quantity)/100) * 6))