internal Product ConvertToProduct(string condition = null, int?userDemand = null, decimal?Duration = null, char?dlmtr = null)
        {
            decimal?price   = null;
            var     prodDet = "";
            var     config  = new MapperConfiguration(cfg => { });
            var     mapper  = new Mapper(config);

            if (this.ProductType.Equals("FoodAndBeverageItems"))
            {
                FoodAndBeveragesViewModel food = mapper.Map <FoodAndBeveragesViewModel>(this.ProductDetail);
                prodDet = food.ConvertToItem(dlmtr);
                price   = food.UnitPriceItemCalculation();
            }
            else if (this.ProductType.Equals("MaterialItems"))
            {
                MaterialViewModel materi = mapper.Map <MaterialViewModel>(this.ProductDetail);
                prodDet = materi.ConvertToItem(dlmtr);
                price   = materi.UnitPriceItemCalculation();
            }
            else if (this.ProductType.Equals("GarmentItems"))
            {
                GarmentViewModel garment = mapper.Map <GarmentViewModel>(this.ProductDetail);
                prodDet = garment.ConvertToItem(dlmtr);
                price   = garment.UnitPriceItemCalculation();
            }
            else if (this.ProductType.Equals("TransportationServices"))
            {
                TransportationServicesViewModel trans = mapper.Map <TransportationServicesViewModel>(this.ProductDetail);
                prodDet = trans.ConvertToServ(dlmtr);
                price   = trans.RateCostCalculation(condition, userDemand, Duration);
            }
            else if (this.ProductType.Equals("TelecommunicationServices"))
            {
                TelecomunicationServicesViewModel tele = mapper.Map <TelecomunicationServicesViewModel>(this.ProductDetail);
                prodDet = tele.ConvertToServ(dlmtr);
                price   = tele.RateCostCalculation(condition, userDemand, Duration);
            }
            else
            {
                price         = 0;
                ProductDetail = null;
            }
            return(new Product()
            {
                ProductID = this.ProductID,
                ProductName = this.ProductName,
                SupplierID = this.SupplierID,
                CategoryID = this.CategoryID,
                QuantityPerUnit = this.QuantityPerUnit,
                UnitPrice = price,
                UnitsInStock = this.UnitsInStock,
                UnitsOnOrder = this.UnitsOnOrder,
                ReorderLevel = this.ReorderLevel,
                Discontinued = this.Discontinued,
                ProductType = this.ProductType,
                ProductDetail = prodDet
            });
        }
        public Product ConvertToProduct2(string condition = null, int?userDemand = null, decimal?Duration = null)
        {
            decimal?price = null;
            Dictionary <string, object> prodDict  = new Dictionary <string, object>();
            ProductValidator            validator = new ProductValidator();
            var config = new MapperConfiguration(cfg => { });
            var mapper = new Mapper(config);

            if (this.ProductType.Equals("FoodAndBeverageItems"))
            {
                FoodBevItemViewModel food = mapper.Map <FoodBevItemViewModel>(this.ProductDetail);
                prodDict = food.fromItemToDict();
                price    = food.unitPriceItemCalculation();
                validator.isValidProductDetail(prodDict, ProductType);
            }
            else if (this.ProductType.Equals("MaterialItems"))
            {
                MaterialViewModel materi = mapper.Map <MaterialViewModel>(this.ProductDetail);
                prodDict = materi.fromItemToDict();
                price    = materi.unitPriceItemCalculation();
                validator.isValidProductDetail(prodDict, ProductType);
            }
            else if (this.ProductType.Equals("GarmentItems"))
            {
                GarmentViewModel garment = mapper.Map <GarmentViewModel>(this.ProductDetail);
                prodDict = garment.fromItemToDict();
                price    = garment.unitPriceItemCalculation();
                validator.isValidProductDetail(prodDict, ProductType);
            }
            else if (this.ProductType.Equals("TransportationServices"))
            {
                TransportationServicesViewModel trans = mapper.Map <TransportationServicesViewModel>(this.ProductDetail);
                prodDict = trans.fromServToDict();
                price    = trans.RateCostCalculation(condition, userDemand, Duration);
                validator.isValidProductDetail(prodDict, ProductType);
            }
            else if (this.ProductType.Equals("TelecommunicationServices"))
            {
                TelecomunicationServiceViewModel tele = mapper.Map <TelecomunicationServiceViewModel>(this.ProductDetail);
                prodDict = tele.fromServToDict();
                price    = tele.RateCostCalculation(condition, userDemand, Duration);
                validator.isValidProductDetail(prodDict, ProductType);
            }
            else
            {
                price         = 0;
                ProductDetail = null;
            }

            if (validator.isValidProductDetail(prodDict, ProductType))
            {
                return(new Product()
                {
                    ProductID = this.ProductID,
                    ProductName = this.ProductName,
                    SupplierID = this.SupplierID,
                    CategoryID = this.CategoryID,
                    QuantityPerUnit = this.QuantityPerUnit,
                    UnitPrice = price,
                    UnitsInStock = this.UnitsInStock,
                    UnitsOnOrder = this.UnitsOnOrder,
                    ReorderLevel = this.ReorderLevel,
                    Discontinued = this.Discontinued,
                    ProductType = this.ProductType,
                    ProductDetail = prodDict.ToString()
                });
            }
            else
            {
                return(null);
            }
        }