public void UnassignAsset(AssetModel assetModel) { if (assetModel.ID != 0 && assetModel.EmployeeID != 0) { var employeeAssetMapping = _employeeAssetMappingRepository.GetEmployeeAssetMappings().Where(m => m.AssetID == assetModel.ID && m.EmployeeID == assetModel.EmployeeID).First(); if (employeeAssetMapping != null) { _employeeAssetMappingRepository.DeleteEmployeeAssetMappingByID(employeeAssetMapping.ID); } } int id = _assetTrackerService.CreateAssetTracker(new AssetTrackerModel { AssetID = assetModel.ID, EmpID = assetModel.EmployeeID, AssetStatusID = (int)AssetTrackingStatus.Unassign, CreatedDate = DateTime.Now, CreatedBy = _employeeService.GetEmployeeByCorpId(HttpContext.Current.User.Identity.Name).ID, Remarks = assetModel.Remarks }); if (id != 0) { assetModel.AssetStatusID = (int)AssetTrackingStatus.Unassign; id = UpdateAsset(assetModel); } }
public void UnassignAsset(AssetModel assetModel) { using (var scope = new TransactionScope(TransactionScopeOption.Required)) { try { if (assetModel.ID != 0 && assetModel.EmployeeID != 0) { var employeeAssetMapping = _employeeAssetMappingRepository.GetEmployeeAssetMappings().Where(m => m.AssetID == assetModel.ID && m.EmployeeID == assetModel.EmployeeID).First(); if (employeeAssetMapping != null) { _employeeAssetMappingRepository.DeleteEmployeeAssetMappingByID(employeeAssetMapping.ID); } } int id = _assetTrackerService.CreateAssetTracker(new AssetTrackerModel { AssetID = assetModel.ID, EmpID = assetModel.EmployeeID, AssetStatusID = (int)AssetTrackingStatus.Unassign, CreatedDate = DateTime.Now, CreatedBy = _employeeService.GetEmployeeByCorpId(HttpContext.Current.User.Identity.Name).ID, Remarks = assetModel.Remarks }); if (id != 0) { assetModel.AssetStatusID = (int)AssetTrackingStatus.Unassign; id = UpdateAsset(assetModel); } scope.Complete(); } catch (Exception) { scope.Dispose(); throw; } } }