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 List <EmployeeAssetMappingModel> GetEmployeeAssetMappingsModel() { var employeeAssetMappings = _employeeAssetMappingRepository.GetEmployeeAssetMappings(); if (employeeAssetMappings != null && employeeAssetMappings.Count > 0) { return(employeeAssetMappings.Select(eam => new EmployeeAssetMappingModel { ID = eam.ID, EmployeeID = eam.EmployeeID, EmployeeName = eam.Employee.EmployeeName, AssetID = eam.AssetID, AssetName = eam.Assets.AssetName, CreatedDate = eam.CreatedDate, CreatedBy = eam.CreatedBy }).ToList()); } else { return(new List <EmployeeAssetMappingModel> { }); } }
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; } } }