public CostCalculationGarmentViewModel MapToViewModel(CostCalculationGarment model)
        {
            CostCalculationGarmentViewModel viewModel = new CostCalculationGarmentViewModel();

            PropertyCopier <CostCalculationGarment, CostCalculationGarmentViewModel> .Copy(model, viewModel);

            viewModel.Convection          = model.Convection;
            viewModel.AutoIncrementNumber = model.AutoIncrementNumber;

            viewModel.FabricAllowance      = Percentage.ToPercent(model.FabricAllowance);
            viewModel.AccessoriesAllowance = Percentage.ToPercent(model.AccessoriesAllowance);

            viewModel.SizeRange = model.SizeRange;

            viewModel.Buyer      = new BuyerViewModel();
            viewModel.Buyer._id  = model.BuyerId;
            viewModel.Buyer.name = model.BuyerName;

            viewModel.Efficiency       = new EfficiencyViewModel();
            viewModel.Efficiency.Id    = model.EfficiencyId;
            viewModel.Efficiency.Value = Percentage.ToPercent(model.EfficiencyValue);

            viewModel.UOM = new UOMViewModel()
            {
                _id  = model.UOMID,
                code = model.UOMCode,
                unit = model.UOMUnit
            };

            viewModel.Wage       = new RateViewModel();
            viewModel.Wage.Id    = model.WageId;
            viewModel.Wage.Value = model.WageRate;

            viewModel.THR       = new RateViewModel();
            viewModel.THR.Id    = model.THRId;
            viewModel.THR.Value = model.THRRate;

            viewModel.Rate       = new RateViewModel();
            viewModel.Rate.Id    = model.RateId;
            viewModel.Rate.Value = model.RateValue;

            viewModel.Commodity            = new MasterPlanComodityViewModel();
            viewModel.Commodity.name       = model.Commodity;
            viewModel.Commodity._id        = model.ComodityID;
            viewModel.CommodityDescription = model.CommodityDescription;

            viewModel.CostCalculationGarment_Materials = new List <CostCalculationGarment_MaterialViewModel>();
            if (model.CostCalculationGarment_Materials != null)
            {
                foreach (CostCalculationGarment_Material CostCalculationGarment_Material in model.CostCalculationGarment_Materials)
                {
                    CostCalculationGarment_MaterialViewModel CostCalculationGarment_MaterialVM = new CostCalculationGarment_MaterialViewModel();
                    PropertyCopier <CostCalculationGarment_Material, CostCalculationGarment_MaterialViewModel> .Copy(CostCalculationGarment_Material, CostCalculationGarment_MaterialVM);

                    CostCalculationGarment_Material.Convection = model.Convection;

                    CategoryViewModel categoryVM = new CategoryViewModel()
                    {
                        _id = CostCalculationGarment_Material.CategoryId
                    };
                    string[] names = CostCalculationGarment_Material.CategoryName.Split(new[] { " - " }, StringSplitOptions.None);
                    categoryVM.name = names[0];
                    try
                    {
                        categoryVM.SubCategory = names[1];
                    }
                    catch (IndexOutOfRangeException)
                    {
                        categoryVM.SubCategory = null;
                    }
                    CostCalculationGarment_MaterialVM.Category = categoryVM;

                    //CostCalculationGarment_Material.ProductId = new GarmentProductViewModel();

                    UOMViewModel uomQuantityVM = new UOMViewModel()
                    {
                        _id  = CostCalculationGarment_Material.UOMQuantityId,
                        unit = CostCalculationGarment_Material.UOMQuantityName
                    };
                    CostCalculationGarment_MaterialVM.UOMQuantity = uomQuantityVM;

                    UOMViewModel uomPriceVM = new UOMViewModel()
                    {
                        _id  = CostCalculationGarment_Material.UOMPriceId,
                        unit = CostCalculationGarment_Material.UOMPriceName
                    };
                    CostCalculationGarment_MaterialVM.UOMPrice = uomPriceVM;

                    CostCalculationGarment_MaterialVM.ShippingFeePortion = Percentage.ToPercent(CostCalculationGarment_Material.ShippingFeePortion);

                    CostCalculationGarment_MaterialVM.Product = new GarmentProductViewModel
                    {
                        _id          = CostCalculationGarment_Material.ProductId,
                        code         = CostCalculationGarment_Material.ProductCode,
                        composition  = CostCalculationGarment_Material.Composition,
                        construction = CostCalculationGarment_Material.Construction,
                        yarn         = CostCalculationGarment_Material.Yarn,
                        width        = CostCalculationGarment_Material.Width
                    };

                    //CostCalculationGarment_MaterialVM.PO_SerialNumber =

                    viewModel.CostCalculationGarment_Materials.Add(CostCalculationGarment_MaterialVM);
                }
            }

            viewModel.CommissionPortion = Percentage.ToPercent(model.CommissionPortion);
            viewModel.Risk = Percentage.ToPercent(model.Risk);

            viewModel.OTL1                 = new RateCalculatedViewModel();
            viewModel.OTL1.Id              = model.OTL1Id;
            viewModel.OTL1.Value           = model.OTL1Rate;
            viewModel.OTL1.CalculatedValue = model.OTL1CalculatedRate;

            viewModel.OTL2                 = new RateCalculatedViewModel();
            viewModel.OTL2.Id              = model.OTL2Id;
            viewModel.OTL2.Value           = model.OTL2Rate;
            viewModel.OTL2.CalculatedValue = model.OTL2CalculatedRate;

            viewModel.NETFOBP = Percentage.ToPercent((double)model.NETFOBP);

            return(viewModel);
        }
        public CostCalculationGarmentViewModel MapToViewModel(CostCalculationGarment model)
        {
            CostCalculationGarmentViewModel viewModel = new CostCalculationGarmentViewModel();

            PropertyCopier <CostCalculationGarment, CostCalculationGarmentViewModel> .Copy(model, viewModel);

            viewModel.Line      = new LineViewModel();
            viewModel.Line.Id   = model.LineId;
            viewModel.Line.Name = model.LineName;

            viewModel.FabricAllowance      = Percentage.ToPercent(model.FabricAllowance);
            viewModel.AccessoriesAllowance = Percentage.ToPercent(model.AccessoriesAllowance);

            viewModel.SizeRange      = new SizeRangeViewModel();
            viewModel.SizeRange.Id   = model.SizeRangeId;
            viewModel.SizeRange.Name = model.SizeRangeName;

            viewModel.Buyer      = new BuyerViewModel();
            viewModel.Buyer.Id   = model.BuyerId;
            viewModel.Buyer.Name = model.BuyerName;

            viewModel.Efficiency       = new EfficiencyViewModel();
            viewModel.Efficiency.Id    = model.EfficiencyId;
            viewModel.Efficiency.Value = Percentage.ToPercent(model.EfficiencyValue);

            viewModel.Wage       = new RateViewModel();
            viewModel.Wage.Id    = model.WageId;
            viewModel.Wage.Value = model.WageRate;

            viewModel.THR       = new RateViewModel();
            viewModel.THR.Id    = model.THRId;
            viewModel.THR.Value = model.THRRate;

            viewModel.Rate       = new RateViewModel();
            viewModel.Rate.Id    = model.RateId;
            viewModel.Rate.Value = model.RateValue;

            viewModel.CostCalculationGarment_Materials = new List <CostCalculationGarment_MaterialViewModel>();
            if (model.CostCalculationGarment_Materials != null)
            {
                foreach (CostCalculationGarment_Material CostCalculationGarment_Material in model.CostCalculationGarment_Materials)
                {
                    CostCalculationGarment_MaterialViewModel CostCalculationGarment_MaterialVM = new CostCalculationGarment_MaterialViewModel();
                    PropertyCopier <CostCalculationGarment_Material, CostCalculationGarment_MaterialViewModel> .Copy(CostCalculationGarment_Material, CostCalculationGarment_MaterialVM);

                    CategoryViewModel categoryVM = new CategoryViewModel()
                    {
                        Id = CostCalculationGarment_Material.CategoryId
                    };
                    string[] names = CostCalculationGarment_Material.CategoryName.Split(new[] { " - " }, StringSplitOptions.None);
                    categoryVM.Name = names[0];
                    try
                    {
                        categoryVM.SubCategory = names[1];
                    }
                    catch (IndexOutOfRangeException)
                    {
                        categoryVM.SubCategory = null;
                    }
                    CostCalculationGarment_MaterialVM.Category = categoryVM;

                    MaterialViewModel materialVM = new MaterialViewModel()
                    {
                        Id   = CostCalculationGarment_Material.MaterialId,
                        Name = CostCalculationGarment_Material.MaterialName
                    };
                    CostCalculationGarment_MaterialVM.Material = materialVM;

                    UOMViewModel uomQuantityVM = new UOMViewModel()
                    {
                        Id   = CostCalculationGarment_Material.UOMQuantityId,
                        Name = CostCalculationGarment_Material.UOMQuantityName
                    };
                    CostCalculationGarment_MaterialVM.UOMQuantity = uomQuantityVM;

                    UOMViewModel uomPriceVM = new UOMViewModel()
                    {
                        Id   = CostCalculationGarment_Material.UOMPriceId,
                        Name = CostCalculationGarment_Material.UOMPriceName
                    };
                    CostCalculationGarment_MaterialVM.UOMPrice = uomPriceVM;

                    CostCalculationGarment_MaterialVM.ShippingFeePortion = Percentage.ToPercent(CostCalculationGarment_Material.ShippingFeePortion);

                    viewModel.CostCalculationGarment_Materials.Add(CostCalculationGarment_MaterialVM);
                }
            }

            viewModel.CommissionPortion = Percentage.ToPercent(model.CommissionPortion);
            viewModel.Risk = Percentage.ToPercent(model.Risk);

            viewModel.OTL1                 = new RateCalculatedViewModel();
            viewModel.OTL1.Id              = model.OTL1Id;
            viewModel.OTL1.Value           = model.OTL1Rate;
            viewModel.OTL1.CalculatedValue = model.OTL1CalculatedRate;

            viewModel.OTL2                 = new RateCalculatedViewModel();
            viewModel.OTL2.Id              = model.OTL2Id;
            viewModel.OTL2.Value           = model.OTL2Rate;
            viewModel.OTL2.CalculatedValue = model.OTL2CalculatedRate;

            viewModel.NETFOBP = Percentage.ToPercent((double)model.NETFOBP);

            return(viewModel);
        }