I am trying to create an 'if' statement inside the coding below:
var qisg = new QuoteItemSectionGroup
{
SectionGroup = db.SectionGroups.Where(x => x.Name == "Longitudinals" && x.Section == TruckSection.Floor).First(),
StockItem = quoteItem.Chassis.Longitudinal, <<-- Here
Quantity = 2,
Length = globals.FloorCalculatedLength
};
Example:
if (quoteItem.Chassis.Longitudinal == "SCH100")
Stockitem = quoteItem.BodyType.Longitudinal;
Is there a way that I might be able to create a method like this in my var qisg?
EDIT: This is what the code looks like now
var qisg = new QuoteItemSectionGroup
{
SectionGroup = db.SectionGroups.Where(x => x.Name == "Longitudinals" && x.Section == TruckSection.Floor).First(),
StockItem = quoteItem.BodyType.Longitudinal == "SCH100" ? quoteItem.Chassis.Longitudinal : quoteItem.BodyType.Longitudinal,
Quantity = 2,
Length = globals.FloorCalculatedLength
};
I'm getting the error:
Operator '==' cannot be applied to operands of type 'TrucksWcf.Models.StockItem' and 'string'
I'm sorry but some of the answers are a bit too complex for me to understand 0_o
ALSO Here is an example of another StockItem being assigned to a product:
qisg = new QuoteItemSectionGroup
{
SectionGroup = db.SectionGroups.Where(x => x.Name == "Cross Member" && x.Section == TruckSection.Floor).First(),
StockItem = db.StockItems.Where(x => x.StockCode == "SCH075").First(),
Length = globals.FloorCalculatedWidth
};