如何计算多个模型之间的参数? asp.net MVC [英] How to calculate a parameter between multiple models? asp.net MVC
问题描述
我有多个型号,我试图来计算总参数命名。我是新来的MVC和真的不知道如何做到这一点或者(看到,它不应该认为是肯定做)。
I have multiple models and I am trying to calculate a parameter named total. I am new to MVC and are not really sure how to do this or where (seen that it should not be done in view that's for sure).
我有这个参数我要计算:
I have this parameter I have to calculate:
public class Bill
{
public int Total { get; set; }
}
通过使用这些参数:
by using these parameters:
public class Article
{
public int Price { get; set; }
public float Quantity { get; set; }
}
和也:
public class BillLine
{
public int DiscountValue { get; set; }
}
总用这3个值计算,但我真的不知道该怎么做。该方案是这样的:每个billLine可以有1条和1个票据可以有很多账单行
The total is calculated using those 3 values but I am not really sure how to do it. The program works like this: each billLine can have 1 article and 1 bill can have many bill lines.
推荐答案
根据谅解我有以下code:考虑数量
指的是没有项目的它应该是int和价格做一个float属性。 TotalArticlePrice
是一个计算的属性。
As per understanding I have following Code: Considering Quantity
refers to no of Items it should be Int and Price Be a Float property. TotalArticlePrice
is a calculated property.
public class Article
{
public float Price { get; set; }
public int Quantity { get; set; }
public float TotalArticlePrice
{
get
{
return Price * Quantity;
}
}
}
正如你所说,一个BillLine有一个文章这样模型应该如下面文章
属性和 FinalBillLinePrice
这计算扣除优惠的折扣值
As you mentioned that one BillLine has one Article so model should be as below with Article
property and FinalBillLinePrice
which is calculated deducting the discout value
public class BillLine
{
public int DiscountValue { get; set; }
public Article Article { get; set; }
public float FinalBillLinePrice
{
get
{
return Article.TotalArticlePrice - DiscountValue;
}
}
}
最后,
正如你提到的一个比尔
可以有多个 BillLine
,因此模型应该如下,其中总
属性存储的总账单的价格。
finally,
As you mentioned One Bill
May have Multiple BillLine
,therefore Model should look like below, where Total
property stores the Total Bill Price.
public class Bill
{
public float Total
{
get
{
return BillLineList.Sum(x => x.FinalBillLinePrice);
}
}
public List<BillLine> BillLineList { get; set; }
}
在的情况下,我误解了什么,请在注释中介绍。
In case, I have misunderstood anything Please brief in comments.
这篇关于如何计算多个模型之间的参数? asp.net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!