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); }
public int AssignAsset(AssetModel assetModel) { EmployeeAssetMappingModel employeeAssetMappingModel = new EmployeeAssetMappingModel { EmployeeID = assetModel.EmployeeID, AssetID = assetModel.ID, CreatedBy = _employeeService.GetEmployeeByCorpId(HttpContext.Current.User.Identity.Name).ID }; var employeeAssetMapping = _employeeAssetMappingRepository.CreateEmployeeAssetMapping(new EmployeeAssetMapping { AssetID = assetModel.ID, EmployeeID = assetModel.EmployeeID, CreatedBy = _employeeService.GetEmployeeByCorpId(HttpContext.Current.User.Identity.Name).ID, }); if (employeeAssetMapping != null && employeeAssetMapping.ID != 0) { int id = _assetTrackerService.CreateAssetTracker(new AssetTrackerModel { AssetID = assetModel.ID, EmpID = assetModel.EmployeeID, AssetStatusID = (int)AssetTrackingStatus.Assign, CreatedDate = DateTime.Now, CreatedBy = employeeAssetMappingModel.CreatedBy, Remarks = assetModel.Remarks }); if (id != 0) { assetModel.AssetStatusID = (int)AssetTrackingStatus.Assign; id = UpdateAsset(assetModel); } } return(assetModel.ID); }
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; } } }