コード例 #1
0
ファイル: AssetService.cs プロジェクト: ravibharathim/AMS_02
        public HardwareAssetModel CreateHardwareAsset(HardwareAssetModel hardwareAssetModel)
        {
            Assets assets = new Assets
            {
                AssetName     = hardwareAssetModel.AssetName,
                SerialNumber  = hardwareAssetModel.SerialNumber,
                AssetTypeID   = hardwareAssetModel.AssetTypeID,
                AssetStatusID = (int)AssetTrackingStatus.New,
                CreatedDate   = DateTime.Now,
                CreatedBy     = GetLoginEmployeeId()
            };
            var createdAsset = _assetRepository.CreateAsset(assets);

            hardwareAssetModel.AssetID = createdAsset.ID;
            _hardwareAssetService.CreateHardwareAsset(hardwareAssetModel);

            AssetTrackerModel assetTrackerModel = new AssetTrackerModel
            {
                AssetID       = hardwareAssetModel.AssetID,
                AssetStatusID = (int)AssetTrackingStatus.New,
                CreatedDate   = DateTime.Now,
                CreatedBy     = assets.CreatedBy,
                Remarks       = hardwareAssetModel.Comment,
            };

            _assetTrackerService.CreateAssetTracker(assetTrackerModel);

            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   = createdAsset.ID;
                        item.ActualAssetID     = createdAsset.ID;
                        item.AssignedDate      = DateTime.Now;
                        item.AssignedBy        = GetLoginEmployeeId();
                        item.CreatedDate       = DateTime.Now;
                        item.CreatedBy         = GetLoginEmployeeId();
                        item.ComponentStatusId = (int)ComponentTrackingStatus.Assign;
                        _componentAssetMappingService.CreateComponentAssetMapping(item);
                        ComponentTrackerModel componentTrackerModel = new ComponentTrackerModel
                        {
                            AssetID           = createdAsset.ID,
                            ComponentID       = item.ComponentID,
                            ComponentStatusID = (int)ComponentTrackingStatus.Assign,
                            CreatedBy         = GetLoginEmployeeId(),
                            CreatedDate       = DateTime.Now
                        };
                        _componentTrackerService.CreateComponentTracker(componentTrackerModel);
                    }
                }
            }
            return(hardwareAssetModel);
        }
コード例 #2
0
        public HardwareAssetModel CreateHardwareAsset(HardwareAssetModel hardwareAssetModel)
        {
            using (var scope = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    Assets assets = new Assets
                    {
                        AssetName     = hardwareAssetModel.AssetName,
                        SerialNumber  = hardwareAssetModel.SerialNumber,
                        AssetTypeID   = hardwareAssetModel.AssetTypeID,
                        AssetStatusID = (int)AssetTrackingStatus.New,
                        CreatedDate   = DateTime.Now,
                        CreatedBy     = GetLoginEmployeeId()
                    };
                    var createdAsset = _assetRepository.CreateAsset(assets);

                    hardwareAssetModel.AssetID = createdAsset.ID;
                    _hardwareAssetService.CreateHardwareAsset(hardwareAssetModel);

                    AssetTrackerModel assetTrackerModel = new AssetTrackerModel
                    {
                        AssetID       = hardwareAssetModel.AssetID,
                        AssetStatusID = (int)AssetTrackingStatus.New,
                        CreatedDate   = DateTime.Now,
                        CreatedBy     = assets.CreatedBy,
                        Remarks       = hardwareAssetModel.Comment,
                    };
                    _assetTrackerService.CreateAssetTracker(assetTrackerModel);

                    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   = createdAsset.ID;
                                item.ActualAssetID     = createdAsset.ID;
                                item.AssignedDate      = DateTime.Now;
                                item.AssignedBy        = GetLoginEmployeeId();
                                item.CreatedDate       = DateTime.Now;
                                item.CreatedBy         = GetLoginEmployeeId();
                                item.ComponentStatusId = (int)ComponentTrackingStatus.Assign;
                                _componentAssetMappingService.CreateComponentAssetMapping(item);
                                ComponentTrackerModel componentTrackerModel = new ComponentTrackerModel
                                {
                                    AssetID           = createdAsset.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;
                }
            }
        }