Exemple #1
0
        /// <summary>
        /// Map item model to view model
        /// </summary>
        /// <param name="bomItem"></param>
        /// <returns></returns>
        private BomItemViewModel MapBomItemToViewModel(BomItem bomItem)
        {
            var bomItemViewModel = new BomItemViewModel {
                ItemType = bomItem.ItemType
            };

            if (bomItem.ItemType == BomItemType.Equipment)
            {
                var equipmentViewModel = new EquipmentViewModel();
                equipmentViewModel.MapFromModel(bomItem.Item as Equipment);
                bomItemViewModel.Item = equipmentViewModel;
            }
            else
            {
                var materialViewModel = new MaterialViewModel();
                materialViewModel.MapFromModel(bomItem.Item as Material);
                bomItemViewModel.Item = materialViewModel;
            }
            return(bomItemViewModel);
        }
Exemple #2
0
        /// <summary>
        /// Map Bom Item View Model To Model
        /// </summary>
        /// <param name="bomItemViewModel"></param>
        /// <returns></returns>
        private BomItem MapBomItemToModel(BomItemViewModel bomItemViewModel)
        {
            var bomItem = new BomItem {
                ItemType = bomItemViewModel.ItemType
            };

            if (bomItemViewModel.ItemType == BomItemType.Equipment)
            {
                var equipmentViewModel = JsonConvert.DeserializeObject <EquipmentViewModel>(bomItemViewModel.Item.ToString());
                var equipment          = new Equipment();
                bomItem.Item = equipment.MapFromViewModel(equipmentViewModel as EquipmentViewModel) as BillOfMaterialsItem;
            }
            else
            {
                var materialViewModel = JsonConvert.DeserializeObject <MaterialViewModel>(bomItemViewModel.Item.ToString());
                var material          = new Material();
                bomItem.Item = material.MapFromViewModel(materialViewModel as MaterialViewModel) as BillOfMaterialsItem;
            }
            return(bomItem);
        }