'Calculate properties using items in List with conditions

I have a list object that has several properties that I want to use for calculations for an model properties.

something like:

List<Cars>

that has properties for Wheels/Windows/HasRoof/FuelType, etc.

I have a model for "Parts" (class example below) that I want to fill but I have a few rules to apply, I'm going to pseudoCode what I think I should do, but I'm not sure if this is the approach for this:

  public class Parts
    {
        public int AmountOfWheels { get; set; }
        public int AmountOfWheelsForFuelTypeGas { get; set; }
        public AmountOfWindowsForCarsWithRoof Type { get; set; }
    }

public Parts Parts { get; set; }

this is what I want to fill:

    foreach (var item in Cars)
    {
        Parts.AmountOfWheels =+ item.Wheels;
        Parts.AmountOfWheelsForFuelTypeGas   // <-- This is what I don't know
        Parts.AmountOfWindowsForCarsWithRoof // <-- This is what I don't know
    }

Then later I want to show the user this Parts object in a webApp, but I'm not sure how to populate this object.

The part I'm not sure if it's ok to do the calculations like this or shall I do something in the object model with properties



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source