예제 #1
0
        public SoftwareAssetModel CreateSoftwareAsset(SoftwareAssetModel softwareAssetModel)
        {
            Assets assets = new Assets
            {
                AssetName     = softwareAssetModel.AssetName,
                SerialNumber  = softwareAssetModel.SerialNumber,
                AssetTypeID   = softwareAssetModel.AssetTypeID,
                AssetStatusID = (int)AssetTrackingStatus.New,
                CreatedDate   = DateTime.Now,
                CreatedBy     = GetLoginEmployeeId()
            };
            var createdAsset = _assetRepository.CreateAsset(assets);

            softwareAssetModel.AssetID = createdAsset.ID;
            _softwareAssetService.CreateSoftwareAsset(softwareAssetModel);

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

            _assetTrackerService.CreateAssetTracker(assetTrackerModel);
            if (softwareAssetModel.ComponentAssetMapping != null)
            {
                if (softwareAssetModel.ComponentAssetMapping.Where(fet => fet.Mandatory == true || fet.ComponentID != 0).ToList().Count > 0)
                {
                    foreach (var item in softwareAssetModel.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(softwareAssetModel);
        }
예제 #2
0
        //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.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);
        //             }
        //         }
        //     }
        //     return hardwareAssetModel;
        // }

        public SoftwareAssetModel CreateSoftwareAsset(SoftwareAssetModel softwareAssetModel)
        {
            using (var scope = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    Assets assets = new Assets
                    {
                        AssetName     = softwareAssetModel.AssetName,
                        SerialNumber  = softwareAssetModel.SerialNumber,
                        AssetTypeID   = softwareAssetModel.AssetTypeID,
                        AssetStatusID = (int)AssetTrackingStatus.New,
                        CreatedDate   = DateTime.Now,
                        CreatedBy     = GetLoginEmployeeId()
                    };
                    var createdAsset = _assetRepository.CreateAsset(assets);
                    softwareAssetModel.AssetID = createdAsset.ID;
                    _softwareAssetService.CreateSoftwareAsset(softwareAssetModel);

                    AssetTrackerModel assetTrackerModel = new AssetTrackerModel
                    {
                        AssetID       = softwareAssetModel.AssetID,
                        AssetStatusID = (int)AssetTrackingStatus.New,
                        CreatedDate   = DateTime.Now,
                        CreatedBy     = assets.CreatedBy,
                        Remarks       = softwareAssetModel.Comment,
                    };
                    _assetTrackerService.CreateAssetTracker(assetTrackerModel);
                    if (softwareAssetModel.ComponentAssetMapping != null)
                    {
                        if (softwareAssetModel.ComponentAssetMapping.Where(fet => fet.ComponentID != 0).ToList().Count > 0)
                        {
                            foreach (var item in softwareAssetModel.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(softwareAssetModel);
                }
                catch (Exception)
                {
                    scope.Dispose();
                    throw;
                }
            }
        }