Esempio n. 1
0
        public HardwareAssetModel UpdateHardwareAsset(HardwareAssetModel hardwareAssetModel)
        {
            using (var scope = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    Assets selectedAsset = _assetRepository.GetAssetByID(hardwareAssetModel.AssetID);
                    if (selectedAsset != null)
                    {
                        selectedAsset.AssetName     = hardwareAssetModel.AssetName;
                        selectedAsset.SerialNumber  = hardwareAssetModel.SerialNumber;
                        selectedAsset.AssetTypeID   = hardwareAssetModel.AssetTypeID;
                        selectedAsset.AssetStatusID = (int)AssetTrackingStatus.New;
                    }
                    _assetRepository.UpdateAsset(selectedAsset);

                    _hardwareAssetService.UpdateHardwareAsset(hardwareAssetModel);

                    if (hardwareAssetModel.ComponentAssetMapping != null)
                    {
                        if (hardwareAssetModel.ComponentAssetMapping.Where(fet => fet.ComponentID != 0).ToList().Count > 0)
                        {
                            foreach (var item in hardwareAssetModel.ComponentAssetMapping.Where(fet => fet.ComponentID != 0).ToList())
                            {
                                item.AssignedAssetID   = selectedAsset.ID;
                                item.ActualAssetID     = selectedAsset.ID;
                                item.AssignedDate      = DateTime.Now;
                                item.AssignedBy        = GetLoginEmployeeId();
                                item.ComponentStatusId = (int)ComponentTrackingStatus.Assign;
                                _componentAssetMappingService.UpdateComponentAssetMapping(item);
                                ComponentTrackerModel componentTrackerModel = new ComponentTrackerModel
                                {
                                    AssetID           = selectedAsset.ID,
                                    ComponentID       = item.ComponentID,
                                    ComponentStatusID = (int)ComponentTrackingStatus.Assign,
                                    CreatedBy         = GetLoginEmployeeId(),
                                    CreatedDate       = DateTime.Now
                                };
                                _componentTrackerService.CreateComponentTracker(componentTrackerModel);
                            }
                        }
                    }
                    scope.Complete();
                    return(hardwareAssetModel);
                }
                catch (Exception)
                {
                    scope.Dispose();
                    throw;
                }
            }
        }
Esempio n. 2
0
        public HardwareAssetModel UpdateHardwareAsset(HardwareAssetModel hardwareAssetModel)
        {
            Assets selectedAsset = _assetRepository.GetAssetByID(hardwareAssetModel.AssetID);

            if (selectedAsset != null)
            {
                selectedAsset.AssetName     = hardwareAssetModel.AssetName;
                selectedAsset.SerialNumber  = hardwareAssetModel.SerialNumber;
                selectedAsset.AssetTypeID   = hardwareAssetModel.AssetTypeID;
                selectedAsset.AssetStatusID = (int)AssetTrackingStatus.New;
            }
            _assetRepository.UpdateAsset(selectedAsset);

            _hardwareAssetService.UpdateHardwareAsset(hardwareAssetModel);

            if (hardwareAssetModel.ComponentAssetMapping != null)
            {
                if (hardwareAssetModel.ComponentAssetMapping.Where(fet => fet.Mandatory == true || fet.ComponentID != 0).ToList().Count > 0)
                {
                    foreach (var item in hardwareAssetModel.ComponentAssetMapping.Where(fet => fet.Mandatory == true || fet.ComponentID != 0).ToList())
                    {
                        item.AssignedAssetID   = selectedAsset.ID;
                        item.ActualAssetID     = selectedAsset.ID;
                        item.AssignedDate      = DateTime.Now;
                        item.AssignedBy        = GetLoginEmployeeId();
                        item.ComponentStatusId = (int)ComponentTrackingStatus.Assign;
                        _componentAssetMappingService.UpdateComponentAssetMapping(item);
                        ComponentTrackerModel componentTrackerModel = new ComponentTrackerModel
                        {
                            AssetID           = selectedAsset.ID,
                            ComponentID       = item.ComponentID,
                            ComponentStatusID = (int)ComponentTrackingStatus.Assign,
                            CreatedBy         = GetLoginEmployeeId(),
                            CreatedDate       = DateTime.Now
                        };
                        _componentTrackerService.CreateComponentTracker(componentTrackerModel);
                    }
                }
            }

            return(hardwareAssetModel);
        }