private InventoryItem RandomlyGenerate(int x)
        {
            var vehicleCount       = VehicleRepository.List.Count;
            var vehicleRandomIndex = this.randomValue.Next(0, vehicleCount - 1);

            var randomVehicle = VehicleRepository.List[vehicleRandomIndex];
            var item          = new InventoryItem();

            item.StockNumber = StockNumberGenerator.GenerateStockNumber();
            item.Id          = x.ToString();
            item.Vehicle     = randomVehicle;

            var featureCount       = FeatureRepository.List.Count;
            var featureRandomIndex = this.randomValue.Next(0, featureCount - 1);
            var randomFeature      = FeatureRepository.List[featureRandomIndex];

            item.Features.Add(randomFeature);

            //Provide a random markup between 0 and 20 percent.
            item.Markup = this.randomValue.Next(0, 20);
            return(item);
        }
        public IActionResult Post(InventoryItemRPC item)
        {
            //Quantity in stock

            //It isn't enough to only do validation client side, for data integrity it must be done server side as well.
            //TODO - Add Post, business logic must be enforced server side as well.
            //TODO - Add server side validation
            var vehicle = new Vehicle {
                Make        = (Make)Enum.Parse(typeof(Make), item.Make, true),
                Model       = item.Model,
                Year        = item.Year,
                VehicleType = (VehicleType)Enum.Parse(typeof(VehicleType), item.Type, true),
                RetailPrice = item.RetailPrice,
            };

            //Parse Features
            var features = new List <Feature>();

            if (!string.IsNullOrEmpty(item.Fuel))
            {
                var fuel = FeatureRepository.List.FirstOrDefault(feature => feature.Type == FeatureType.Fuel && feature.Description.Equals(item.Fuel, StringComparison.InvariantCultureIgnoreCase));
                if (fuel != null)
                {
                    features.Add(fuel);
                }
            }

            if (!string.IsNullOrEmpty(item.Doors))
            {
                var doors = FeatureRepository.List.FirstOrDefault(feature => feature.Type == FeatureType.Doors && feature.Description.Equals(item.Doors, StringComparison.InvariantCultureIgnoreCase));
                if (doors != null)
                {
                    features.Add(doors);
                }
            }

            if (!string.IsNullOrEmpty(item.Interior))
            {
                var interior = FeatureRepository.List.FirstOrDefault(feature => feature.Type == FeatureType.Interior && feature.Description.Equals(item.Interior, StringComparison.InvariantCultureIgnoreCase));
                if (interior != null)
                {
                    features.Add(interior);
                }
            }

            if (!string.IsNullOrEmpty(item.Transmission))
            {
                var transmission = FeatureRepository.List.FirstOrDefault(feature => feature.Type == FeatureType.Transmission && feature.Description.Equals(item.Transmission, StringComparison.InvariantCultureIgnoreCase));
                if (transmission != null)
                {
                    features.Add(transmission);
                }
            }

            var newItem = new InventoryItem
            {
                Markup   = item.Markup,
                Vehicle  = vehicle,
                Features = features
            };

            //Assign unique stock number...
            newItem.StockNumber = StockNumberGenerator.GenerateStockNumber();

            InventoryRepository.AddItem(newItem);

            return(Ok());
        }