public async Task <IActionResult> OnPostDivisionTemplate() { if (ModelState.IsValid) { try { var FormData = Request.Form; OS_DivisionTemplate_Dto businessUnitTemplate_Dto = JsonSerializer.Deserialize <OS_DivisionTemplate_Dto>(FormData["info"]); bool IsEditing = businessUnitTemplate_Dto.Id > 0; if (IsEditing) { OS_DivisionTemplate curDivisionTemplate = await OS_DivisionTemplateAppService.Repository.GetAsync(businessUnitTemplate_Dto.Id); if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = businessUnitTemplate_Dto.Id.ToString(); entityChangeInfo.EntityTenantId = businessUnitTemplate_Dto.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Updated; entityChangeInfo.EntityTypeFullName = typeof(OS_DivisionTemplate).FullName; entityChangeInfo.PropertyChanges = new List <EntityPropertyChangeInfo>(); List <EntityPropertyChangeInfo> entityPropertyChanges = new List <EntityPropertyChangeInfo>(); var auditProps = typeof(OS_DivisionTemplate).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); OS_DivisionTemplate mappedInput = ObjectMapper.Map <OS_DivisionTemplate_Dto, OS_DivisionTemplate>(businessUnitTemplate_Dto); foreach (var prop in auditProps) { EntityPropertyChangeInfo propertyChange = new EntityPropertyChangeInfo(); object origVal = prop.GetValue(curDivisionTemplate); propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); object newVal = prop.GetValue(mappedInput); propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); if (propertyChange.OriginalValue == propertyChange.NewValue) { continue; } propertyChange.PropertyName = prop.Name; if (prop.Name.EndsWith("Id")) { try { string valuePropName = prop.Name.TrimEnd('d', 'I'); propertyChange.PropertyName = valuePropName; var valueProp = typeof(OS_DivisionTemplate).GetProperty(valuePropName); DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(businessUnitTemplate_Dto); if (_origValObj == null) { _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); } string _origVal = _origValObj.Value; propertyChange.OriginalValue = origVal == null ? "" : _origVal; DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(mappedInput); if (_newValObj == null) { _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); } string _newVal = _newValObj.Value; propertyChange.NewValue = _newValObj == null ? "" : _newVal; } catch (Exception ex) { } } propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; entityChangeInfo.PropertyChanges.Add(propertyChange); } #region ExtraProperties //List<EmployeeExtraPropertyHistory> allExtraPropertyHistories = new List<EmployeeExtraPropertyHistory>(); //if (departmentTemplate_Dto.ExtraProperties != curDivisionTemplate.ExtraProperties) //{ // //GeneralInfo oldGeneralInfo = department.GetProperty<GeneralInfo>("generalInfo"); // //List<EmployeeExtraPropertyHistory> physicalIdsHistory = new List<EmployeeExtraPropertyHistory>(); // //var generalInfoPhysicalIdAuditProps = typeof(PhysicalID).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); // //List<PhysicalId<Guid>> NewPhysicalIds = generalInfo.PhysicalIds.Where(x => !oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //List<PhysicalId<Guid>> UpdatedPhysicalIds = generalInfo.PhysicalIds.Where(x => oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //List<PhysicalId<Guid>> DeletedPhysicalIds = oldGeneralInfo.PhysicalIds.Where(x => !generalInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //for (int i = 0; i < NewPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // EmployeeExtraPropertyHistory newPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Created"); // // physicalIdsHistory.Add(newPhIdHistory); // //} // //for (int i = 0; i < UpdatedPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // PhysicalId<Guid> oldPhId = oldGeneralInfo.PhysicalIds.First(x => x.Id == curPhId.Id); // // EmployeeExtraPropertyHistory updatedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Updated"); // // foreach (var prop in generalInfoPhysicalIdAuditProps) // // { // // updatedPhIdHistory.PropertyChanges = new List<EmployeeTypePropertyChange>(); // // EmployeeTypePropertyChange propertyChange = new EmployeeTypePropertyChange(); // // object origVal = prop.GetValue(oldPhId); // // propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); // // object newVal = prop.GetValue(curPhId); // // propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); // // if (propertyChange.OriginalValue == propertyChange.NewValue) continue; // // propertyChange.PropertyName = prop.Name; // // if (prop.Name.EndsWith("Id")) // // { // // try // // { // // string valuePropName = prop.Name.TrimEnd('d', 'I'); // // propertyChange.PropertyName = valuePropName; // // var valueProp = typeof(PhysicalID).GetProperty(valuePropName); // // DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(oldPhId); // // if (_origValObj == null) _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); // // string _origVal = _origValObj.Value; // // propertyChange.OriginalValue = origVal == null ? "" : _origVal; // // DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(curPhId); // // if (_newValObj == null) _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); // // string _newVal = _newValObj.Value; // // propertyChange.NewValue = _newValObj == null ? "" : _newVal; // // } // // catch (Exception ex) // // { // // } // // } // // propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; // // updatedPhIdHistory.PropertyChanges.Add(propertyChange); // // } // // physicalIdsHistory.Add(updatedPhIdHistory); // //} // //for (int i = 0; i < DeletedPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // EmployeeExtraPropertyHistory deletedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Deleted"); // // physicalIdsHistory.Add(deletedPhIdHistory); // //} // entityChangeInfo.SetProperty("extraPropertiesHistory", allExtraPropertyHistories); //} #endregion AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } curDivisionTemplate.Name = businessUnitTemplate_Dto.Name; curDivisionTemplate.NameLocalized = businessUnitTemplate_Dto.NameLocalized; curDivisionTemplate.Code = businessUnitTemplate_Dto.Code; curDivisionTemplate.Description = businessUnitTemplate_Dto.Description; curDivisionTemplate.ValidityFromDate = businessUnitTemplate_Dto.ValidityFromDate; curDivisionTemplate.ValidityToDate = businessUnitTemplate_Dto.ValidityToDate; OS_DivisionTemplate_Dto updated = ObjectMapper.Map <OS_DivisionTemplate, OS_DivisionTemplate_Dto>(await OS_DivisionTemplateAppService.Repository.UpdateAsync(curDivisionTemplate)); return(StatusCode(200, updated)); } else { businessUnitTemplate_Dto.Id = 0; OS_DivisionTemplate_Dto added = await OS_DivisionTemplateAppService.CreateAsync(businessUnitTemplate_Dto); added = await OS_DivisionTemplateAppService.GetAsync(added.Id); if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = added.Id.ToString(); entityChangeInfo.EntityTenantId = added.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Created; entityChangeInfo.EntityTypeFullName = typeof(OS_DivisionTemplate).FullName; AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } return(StatusCode(200, added)); } } catch (Exception ex) { } } return(StatusCode(500)); }
public async Task <IActionResult> OnPostDepartmentTemplate() { if (ModelState.IsValid) { try { var FormData = Request.Form; OS_DepartmentTemplate_Dto departmentTemplate_Dto = JsonSerializer.Deserialize <OS_DepartmentTemplate_Dto>(FormData["info"]); bool IsEditing = departmentTemplate_Dto.Id > 0; if (IsEditing) { OS_DepartmentTemplate curDepartmentTemplate = await OS_DepartmentTemplateAppService.Repository.GetAsync(departmentTemplate_Dto.Id); if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = departmentTemplate_Dto.Id.ToString(); entityChangeInfo.EntityTenantId = departmentTemplate_Dto.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Updated; entityChangeInfo.EntityTypeFullName = typeof(OS_DepartmentTemplate).FullName; entityChangeInfo.PropertyChanges = new List <EntityPropertyChangeInfo>(); List <EntityPropertyChangeInfo> entityPropertyChanges = new List <EntityPropertyChangeInfo>(); var auditProps = typeof(OS_DepartmentTemplate).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); OS_DepartmentTemplate mappedInput = ObjectMapper.Map <OS_DepartmentTemplate_Dto, OS_DepartmentTemplate>(departmentTemplate_Dto); foreach (var prop in auditProps) { EntityPropertyChangeInfo propertyChange = new EntityPropertyChangeInfo(); object origVal = prop.GetValue(curDepartmentTemplate); propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); object newVal = prop.GetValue(mappedInput); propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); if (propertyChange.OriginalValue == propertyChange.NewValue) { continue; } propertyChange.PropertyName = prop.Name; if (prop.Name.EndsWith("Id")) { try { string valuePropName = prop.Name.TrimEnd('d', 'I'); propertyChange.PropertyName = valuePropName; var valueProp = typeof(OS_DepartmentTemplate).GetProperty(valuePropName); DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(departmentTemplate_Dto); if (_origValObj == null) { _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); } string _origVal = _origValObj.Value; propertyChange.OriginalValue = origVal == null ? "" : _origVal; DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(mappedInput); if (_newValObj == null) { _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); } string _newVal = _newValObj.Value; propertyChange.NewValue = _newValObj == null ? "" : _newVal; } catch (Exception ex) { } } propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; entityChangeInfo.PropertyChanges.Add(propertyChange); } #region ExtraProperties //List<EmployeeExtraPropertyHistory> allExtraPropertyHistories = new List<EmployeeExtraPropertyHistory>(); //if (departmentTemplate_Dto.ExtraProperties != curDepartmentTemplate.ExtraProperties) //{ // //GeneralInfo oldGeneralInfo = department.GetProperty<GeneralInfo>("generalInfo"); // //List<EmployeeExtraPropertyHistory> physicalIdsHistory = new List<EmployeeExtraPropertyHistory>(); // //var generalInfoPhysicalIdAuditProps = typeof(PhysicalID).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); // //List<PhysicalId<Guid>> NewPhysicalIds = generalInfo.PhysicalIds.Where(x => !oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //List<PhysicalId<Guid>> UpdatedPhysicalIds = generalInfo.PhysicalIds.Where(x => oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //List<PhysicalId<Guid>> DeletedPhysicalIds = oldGeneralInfo.PhysicalIds.Where(x => !generalInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //for (int i = 0; i < NewPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // EmployeeExtraPropertyHistory newPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Created"); // // physicalIdsHistory.Add(newPhIdHistory); // //} // //for (int i = 0; i < UpdatedPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // PhysicalId<Guid> oldPhId = oldGeneralInfo.PhysicalIds.First(x => x.Id == curPhId.Id); // // EmployeeExtraPropertyHistory updatedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Updated"); // // foreach (var prop in generalInfoPhysicalIdAuditProps) // // { // // updatedPhIdHistory.PropertyChanges = new List<EmployeeTypePropertyChange>(); // // EmployeeTypePropertyChange propertyChange = new EmployeeTypePropertyChange(); // // object origVal = prop.GetValue(oldPhId); // // propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); // // object newVal = prop.GetValue(curPhId); // // propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); // // if (propertyChange.OriginalValue == propertyChange.NewValue) continue; // // propertyChange.PropertyName = prop.Name; // // if (prop.Name.EndsWith("Id")) // // { // // try // // { // // string valuePropName = prop.Name.TrimEnd('d', 'I'); // // propertyChange.PropertyName = valuePropName; // // var valueProp = typeof(PhysicalID).GetProperty(valuePropName); // // DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(oldPhId); // // if (_origValObj == null) _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); // // string _origVal = _origValObj.Value; // // propertyChange.OriginalValue = origVal == null ? "" : _origVal; // // DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(curPhId); // // if (_newValObj == null) _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); // // string _newVal = _newValObj.Value; // // propertyChange.NewValue = _newValObj == null ? "" : _newVal; // // } // // catch (Exception ex) // // { // // } // // } // // propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; // // updatedPhIdHistory.PropertyChanges.Add(propertyChange); // // } // // physicalIdsHistory.Add(updatedPhIdHistory); // //} // //for (int i = 0; i < DeletedPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // EmployeeExtraPropertyHistory deletedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Deleted"); // // physicalIdsHistory.Add(deletedPhIdHistory); // //} // entityChangeInfo.SetProperty("extraPropertiesHistory", allExtraPropertyHistories); //} #endregion AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } curDepartmentTemplate.Name = departmentTemplate_Dto.Name; curDepartmentTemplate.NameLocalized = departmentTemplate_Dto.NameLocalized; curDepartmentTemplate.Code = departmentTemplate_Dto.Code; //curDepartmentTemplate.ReviewPeriod = departmentTemplate_Dto.ReviewPeriod; curDepartmentTemplate.ValidityFromDate = departmentTemplate_Dto.ValidityFromDate; curDepartmentTemplate.ValidityToDate = departmentTemplate_Dto.ValidityToDate; OS_DepartmentCostCenterTemplate_Dto[] depCostCenters = departmentTemplate_Dto.DepartmentCostCenterTemplates.ToArray(); int[] curPosCostCentersIds = curDepartmentTemplate.DepartmentCostCenterTemplates != null && curDepartmentTemplate.DepartmentCostCenterTemplates.Count > 0 ? curDepartmentTemplate.DepartmentCostCenterTemplates.Select(x => x.DepartmentTemplate.Id).ToArray() : new int[0]; List <int> toDeleteCostCenters = new List <int>(); for (int i = 0; i < curPosCostCentersIds.Length; i++) { OS_DepartmentCostCenterTemplate curDepartmentCostCenter = curDepartmentTemplate.DepartmentCostCenterTemplates.First(x => x.DepartmentTemplate.Id == curPosCostCentersIds[i]); if (!depCostCenters.Any(x => x.DepartmentTemplateId == curPosCostCentersIds[i] && x.CreationTime == curDepartmentCostCenter.CreationTime)) { curDepartmentTemplate.DepartmentCostCenterTemplates.Remove(curDepartmentTemplate.DepartmentCostCenterTemplates.First(x => x.DepartmentTemplate.Id == curPosCostCentersIds[i])); toDeleteCostCenters.Add(curPosCostCentersIds[i]); } } for (int i = 0; i < depCostCenters.Length; i++) { if (!curDepartmentTemplate.DepartmentCostCenterTemplates.Any(x => x.CostCenterId == depCostCenters[i].CostCenter.Id && x.CreationTime == depCostCenters[i].CreationTime)) { curDepartmentTemplate.DepartmentCostCenterTemplates.Add(new OS_DepartmentCostCenterTemplate() { CostCenterId = depCostCenters[i].CostCenter.Id, Percentage = depCostCenters[i].Percentage }); } else { var _departmentCostCenter = curDepartmentTemplate.DepartmentCostCenterTemplates.First(x => x.DepartmentTemplateId == depCostCenters[i].DepartmentTemplate.Id); //_departmentLoc.DepartmentValidityStart = posCostCenters[i].DepartmentValidityStart; //_departmentLoc.DepartmentValidityEnd = posCostCenters[i].DepartmentValidityEnd; //_departmentLoc.Name = posCostCenters[i].Name; //curDepartment.DepartmentCostCenterTemplates.Remove(curDepartment.DepartmentCostCenterTemplates.First(x => x.DepartmentTemplateId == _departmentLoc.DepartmentTemplateId)); await OS_DepartmentTemplateAppService.DepartmentCostCentersTemplateRepo.UpdateAsync(_departmentCostCenter); } } for (int i = 0; i < toDeleteCostCenters.Count; i++) { await OS_DepartmentTemplateAppService.DepartmentCostCentersTemplateRepo.DeleteAsync(x => x.DepartmentTemplateId == toDeleteCostCenters[i]); } //OS_PositionTemplate_Dto[] depPositions = departmentTemplate_Dto.PositionTemplates.ToArray(); //int[] curDepPositionsIds = curDepartmentTemplate.PositionTemplates != null && curDepartmentTemplate.PositionTemplates.Count > 0? curDepartmentTemplate.PositionTemplates.Select(x => x.Id).ToArray() : new int[0]; //List<OS_PositionTemplate> toDeletePositions = new List<OS_PositionTemplate>(); //for (int i = 0; i < curDepPositionsIds.Length; i++) //{ // OS_PositionTemplate curDepartmentPosition = curDepartmentTemplate.PositionTemplates.First(x => x.Id == curDepPositionsIds[i]); // if (!depPositions.Any(x => x.Id == curDepPositionsIds[i] && x.CreationTime == curDepartmentPosition.CreationTime)) // { // //curDepartmentTemplate.PositionTemplates.Remove(curDepartmentPosition); // toDeletePositions.Add(curDepartmentPosition); // } // else // { // } //} //for (int i = 0; i < depPositions.Length; i++) //{ // if (!curDepartmentTemplate.PositionTemplates.Any(x => x.Id == depPositions[i].Id && x.CreationTime == depPositions[i].CreationTime)) // { // OS_PositionTemplate positionTemplate = await OS_DepartmentTemplateAppService.PositionTemplateRepo.GetAsync(depPositions[i].Id); // curDepartmentTemplate.PositionTemplates.Add(positionTemplate); // positionTemplate.DepartmentTemplateId = curDepartmentTemplate.Id; // positionTemplate.DepartmentTemplate = null; // } // else // { // var _positionLoc = curDepartmentTemplate.PositionTemplates.First(x => x.Id == depPositions[i].Id); // //_departmentLoc.PositionValidityStart = depPositions[i].PositionValidityStart; // //_departmentLoc.PositionValidityEnd = depPositions[i].PositionValidityEnd; // //_departmentLoc.Name = depPositions[i].Name; // //curDepartment.DepartmentPositionTemplates.Remove(curDepartment.DepartmentPositionTemplates.First(x => x.PositionTemplateId == _departmentLoc.PositionTemplateId)); // //await OS_DepartmentTemplateAppService.PositionTemplateRepo.UpdateAsync(_positionLoc); // } //} //for (int i = 0; i < toDeletePositions.Count; i++) //{ // curDepartmentTemplate.PositionTemplates.Remove(curDepartmentTemplate.PositionTemplates.First(x => x.Id == toDeletePositions[i].Id && x.CreationTime == toDeletePositions[i].CreationTime)); // if (toDeletePositions[i].PositionJobTemplates != null) // { // for (int y = 0; y < toDeletePositions[i].PositionJobTemplates.Count; y++) // { // await OS_PositionTemplateAppService.PositionJobsTemplateRepo.DeleteAsync(toDeletePositions[i].PositionJobTemplates.ElementAt(y).Id); // } // } // if (toDeletePositions[i].PositionTaskTemplates != null) // { // for (int y = 0; y < toDeletePositions[i].PositionTaskTemplates.Count; y++) // { // await OS_PositionTemplateAppService.PositionTasksTemplateRepo.DeleteAsync(toDeletePositions[i].PositionTaskTemplates.ElementAt(y).Id); // } // } // await OS_DepartmentTemplateAppService.PositionTemplateRepo.DeleteAsync(x => x.Id == toDeletePositions[i].Id && x.CreationTime == toDeletePositions[i].CreationTime); //} OS_DepartmentSubDepartmentTemplate_Dto[] depSubDeps = departmentTemplate_Dto.SubDepartmentTemplates.ToArray(); int[] curDepSubDepsIds = curDepartmentTemplate.SubDepartmentTemplates != null && curDepartmentTemplate.SubDepartmentTemplates.Count > 0? curDepartmentTemplate.SubDepartmentTemplates.Select(x => x.Id).ToArray() : new int[0]; List <OS_DepartmentSubDepartmentTemplate> toDeleteSubDeps = new List <OS_DepartmentSubDepartmentTemplate>(); for (int i = 0; i < curDepSubDepsIds.Length; i++) { OS_DepartmentSubDepartmentTemplate curSubDepartment = curDepartmentTemplate.SubDepartmentTemplates.First(x => x.Id == curDepSubDepsIds[i]); if (!depSubDeps.Any(x => x.Id == curDepSubDepsIds[i] && x.CreationTime == curSubDepartment.CreationTime)) { OS_DepartmentSubDepartmentTemplate item = curDepartmentTemplate.SubDepartmentTemplates.First(x => x.Id == curDepSubDepsIds[i]); curDepartmentTemplate.SubDepartmentTemplates.Remove(item); toDeleteSubDeps.Add(item); } } for (int i = 0; i < depSubDeps.Length; i++) { if (!curDepartmentTemplate.SubDepartmentTemplates.Any(x => x.Id == depSubDeps[i].Id && x.CreationTime == depSubDeps[i].CreationTime)) { if (!depSubDeps[i].SubDepartmentTemplate.ContainsDepartment(curDepartmentTemplate.Id)) { curDepartmentTemplate.SubDepartmentTemplates.Add(new OS_DepartmentSubDepartmentTemplate { SubDepartmentTemplateId = depSubDeps[i].SubDepartmentTemplate.Id, SubDepartmentRelationshipType = depSubDeps[i].SubDepartmentRelationshipType, Name = depSubDeps[i].Name }); } else { Exception ex = new Exception($"Cannot add the parent/sibling department '{depSubDeps[i].SubDepartmentTemplate.Name}', as a sub department."); ex.Data.Add(depSubDeps[i], "main"); ex.Data.Add(depSubDeps[i].SubDepartmentTemplate, "subDepartment"); throw ex; } } else { var _departmentSubDep = curDepartmentTemplate.SubDepartmentTemplates.First(x => x.SubDepartmentTemplateId == depSubDeps[i].SubDepartmentTemplateId); _departmentSubDep.SubDepartmentRelationshipType = depSubDeps[i].SubDepartmentRelationshipType; _departmentSubDep.Name = depSubDeps[i].Name; //curDepartmentTemplate.SubDepartmentTemplates.Remove(curDepartmentTemplate.SubDepartmentTemplates.First(x => x.Id == _departmentLoc.Id)); await OS_DepartmentTemplateAppService.DepartmentSubDepartmentTemplateRepo.UpdateAsync(_departmentSubDep); } } for (int i = 0; i < toDeleteSubDeps.Count; i++) { await OS_DepartmentTemplateAppService.DepartmentSubDepartmentTemplateRepo.DeleteAsync(x => x.SubDepartmentTemplateId == toDeleteSubDeps[i].SubDepartmentTemplateId && x.CreationTime == toDeleteSubDeps[i].CreationTime); } OS_DepartmentTemplate_Dto updated = ObjectMapper.Map <OS_DepartmentTemplate, OS_DepartmentTemplate_Dto>(await OS_DepartmentTemplateAppService.Repository.UpdateAsync(curDepartmentTemplate)); OS_DepartmentTemplate_Dto updatedDto = await OS_DepartmentTemplateAppService.GetDepartmentTemplateAsync(updated.Id); return(StatusCode(200, updatedDto)); } else { departmentTemplate_Dto.Id = 0; //departmentTemplate_Dto.PositionTemplates.ForEach(x => { x.Id = 0; x.Id = x.Id; }); departmentTemplate_Dto.SubDepartmentTemplates.ForEach(x => { x.Id = 0; x.SubDepartmentTemplateId = x.SubDepartmentTemplate.Id; x.SubDepartmentTemplate = null; }); departmentTemplate_Dto.DepartmentCostCenterTemplates.ForEach(x => { x.Id = 0; x.CostCenterId = x.CostCenter.Id; x.CostCenter = null; }); OS_DepartmentTemplate_Dto added = await OS_DepartmentTemplateAppService.CreateAsync(departmentTemplate_Dto); OS_DepartmentTemplate_Dto addeddDto = await OS_DepartmentTemplateAppService.GetDepartmentTemplateAsync(added.Id); if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = added.Id.ToString(); entityChangeInfo.EntityTenantId = added.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Created; entityChangeInfo.EntityTypeFullName = typeof(OS_DepartmentTemplate).FullName; AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } return(StatusCode(200, addeddDto)); } } catch (Exception ex) { return(StatusCode(500, ex)); } } return(StatusCode(500)); }
public async Task <IActionResult> OnPostFunctionTemplate() { if (ModelState.IsValid) { try { var FormData = Request.Form; OS_FunctionTemplate_Dto functionTemplate_Dto = JsonSerializer.Deserialize <OS_FunctionTemplate_Dto>(FormData["info"]); bool IsEditing = functionTemplate_Dto.Id > 0; if (IsEditing) { OS_FunctionTemplate curFunctionTemplate = await OS_FunctionTemplateAppService.Repository.GetAsync(functionTemplate_Dto.Id); if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = functionTemplate_Dto.Id.ToString(); entityChangeInfo.EntityTenantId = functionTemplate_Dto.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Updated; entityChangeInfo.EntityTypeFullName = typeof(OS_FunctionTemplate).FullName; entityChangeInfo.PropertyChanges = new List <EntityPropertyChangeInfo>(); List <EntityPropertyChangeInfo> entityPropertyChanges = new List <EntityPropertyChangeInfo>(); var auditProps = typeof(OS_FunctionTemplate).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); OS_FunctionTemplate mappedInput = ObjectMapper.Map <OS_FunctionTemplate_Dto, OS_FunctionTemplate>(functionTemplate_Dto); foreach (var prop in auditProps) { EntityPropertyChangeInfo propertyChange = new EntityPropertyChangeInfo(); object origVal = prop.GetValue(curFunctionTemplate); propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); object newVal = prop.GetValue(mappedInput); propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); if (propertyChange.OriginalValue == propertyChange.NewValue) { continue; } propertyChange.PropertyName = prop.Name; if (prop.Name.EndsWith("Id")) { try { string valuePropName = prop.Name.TrimEnd('d', 'I'); propertyChange.PropertyName = valuePropName; var valueProp = typeof(OS_FunctionTemplate).GetProperty(valuePropName); DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(functionTemplate_Dto); if (_origValObj == null) { _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); } string _origVal = _origValObj.Value; propertyChange.OriginalValue = origVal == null ? "" : _origVal; DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(mappedInput); if (_newValObj == null) { _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); } string _newVal = _newValObj.Value; propertyChange.NewValue = _newValObj == null ? "" : _newVal; } catch (Exception ex) { } } propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; entityChangeInfo.PropertyChanges.Add(propertyChange); } #region ExtraProperties //List<EmployeeExtraPropertyHistory> allExtraPropertyHistories = new List<EmployeeExtraPropertyHistory>(); //if (departmentTemplate_Dto.ExtraProperties != curFunctionTemplate.ExtraProperties) //{ // //GeneralInfo oldGeneralInfo = department.GetProperty<GeneralInfo>("generalInfo"); // //List<EmployeeExtraPropertyHistory> physicalIdsHistory = new List<EmployeeExtraPropertyHistory>(); // //var generalInfoPhysicalIdAuditProps = typeof(PhysicalID).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); // //List<PhysicalId<Guid>> NewPhysicalIds = generalInfo.PhysicalIds.Where(x => !oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //List<PhysicalId<Guid>> UpdatedPhysicalIds = generalInfo.PhysicalIds.Where(x => oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //List<PhysicalId<Guid>> DeletedPhysicalIds = oldGeneralInfo.PhysicalIds.Where(x => !generalInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //for (int i = 0; i < NewPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // EmployeeExtraPropertyHistory newPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Created"); // // physicalIdsHistory.Add(newPhIdHistory); // //} // //for (int i = 0; i < UpdatedPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // PhysicalId<Guid> oldPhId = oldGeneralInfo.PhysicalIds.First(x => x.Id == curPhId.Id); // // EmployeeExtraPropertyHistory updatedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Updated"); // // foreach (var prop in generalInfoPhysicalIdAuditProps) // // { // // updatedPhIdHistory.PropertyChanges = new List<EmployeeTypePropertyChange>(); // // EmployeeTypePropertyChange propertyChange = new EmployeeTypePropertyChange(); // // object origVal = prop.GetValue(oldPhId); // // propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); // // object newVal = prop.GetValue(curPhId); // // propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); // // if (propertyChange.OriginalValue == propertyChange.NewValue) continue; // // propertyChange.PropertyName = prop.Name; // // if (prop.Name.EndsWith("Id")) // // { // // try // // { // // string valuePropName = prop.Name.TrimEnd('d', 'I'); // // propertyChange.PropertyName = valuePropName; // // var valueProp = typeof(PhysicalID).GetProperty(valuePropName); // // DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(oldPhId); // // if (_origValObj == null) _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); // // string _origVal = _origValObj.Value; // // propertyChange.OriginalValue = origVal == null ? "" : _origVal; // // DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(curPhId); // // if (_newValObj == null) _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); // // string _newVal = _newValObj.Value; // // propertyChange.NewValue = _newValObj == null ? "" : _newVal; // // } // // catch (Exception ex) // // { // // } // // } // // propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; // // updatedPhIdHistory.PropertyChanges.Add(propertyChange); // // } // // physicalIdsHistory.Add(updatedPhIdHistory); // //} // //for (int i = 0; i < DeletedPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // EmployeeExtraPropertyHistory deletedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Deleted"); // // physicalIdsHistory.Add(deletedPhIdHistory); // //} // entityChangeInfo.SetProperty("extraPropertiesHistory", allExtraPropertyHistories); //} #endregion AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } curFunctionTemplate.Name = functionTemplate_Dto.Name; curFunctionTemplate.NameLocalized = functionTemplate_Dto.NameLocalized; curFunctionTemplate.Code = functionTemplate_Dto.Code; curFunctionTemplate.ReviewPeriod = functionTemplate_Dto.ReviewPeriod; curFunctionTemplate.ReviewPeriodDays = functionTemplate_Dto.ReviewPeriodDays; curFunctionTemplate.ValidityFromDate = functionTemplate_Dto.ValidityFromDate; curFunctionTemplate.ValidityToDate = functionTemplate_Dto.ValidityToDate; curFunctionTemplate.Description = functionTemplate_Dto.Description; curFunctionTemplate.DoesKPI = functionTemplate_Dto.DoesKPI; curFunctionTemplate.CompensationMatrix = null; curFunctionTemplate.CompensationMatrixId = functionTemplate_Dto.CompensationMatrixId; #region Child Entities OS_FunctionSkillTemplate_Dto[] functionSkills = functionTemplate_Dto.FunctionSkillTemplates.ToArray(); int[] curFunctionSkillsIds = curFunctionTemplate.FunctionSkillTemplates != null && curFunctionTemplate.FunctionSkillTemplates.Count > 0 ? curFunctionTemplate.FunctionSkillTemplates.Select(x => x.SkillTemplate.Id).ToArray() : new int[0]; List <int> toDeleteSkills = new List <int>(); for (int i = 0; i < curFunctionSkillsIds.Length; i++) { OS_FunctionSkillTemplate curFunctionSkill = curFunctionTemplate.FunctionSkillTemplates.First(x => x.SkillTemplate.Id == curFunctionSkillsIds[i]); if (!functionSkills.Any(x => x.SkillTemplate.Id == curFunctionSkillsIds[i])) { curFunctionTemplate.FunctionSkillTemplates.Remove(curFunctionTemplate.FunctionSkillTemplates.First(x => x.SkillTemplate.Id == curFunctionSkillsIds[i])); toDeleteSkills.Add(curFunctionSkillsIds[i]); } } for (int i = 0; i < functionSkills.Length; i++) { if (!curFunctionTemplate.FunctionSkillTemplates.Any(x => x.SkillTemplateId == functionSkills[i].SkillTemplate.Id)) { curFunctionTemplate.FunctionSkillTemplates.Add(new OS_FunctionSkillTemplate() { SkillTemplateId = functionSkills[i].SkillTemplate.Id }); } else { var _functionSkill = curFunctionTemplate.FunctionSkillTemplates.First(x => x.SkillTemplateId == functionSkills[i].SkillTemplate.Id); //_functionLoc.FunctionValidityStart = posFunctions[i].FunctionValidityStart; //_functionLoc.FunctionValidityEnd = posFunctions[i].FunctionValidityEnd; //_functionLoc.Name = posFunctions[i].Name; //curFunction.FunctionSkillTemplates.Remove(curFunction.FunctionSkillTemplates.First(x => x.FunctionTemplateId == _functionLoc.FunctionTemplateId)); await OS_FunctionTemplateAppService.SkillsRepository.UpdateAsync(_functionSkill); } } for (int i = 0; i < toDeleteSkills.Count; i++) { await OS_FunctionTemplateAppService.SkillsRepository.DeleteAsync(x => x.SkillTemplateId == toDeleteSkills[i]); } OS_FunctionAcademiaTemplate_Dto[] functionAcademia = functionTemplate_Dto.FunctionAcademiaTemplates.ToArray(); int[] curFunctionAcademiaIds = curFunctionTemplate.FunctionAcademiaTemplates != null && curFunctionTemplate.FunctionAcademiaTemplates.Count > 0 ? curFunctionTemplate.FunctionAcademiaTemplates.Select(x => x.AcademiaTemplate.Id).ToArray() : new int[0]; List <int> toDeleteAcademia = new List <int>(); for (int i = 0; i < curFunctionAcademiaIds.Length; i++) { OS_FunctionAcademiaTemplate curFunctionAcademia = curFunctionTemplate.FunctionAcademiaTemplates.First(x => x.AcademiaTemplate.Id == curFunctionAcademiaIds[i]); if (!functionAcademia.Any(x => x.AcademiaTemplate.Id == curFunctionAcademiaIds[i])) { curFunctionTemplate.FunctionAcademiaTemplates.Remove(curFunctionTemplate.FunctionAcademiaTemplates.First(x => x.AcademiaTemplate.Id == curFunctionAcademiaIds[i])); toDeleteSkills.Add(curFunctionAcademiaIds[i]); } } for (int i = 0; i < functionAcademia.Length; i++) { if (!curFunctionTemplate.FunctionAcademiaTemplates.Any(x => x.AcademiaTemplateId == functionAcademia[i].AcademiaTemplate.Id)) { curFunctionTemplate.FunctionAcademiaTemplates.Add(new OS_FunctionAcademiaTemplate() { AcademiaTemplateId = functionAcademia[i].AcademiaTemplate.Id }); } else { var _functionAcademia = curFunctionTemplate.FunctionAcademiaTemplates.First(x => x.AcademiaTemplateId == functionAcademia[i].AcademiaTemplate.Id); //_functionLoc.FunctionValidityStart = posFunctions[i].FunctionValidityStart; //_functionLoc.FunctionValidityEnd = posFunctions[i].FunctionValidityEnd; //_functionLoc.Name = posFunctions[i].Name; //curFunction.FunctionAcademiaTemplates.Remove(curFunction.FunctionAcademiaTemplates.First(x => x.FunctionTemplateId == _functionLoc.FunctionTemplateId)); await OS_FunctionTemplateAppService.AcademiaRepository.UpdateAsync(_functionAcademia); } } for (int i = 0; i < toDeleteAcademia.Count; i++) { await OS_FunctionTemplateAppService.AcademiaRepository.DeleteAsync(x => x.AcademiaTemplateId == toDeleteAcademia[i]); } #endregion OS_FunctionTemplate_Dto updated = ObjectMapper.Map <OS_FunctionTemplate, OS_FunctionTemplate_Dto>(await OS_FunctionTemplateAppService.Repository.UpdateAsync(curFunctionTemplate)); updated.FunctionSkillTemplates = ObjectMapper.Map <List <OS_FunctionSkillTemplate>, List <OS_FunctionSkillTemplate_Dto> >(curFunctionTemplate.FunctionSkillTemplates.ToList()); updated.FunctionAcademiaTemplates = ObjectMapper.Map <List <OS_FunctionAcademiaTemplate>, List <OS_FunctionAcademiaTemplate_Dto> >(curFunctionTemplate.FunctionAcademiaTemplates.ToList()); updated.CompensationMatrix = await OS_FunctionTemplateAppService.GetCompensationMatrixAsync(updated.CompensationMatrixId); return(StatusCode(200, updated)); } else { functionTemplate_Dto.Id = 0; if (functionTemplate_Dto.FunctionSkillTemplates != null) { functionTemplate_Dto.FunctionSkillTemplates.ForEach(x => { x.Id = 0; x.SkillTemplateId = x.SkillTemplate.Id; x.SkillTemplate = null; }); } if (functionTemplate_Dto.FunctionAcademiaTemplates != null) { functionTemplate_Dto.FunctionAcademiaTemplates.ForEach(x => { x.Id = 0; x.AcademiaTemplateId = x.AcademiaTemplate.Id; x.AcademiaTemplate = null; }); } functionTemplate_Dto.CompensationMatrix = null; OS_FunctionTemplate_Dto added = await OS_FunctionTemplateAppService.CreateAsync(functionTemplate_Dto); added = await OS_FunctionTemplateAppService.GetAsync(added.Id); if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = added.Id.ToString(); entityChangeInfo.EntityTenantId = added.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Created; entityChangeInfo.EntityTypeFullName = typeof(OS_FunctionTemplate).FullName; AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } return(StatusCode(200, added)); } } catch (Exception ex) { } } return(StatusCode(500)); }
public async Task <IActionResult> OnPostCompany() { if (ModelState.IsValid) { try { var FormData = Request.Form; Company_Dto company = JsonSerializer.Deserialize <Company_Dto>(FormData["info"]); //List<CompanyLocation_Dto> addresses = JsonSerializer.Deserialize<List<CompanyLocation_Dto>>(Request.Form["locations"]); //company.SetProperty("addresses", addresses); bool logoChanged = false; if (FormData.Files.Count > 0 && FormData.Files.Any(x => x.Name == "CompanyPic")) { IFormFile formFile = FormData.Files.First(x => x.Name == "CompanyPic"); string uploadedFileName = UploadedFile(formFile); company.CompanyLogo = uploadedFileName; logoChanged = true; } bool IsEditing = company.Id != Guid.Empty; if (IsEditing) { Company curCompany = await CompanyAppService.Repository.GetAsync(company.Id); if (curCompany.CompanyLogo != null && curCompany.CompanyLogo != "noimage.jpg" && logoChanged) { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "Uploads"); string filePath = Path.Combine(uploadsFolder, curCompany.CompanyLogo); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } } if (logoChanged) { curCompany.CompanyLogo = company.CompanyLogo; } else { company.CompanyLogo = curCompany.CompanyLogo; } if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = company.Id.ToString(); entityChangeInfo.EntityTenantId = company.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Updated; entityChangeInfo.EntityTypeFullName = typeof(Company).FullName; entityChangeInfo.PropertyChanges = new List <EntityPropertyChangeInfo>(); List <EntityPropertyChangeInfo> entityPropertyChanges = new List <EntityPropertyChangeInfo>(); var auditProps = typeof(Company).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); Company mappedInput = ObjectMapper.Map <Company_Dto, Company>(company); foreach (var prop in auditProps) { EntityPropertyChangeInfo propertyChange = new EntityPropertyChangeInfo(); object origVal = prop.GetValue(curCompany); propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); object newVal = prop.GetValue(mappedInput); propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); if (propertyChange.OriginalValue == propertyChange.NewValue) { continue; } propertyChange.PropertyName = prop.Name; if (prop.Name.EndsWith("Id")) { try { string valuePropName = prop.Name.TrimEnd('d', 'I'); propertyChange.PropertyName = valuePropName; var valueProp = typeof(Company).GetProperty(valuePropName); DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(company); if (_origValObj == null) { _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); } string _origVal = _origValObj.Value; propertyChange.OriginalValue = origVal == null ? "" : _origVal; DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(mappedInput); if (_newValObj == null) { _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); } string _newVal = _newValObj.Value; propertyChange.NewValue = _newValObj == null ? "" : _newVal; } catch (Exception ex) { } } propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; entityChangeInfo.PropertyChanges.Add(propertyChange); } #region ExtraProperties List <EmployeeExtraPropertyHistory> allExtraPropertyHistories = new List <EmployeeExtraPropertyHistory>(); if (company.ExtraProperties != curCompany.ExtraProperties) { //GeneralInfo oldGeneralInfo = company.GetProperty<GeneralInfo>("generalInfo"); //List<EmployeeExtraPropertyHistory> physicalIdsHistory = new List<EmployeeExtraPropertyHistory>(); //var generalInfoPhysicalIdAuditProps = typeof(PhysicalID).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); //List<PhysicalId<Guid>> NewPhysicalIds = generalInfo.PhysicalIds.Where(x => !oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); //List<PhysicalId<Guid>> UpdatedPhysicalIds = generalInfo.PhysicalIds.Where(x => oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); //List<PhysicalId<Guid>> DeletedPhysicalIds = oldGeneralInfo.PhysicalIds.Where(x => !generalInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); //for (int i = 0; i < NewPhysicalIds.Count; i++) //{ // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // EmployeeExtraPropertyHistory newPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Created"); // physicalIdsHistory.Add(newPhIdHistory); //} //for (int i = 0; i < UpdatedPhysicalIds.Count; i++) //{ // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // PhysicalId<Guid> oldPhId = oldGeneralInfo.PhysicalIds.First(x => x.Id == curPhId.Id); // EmployeeExtraPropertyHistory updatedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Updated"); // foreach (var prop in generalInfoPhysicalIdAuditProps) // { // updatedPhIdHistory.PropertyChanges = new List<EmployeeTypePropertyChange>(); // EmployeeTypePropertyChange propertyChange = new EmployeeTypePropertyChange(); // object origVal = prop.GetValue(oldPhId); // propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); // object newVal = prop.GetValue(curPhId); // propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); // if (propertyChange.OriginalValue == propertyChange.NewValue) continue; // propertyChange.PropertyName = prop.Name; // if (prop.Name.EndsWith("Id")) // { // try // { // string valuePropName = prop.Name.TrimEnd('d', 'I'); // propertyChange.PropertyName = valuePropName; // var valueProp = typeof(PhysicalID).GetProperty(valuePropName); // DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(oldPhId); // if (_origValObj == null) _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); // string _origVal = _origValObj.Value; // propertyChange.OriginalValue = origVal == null ? "" : _origVal; // DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(curPhId); // if (_newValObj == null) _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); // string _newVal = _newValObj.Value; // propertyChange.NewValue = _newValObj == null ? "" : _newVal; // } // catch (Exception ex) // { // } // } // propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; // updatedPhIdHistory.PropertyChanges.Add(propertyChange); // } // physicalIdsHistory.Add(updatedPhIdHistory); //} //for (int i = 0; i < DeletedPhysicalIds.Count; i++) //{ // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // EmployeeExtraPropertyHistory deletedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Deleted"); // physicalIdsHistory.Add(deletedPhIdHistory); //} entityChangeInfo.SetProperty("extraPropertiesHistory", allExtraPropertyHistories); } #endregion AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } curCompany.CompanyName = company.CompanyName; curCompany.CompanyNameLocalized = company.CompanyNameLocalized; curCompany.CompanyLogo = company.CompanyLogo; curCompany.CompanyCode = company.CompanyCode; curCompany.Status = company.Status; curCompany.TaxID = company.TaxID; curCompany.SocialInsuranceID = company.SocialInsuranceID; curCompany.VATID = company.VATID; curCompany.RegistrationID = company.RegistrationID; curCompany.LabourOfficeId = company.LabourOfficeId; curCompany.Language = company.Language; CompanyLocation_Dto[] compLocs = company.CompanyLocations.ToArray(); Guid[] curCompLocsIds = curCompany.CompanyLocations.Select(x => x.Location.Id).ToArray(); List <Guid> toDeleteLocs = new List <Guid>(); for (int i = 0; i < curCompLocsIds.Length; i++) { CompanyLocation curCompanyLocation = curCompany.CompanyLocations.First(x => x.Location.Id == curCompLocsIds[i]); if (!compLocs.Any(x => x.LocationId == curCompLocsIds[i] && x.CreationTime == curCompanyLocation.CreationTime)) { curCompany.CompanyLocations.Remove(curCompany.CompanyLocations.First(x => x.Location.Id == curCompLocsIds[i])); toDeleteLocs.Add(curCompLocsIds[i]); } } for (int i = 0; i < compLocs.Length; i++) { if (!curCompany.CompanyLocations.Any(x => x.LocationId == compLocs[i].Location.Id && x.CreationTime == compLocs[i].CreationTime)) { curCompany.CompanyLocations.Add(new CompanyLocation() { Name = compLocs[i].Name, LocationValidityStart = compLocs[i].LocationValidityStart, LocationValidityEnd = compLocs[i].LocationValidityEnd, LocationId = compLocs[i].Location.Id, LocationType = compLocs[i].LocationType }); } else { var _companyLoc = curCompany.CompanyLocations.First(x => x.LocationId == compLocs[i].Location.Id); _companyLoc.LocationValidityStart = compLocs[i].LocationValidityStart; _companyLoc.LocationValidityEnd = compLocs[i].LocationValidityEnd; _companyLoc.Name = compLocs[i].Name; //curCompany.CompanyLocations.Remove(curCompany.CompanyLocations.First(x => x.LocationId == _companyLoc.LocationId)); await CompanyAppService.LocationsRepository.UpdateAsync(_companyLoc); } } CompanyCurrency_Dto[] compCurrencies = company.CompanyCurrencies.ToArray(); int[] curCompCurrenciesIds = curCompany.CompanyCurrencies.Select(x => x.Currency.Id).ToArray(); for (int i = 0; i < compCurrencies.Length; i++) { if (!curCompCurrenciesIds.Contains(compCurrencies[i].Currency.Id)) { curCompany.CompanyCurrencies.Add(new CompanyCurrency() { ExchangeRate = compCurrencies[i].ExchangeRate, CurrencyId = compCurrencies[i].Currency.Id, Status = compCurrencies[i].Status }); } else { var _companyCurrency = curCompany.CompanyCurrencies.First(x => x.CurrencyId == compCurrencies[i].Currency.Id); _companyCurrency.ExchangeRate = compCurrencies[i].ExchangeRate; _companyCurrency.Status = compCurrencies[i].Status; //curCompany.CompanyLocations.Remove(curCompany.CompanyLocations.First(x => x.LocationId == _companyLoc.LocationId)); await CompanyAppService.CurrenciesRepository.UpdateAsync(_companyCurrency); } } List <int> toDeleteCurrencies = new List <int>(); for (int i = 0; i < curCompCurrenciesIds.Length; i++) { if (!compCurrencies.Any(x => x.Currency.Id == curCompCurrenciesIds[i])) { curCompany.CompanyCurrencies.Remove(curCompany.CompanyCurrencies.First(x => x.CurrencyId == curCompCurrenciesIds[i])); toDeleteCurrencies.Add(curCompCurrenciesIds[i]); } } CompanyPrintSize_Dto[] compPrintSizes = company.CompanyPrintSizes.ToArray(); int[] curCompPrintSizesIds = curCompany.CompanyPrintSizes.Select(x => x.Id).ToArray(); for (int i = 0; i < compPrintSizes.Length; i++) { if (!curCompPrintSizesIds.Contains(compPrintSizes[i].Id)) { curCompany.CompanyPrintSizes.Add(new CompanyPrintSize() { PrintSize = compPrintSizes[i].PrintSize }); } } List <int> toDeletePrintSizes = new List <int>(); for (int i = 0; i < curCompPrintSizesIds.Length; i++) { if (!compPrintSizes.Any(x => x.Id == curCompPrintSizesIds[i])) { curCompany.CompanyPrintSizes.Remove(curCompany.CompanyPrintSizes.First(x => x.Id == curCompPrintSizesIds[i])); toDeletePrintSizes.Add(curCompPrintSizesIds[i]); } } CompanyDocument_Dto[] compDocuments = company.CompanyDocuments.ToArray(); int[] curCompDocumentsIds = curCompany.CompanyDocuments.Select(x => x.Id).ToArray(); for (int i = 0; i < compDocuments.Length; i++) { if (!curCompDocumentsIds.Contains(compDocuments[i].Id)) { string curFileName = compDocuments[i].Document.Name; if (FormData.Files.Any(x => x.Name == curFileName)) { var curDoc = compDocuments[i].Document; if (curDoc.Id == Guid.Empty) { IFormFile document = FormData.Files.First(x => x.Name == curFileName); string uploadedFileName = UploadedFile(document); Document_Dto doc = new Document_Dto(GuidGenerator.Create()); doc.ReferenceNo = (new Random()).Next(10, 90) * (new Random()).Next(10000, 90000); doc.Name = company.CompanyName + "_" + compDocuments[i].DocumentType.Value + "_" + compDocuments[i].Id; doc.NameLocalized = company.CompanyNameLocalized + "_" + compDocuments[i].DocumentType.Value + "_" + compDocuments[i].Id; doc.Description = $"Soft copy of {compDocuments[i].DocumentType.Value}"; doc.OwnerId = company.Id; doc.OwnerTypeId = DictionaryValuesRepo.WithDetails().Where(x => x.Value == "Company").First(x => x.ValueType.ValueTypeFor == ValueTypeModules.OwnerType).Id; doc.DocumentTypeId = compDocuments[i].DocumentType.Id; doc.IssuedFromId = doc.OwnerTypeId; doc.IssueDate = compDocuments[i].IssueDate; doc.ExpiryDate = compDocuments[i].EndDate; doc.FileName = uploadedFileName; Document_Dto created = await documentAppService.CreateAsync(doc); compDocuments[i].DocumentId = created.Id; } } curCompany.CompanyDocuments.Add(new CompanyDocument() { DocumentTitle = compDocuments[i].DocumentTitle, DocumentTitleLocalized = compDocuments[i].DocumentTitleLocalized, DocumentTypeId = compDocuments[i].DocumentType.Id, DocumentId = compDocuments[i].DocumentId, IssueDate = compDocuments[i].IssueDate, EndDate = compDocuments[i].EndDate }); } } List <CompanyDocument> toDeleteDocuments = new List <CompanyDocument>(); for (int i = 0; i < curCompDocumentsIds.Length; i++) { if (!compDocuments.Any(x => x.Id == curCompDocumentsIds[i])) { var doc = curCompany.CompanyDocuments.First(x => x.Id == curCompDocumentsIds[i]); toDeleteDocuments.Add(doc); curCompany.CompanyDocuments.Remove(doc); } } for (int i = 0; i < toDeletePrintSizes.Count; i++) { await CompanyAppService.PrintSizesRepository.DeleteAsync(x => x.Id == toDeletePrintSizes[i]); } for (int i = 0; i < toDeleteLocs.Count; i++) { await CompanyAppService.LocationsRepository.DeleteAsync(x => x.LocationId == toDeleteLocs[i]); } for (int i = 0; i < toDeleteCurrencies.Count; i++) { await CompanyAppService.CurrenciesRepository.DeleteAsync(x => x.CurrencyId == toDeleteCurrencies[i]); } for (int i = 0; i < toDeleteDocuments.Count; i++) { await documentAppService.Repository.DeleteAsync(toDeleteDocuments[i].DocumentId); await CompanyAppService.DocumentsRepository.DeleteAsync(x => x.Id == toDeleteDocuments[i].Id); } Company_Dto updated = ObjectMapper.Map <Company, Company_Dto>(await CompanyAppService.Repository.UpdateAsync(curCompany)); return(StatusCode(200, updated)); } else { List <Document_Dto> documentsToAdd = new List <Document_Dto>(); List <CompanyDocument_Dto> companyDocuments = company.CompanyDocuments; if (FormData.Files.Count > 0) { for (int i = 0; i < companyDocuments.Count; i++) { CompanyDocument_Dto compDoc = companyDocuments[i]; string curFileName = compDoc.Document.Name; if (FormData.Files.Any(x => x.Name == curFileName)) { var curDoc = compDoc.Document; if (curDoc.Id == Guid.Empty) { IFormFile document = FormData.Files.First(x => x.Name == curFileName); string uploadedFileName = UploadedFile(document); Document_Dto doc = new Document_Dto(GuidGenerator.Create()); doc.ReferenceNo = (new Random()).Next(10, 90) * (new Random()).Next(10000, 90000); doc.Name = company.CompanyName + "_" + compDoc.DocumentType.Value + "_" + compDoc.Id; doc.NameLocalized = company.CompanyNameLocalized + "_" + compDoc.DocumentType.Value + "_" + compDoc.Id; doc.Description = $"Soft copy of {compDoc.DocumentType.Value}"; doc.OwnerId = company.Id; doc.OwnerTypeId = DictionaryValuesRepo.WithDetails().Where(x => x.Value == "Company").First(x => x.ValueType.ValueTypeFor == ValueTypeModules.OwnerType).Id; doc.DocumentTypeId = compDoc.DocumentTypeId; doc.IssuedFromId = compDoc.Document.IssuedFromId; doc.IssueDate = compDoc.IssueDate; doc.ExpiryDate = compDoc.EndDate; doc.FileName = uploadedFileName; Document_Dto created = await documentAppService.CreateAsync(doc); compDoc.DocumentId = created.Id; } } } if (company.CompanyLogo == null) { company.CompanyLogo = "noimage.jpg"; } } for (int i = 0; i < documentsToAdd.Count; i++) { Document_Dto curDoc = documentsToAdd[i]; } company.Id = Guid.Empty; company.CompanyCurrencies.ForEach(x => { x.Id = 0; x.CurrencyId = x.Currency.Id; x.Currency = null; }); company.CompanyLocations.ForEach(x => { x.Id = 0; x.LocationId = x.Location.Id; x.Location = null; }); company.CompanyPrintSizes.ForEach(x => { x.Id = 0; }); Company_Dto added = await CompanyAppService.CreateAsync(company); if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = added.Id.ToString(); entityChangeInfo.EntityTenantId = added.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Created; entityChangeInfo.EntityTypeFullName = typeof(Company).FullName; AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } return(StatusCode(200, added)); } } catch (Exception ex) { } } return(StatusCode(500)); }
public async Task <IActionResult> OnPostPositionTemplate() { if (ModelState.IsValid) { try { var FormData = Request.Form; OS_PositionTemplate_Dto positionTemplate_Dto = JsonSerializer.Deserialize <OS_PositionTemplate_Dto>(FormData["info"]); //if (positionTemplate_Dto.Level == OS_PositionLevel.One) //{ // OS_DepartmentTemplate curPositionDepTemplate = await OS_DepartmentTemplateAppService.Repository.GetAsync(positionTemplate_Dto.DepartmentTemplateId); // if(curPositionDepTemplate.PositionTemplates.Any(x => x.Level == OS_PositionLevel.One && x.Id != positionTemplate_Dto.Id)) // { // Exception ex = new Exception($"The position '{curPositionDepTemplate.PositionTemplates.First(x => x.Level == OS_PositionLevel.One).Name}' as a level '{App.Helpers.EnumExtensions.GetDescription(OS_PositionLevel.One)}' position already exists in the department '{curPositionDepTemplate.Name}'"); // throw ex; // } //} bool IsEditing = positionTemplate_Dto.Id > 0; if (IsEditing) { OS_PositionTemplate curPositionTemplate = await OS_PositionTemplateAppService.Repository.GetAsync(positionTemplate_Dto.Id); if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = positionTemplate_Dto.Id.ToString(); entityChangeInfo.EntityTenantId = positionTemplate_Dto.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Updated; entityChangeInfo.EntityTypeFullName = typeof(OS_PositionTemplate).FullName; entityChangeInfo.PropertyChanges = new List <EntityPropertyChangeInfo>(); List <EntityPropertyChangeInfo> entityPropertyChanges = new List <EntityPropertyChangeInfo>(); var auditProps = typeof(OS_PositionTemplate).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); OS_PositionTemplate mappedInput = ObjectMapper.Map <OS_PositionTemplate_Dto, OS_PositionTemplate>(positionTemplate_Dto); foreach (var prop in auditProps) { EntityPropertyChangeInfo propertyChange = new EntityPropertyChangeInfo(); object origVal = prop.GetValue(curPositionTemplate); propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); object newVal = prop.GetValue(mappedInput); propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); if (propertyChange.OriginalValue == propertyChange.NewValue) { continue; } propertyChange.PropertyName = prop.Name; if (prop.Name.EndsWith("Id")) { try { string valuePropName = prop.Name.TrimEnd('d', 'I'); propertyChange.PropertyName = valuePropName; var valueProp = typeof(OS_PositionTemplate).GetProperty(valuePropName); DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(positionTemplate_Dto); if (_origValObj == null) { _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); } string _origVal = _origValObj.Value; propertyChange.OriginalValue = origVal == null ? "" : _origVal; DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(mappedInput); if (_newValObj == null) { _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); } string _newVal = _newValObj.Value; propertyChange.NewValue = _newValObj == null ? "" : _newVal; } catch (Exception ex) { } } propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; entityChangeInfo.PropertyChanges.Add(propertyChange); } #region ExtraProperties //List<EmployeeExtraPropertyHistory> allExtraPropertyHistories = new List<EmployeeExtraPropertyHistory>(); //if (positionTemplate_Dto.ExtraProperties != curPositionTemplate.ExtraProperties) //{ // //GeneralInfo oldGeneralInfo = position.GetProperty<GeneralInfo>("generalInfo"); // //List<EmployeeExtraPropertyHistory> physicalIdsHistory = new List<EmployeeExtraPropertyHistory>(); // //var generalInfoPhysicalIdAuditProps = typeof(PhysicalID).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); // //List<PhysicalId<Guid>> NewPhysicalIds = generalInfo.PhysicalIds.Where(x => !oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //List<PhysicalId<Guid>> UpdatedPhysicalIds = generalInfo.PhysicalIds.Where(x => oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //List<PhysicalId<Guid>> DeletedPhysicalIds = oldGeneralInfo.PhysicalIds.Where(x => !generalInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //for (int i = 0; i < NewPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // EmployeeExtraPropertyHistory newPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Created"); // // physicalIdsHistory.Add(newPhIdHistory); // //} // //for (int i = 0; i < UpdatedPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // PhysicalId<Guid> oldPhId = oldGeneralInfo.PhysicalIds.First(x => x.Id == curPhId.Id); // // EmployeeExtraPropertyHistory updatedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Updated"); // // foreach (var prop in generalInfoPhysicalIdAuditProps) // // { // // updatedPhIdHistory.PropertyChanges = new List<EmployeeTypePropertyChange>(); // // EmployeeTypePropertyChange propertyChange = new EmployeeTypePropertyChange(); // // object origVal = prop.GetValue(oldPhId); // // propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); // // object newVal = prop.GetValue(curPhId); // // propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); // // if (propertyChange.OriginalValue == propertyChange.NewValue) continue; // // propertyChange.PropertyName = prop.Name; // // if (prop.Name.EndsWith("Id")) // // { // // try // // { // // string valuePropName = prop.Name.TrimEnd('d', 'I'); // // propertyChange.PropertyName = valuePropName; // // var valueProp = typeof(PhysicalID).GetProperty(valuePropName); // // DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(oldPhId); // // if (_origValObj == null) _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); // // string _origVal = _origValObj.Value; // // propertyChange.OriginalValue = origVal == null ? "" : _origVal; // // DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(curPhId); // // if (_newValObj == null) _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); // // string _newVal = _newValObj.Value; // // propertyChange.NewValue = _newValObj == null ? "" : _newVal; // // } // // catch (Exception ex) // // { // // } // // } // // propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; // // updatedPhIdHistory.PropertyChanges.Add(propertyChange); // // } // // physicalIdsHistory.Add(updatedPhIdHistory); // //} // //for (int i = 0; i < DeletedPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // EmployeeExtraPropertyHistory deletedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Deleted"); // // physicalIdsHistory.Add(deletedPhIdHistory); // //} // entityChangeInfo.SetProperty("extraPropertiesHistory", allExtraPropertyHistories); //} #endregion AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } curPositionTemplate.Name = positionTemplate_Dto.Name; curPositionTemplate.NameLocalized = positionTemplate_Dto.NameLocalized; curPositionTemplate.Code = positionTemplate_Dto.Code; //curPositionTemplate.Level = positionTemplate_Dto.Level; //curPositionTemplate.DepartmentTemplate = null; //curPositionTemplate.DepartmentTemplateId = positionTemplate_Dto.DepartmentTemplateId; curPositionTemplate.ReviewPeriod = positionTemplate_Dto.ReviewPeriod; curPositionTemplate.HiringType = positionTemplate_Dto.HiringType; curPositionTemplate.ValidityFromDate = positionTemplate_Dto.ValidityFromDate; curPositionTemplate.ValidityToDate = positionTemplate_Dto.ValidityToDate; curPositionTemplate.ActivationDate = positionTemplate_Dto.ActivationDate; #region Child Entities OS_PositionCostCenterTemplate_Dto[] posCostCenters = positionTemplate_Dto.PositionCostCenterTemplates.ToArray(); int[] curPosCostCentersIds = curPositionTemplate.PositionCostCenterTemplates != null && curPositionTemplate.PositionCostCenterTemplates.Count > 0 ? curPositionTemplate.PositionCostCenterTemplates.Select(x => x.PositionTemplate.Id).ToArray() : new int[0]; List <int> toDeleteCostCenters = new List <int>(); for (int i = 0; i < curPosCostCentersIds.Length; i++) { OS_PositionCostCenterTemplate curPositionCostCenter = curPositionTemplate.PositionCostCenterTemplates.First(x => x.PositionTemplate.Id == curPosCostCentersIds[i]); if (!posCostCenters.Any(x => x.PositionTemplateId == curPosCostCentersIds[i] && x.CreationTime == curPositionCostCenter.CreationTime)) { curPositionTemplate.PositionCostCenterTemplates.Remove(curPositionTemplate.PositionCostCenterTemplates.First(x => x.PositionTemplate.Id == curPosCostCentersIds[i])); toDeleteCostCenters.Add(curPosCostCentersIds[i]); } } for (int i = 0; i < posCostCenters.Length; i++) { if (!curPositionTemplate.PositionCostCenterTemplates.Any(x => x.CostCenterId == posCostCenters[i].CostCenter.Id && x.CreationTime == posCostCenters[i].CreationTime)) { curPositionTemplate.PositionCostCenterTemplates.Add(new OS_PositionCostCenterTemplate() { CostCenterId = posCostCenters[i].CostCenter.Id, Percentage = posCostCenters[i].Percentage }); } else { var _positionCostCenter = curPositionTemplate.PositionCostCenterTemplates.First(x => x.PositionTemplateId == posCostCenters[i].PositionTemplate.Id); //_positionLoc.PositionValidityStart = posCostCenters[i].PositionValidityStart; //_positionLoc.PositionValidityEnd = posCostCenters[i].PositionValidityEnd; //_positionLoc.Name = posCostCenters[i].Name; //curPosition.PositionCostCenterTemplates.Remove(curPosition.PositionCostCenterTemplates.First(x => x.PositionTemplateId == _positionLoc.PositionTemplateId)); await OS_PositionTemplateAppService.PositionCostCentersTemplateRepo.UpdateAsync(_positionCostCenter); } } OS_PositionJobTemplate_Dto[] posJobs = positionTemplate_Dto.PositionJobTemplates.ToArray(); int[] curPosJobsIds = curPositionTemplate.PositionJobTemplates != null && curPositionTemplate.PositionJobTemplates.Count > 0 ? curPositionTemplate.PositionJobTemplates.Select(x => x.PositionTemplate.Id).ToArray() : new int[0]; List <int> toDeleteJobs = new List <int>(); for (int i = 0; i < curPosJobsIds.Length; i++) { OS_PositionJobTemplate curPositionJob = curPositionTemplate.PositionJobTemplates.First(x => x.PositionTemplate.Id == curPosJobsIds[i]); if (!posJobs.Any(x => x.PositionTemplateId == curPosJobsIds[i] && x.CreationTime == curPositionJob.CreationTime)) { curPositionTemplate.PositionJobTemplates.Remove(curPositionTemplate.PositionJobTemplates.First(x => x.PositionTemplate.Id == curPosJobsIds[i])); toDeleteJobs.Add(curPosJobsIds[i]); } } for (int i = 0; i < posJobs.Length; i++) { if (!curPositionTemplate.PositionJobTemplates.Any(x => x.JobTemplateId == posJobs[i].JobTemplate.Id && x.CreationTime == posJobs[i].CreationTime)) { curPositionTemplate.PositionJobTemplates.Add(new OS_PositionJobTemplate() { JobTemplateId = posJobs[i].JobTemplate.Id }); } else { var _positionJob = curPositionTemplate.PositionJobTemplates.First(x => x.PositionTemplateId == posJobs[i].PositionTemplate.Id); //_positionLoc.PositionValidityStart = posJobs[i].PositionValidityStart; //_positionLoc.PositionValidityEnd = posJobs[i].PositionValidityEnd; //_positionLoc.Name = posJobs[i].Name; //curPosition.PositionJobTemplates.Remove(curPosition.PositionJobTemplates.First(x => x.PositionTemplateId == _positionLoc.PositionTemplateId)); await OS_PositionTemplateAppService.PositionJobsTemplateRepo.UpdateAsync(_positionJob); } } //OS_PositionTaskTemplate_Dto[] posTasks = positionTemplate_Dto.PositionTaskTemplates.ToArray(); //int[] curPosTaskIds = curPositionTemplate.PositionTaskTemplates != null && curPositionTemplate.PositionTaskTemplates.Count > 0 ? curPositionTemplate.PositionTaskTemplates.Select(x => x.PositionTemplate.Id).ToArray() : new int[0]; //List<int> toDeleteTasks = new List<int>(); //for (int i = 0; i < curPosTaskIds.Length; i++) //{ // OS_PositionTaskTemplate curPositionTask = curPositionTemplate.PositionTaskTemplates.First(x => x.PositionTemplate.Id == curPosTaskIds[i]); // if (!posTasks.Any(x => x.PositionTemplateId == curPosTaskIds[i] && x.CreationTime == curPositionTask.CreationTime)) // { // curPositionTemplate.PositionTaskTemplates.Remove(curPositionTemplate.PositionTaskTemplates.First(x => x.PositionTemplate.Id == curPosTaskIds[i])); // toDeleteTasks.Add(curPosTaskIds[i]); // } //} //for (int i = 0; i < posTasks.Length; i++) //{ // if (!curPositionTemplate.PositionTaskTemplates.Any(x => x.PositionTemplateId == posTasks[i].PositionTemplateId)) // { // curPositionTemplate.PositionTaskTemplates.Add(new OS_PositionTaskTemplate() { TaskTemplateId = posTasks[i].TaskTemplate.Id }); // } // else // { // var _positionTask = curPositionTemplate.PositionTaskTemplates.First(x => x.PositionTemplateId == posTasks[i].PositionTemplate.Id); // //_positionLoc.PositionValidityStart = posTasks[i].PositionValidityStart; // //_positionLoc.PositionValidityEnd = posTasks[i].PositionValidityEnd; // //_positionLoc.Name = posTasks[i].Name; // //curPosition.PositionTaskTemplates.Remove(curPosition.PositionTaskTemplates.First(x => x.PositionTemplateId == _positionLoc.PositionTemplateId)); // await OS_PositionTemplateAppService.PositionTasksTemplateRepo.UpdateAsync(_positionTask); // } //} //for (int i = 0; i < toDeleteTasks.Count; i++) //{ // await OS_PositionTemplateAppService.PositionTasksTemplateRepo.DeleteAsync(x => x.PositionTemplateId == toDeleteTasks[i]); //} for (int i = 0; i < toDeleteJobs.Count; i++) { await OS_PositionTemplateAppService.PositionJobsTemplateRepo.DeleteAsync(x => x.PositionTemplateId == toDeleteJobs[i]); } for (int i = 0; i < toDeleteCostCenters.Count; i++) { await OS_PositionTemplateAppService.PositionCostCentersTemplateRepo.DeleteAsync(x => x.PositionTemplateId == toDeleteCostCenters[i]); } #endregion OS_PositionTemplate_Dto updated = ObjectMapper.Map <OS_PositionTemplate, OS_PositionTemplate_Dto>(await OS_PositionTemplateAppService.Repository.UpdateAsync(curPositionTemplate)); updated = ObjectMapper.Map <OS_PositionTemplate, OS_PositionTemplate_Dto>(await OS_PositionTemplateAppService.Repository.GetAsync(updated.Id)); return(StatusCode(200, updated)); } else { positionTemplate_Dto.Id = 0; if (positionTemplate_Dto.PositionJobTemplates != null) { positionTemplate_Dto.PositionJobTemplates.ForEach(x => { x.Id = 0; x.JobTemplateId = x.JobTemplate.Id; x.JobTemplate = null; }); } //if(positionTemplate_Dto.PositionTaskTemplates != null) // positionTemplate_Dto.PositionTaskTemplates.ForEach(x => { x.Id = 0; x.TaskTemplateId = x.TaskTemplate.Id; x.TaskTemplate = null; }); if (positionTemplate_Dto.PositionCostCenterTemplates != null) { positionTemplate_Dto.PositionCostCenterTemplates.ForEach(x => { x.Id = 0; x.CostCenterId = x.CostCenter.Id; x.CostCenter = null; }); } OS_PositionTemplate_Dto added = await OS_PositionTemplateAppService.CreateAsync(positionTemplate_Dto); //added.DepartmentTemplate = await OS_DepartmentTemplateAppService.GetDepartmentTemplateAsync(added.DepartmentTemplateId); if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = added.Id.ToString(); entityChangeInfo.EntityTenantId = added.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Created; entityChangeInfo.EntityTypeFullName = typeof(OS_PositionTemplate).FullName; AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } return(StatusCode(200, added)); } } catch (Exception ex) { return(StatusCode(500, ex)); } } return(StatusCode(500)); }
public async Task <IActionResult> OnPostPayGrade() { if (ModelState.IsValid) { try { var FormData = Request.Form; PS_PayGrade_Dto payGrade_Dto = JsonSerializer.Deserialize <PS_PayGrade_Dto>(FormData["info"]); bool IsEditing = payGrade_Dto.Id > 0; if (IsEditing) { PS_PayGrade curPayGrade = await PS_PayGradeAppService.Repository.GetAsync(payGrade_Dto.Id); if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = payGrade_Dto.Id.ToString(); entityChangeInfo.EntityTenantId = payGrade_Dto.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Updated; entityChangeInfo.EntityTypeFullName = typeof(PS_PayGrade).FullName; entityChangeInfo.PropertyChanges = new List <EntityPropertyChangeInfo>(); List <EntityPropertyChangeInfo> entityPropertyChanges = new List <EntityPropertyChangeInfo>(); var auditProps = typeof(PS_PayGrade).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); PS_PayGrade mappedInput = ObjectMapper.Map <PS_PayGrade_Dto, PS_PayGrade>(payGrade_Dto); foreach (var prop in auditProps) { EntityPropertyChangeInfo propertyChange = new EntityPropertyChangeInfo(); object origVal = prop.GetValue(curPayGrade); propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); object newVal = prop.GetValue(mappedInput); propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); if (propertyChange.OriginalValue == propertyChange.NewValue) { continue; } propertyChange.PropertyName = prop.Name; if (prop.Name.EndsWith("Id")) { try { string valuePropName = prop.Name.TrimEnd('d', 'I'); propertyChange.PropertyName = valuePropName; var valueProp = typeof(PS_PayGrade).GetProperty(valuePropName); DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(payGrade_Dto); if (_origValObj == null) { _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); } string _origVal = _origValObj.Value; propertyChange.OriginalValue = origVal == null ? "" : _origVal; DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(mappedInput); if (_newValObj == null) { _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); } string _newVal = _newValObj.Value; propertyChange.NewValue = _newValObj == null ? "" : _newVal; } catch (Exception ex) { } } propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; entityChangeInfo.PropertyChanges.Add(propertyChange); } #region ExtraProperties //List<EmployeeExtraPropertyHistory> allExtraPropertyHistories = new List<EmployeeExtraPropertyHistory>(); //if (department_Dto.ExtraProperties != curPayGrade.ExtraProperties) //{ // //GeneralInfo oldGeneralInfo = department.GetProperty<GeneralInfo>("generalInfo"); // //List<EmployeeExtraPropertyHistory> physicalIdsHistory = new List<EmployeeExtraPropertyHistory>(); // //var generalInfoPhysicalIdAuditProps = typeof(PhysicalID).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); // //List<PhysicalId<Guid>> NewPhysicalIds = generalInfo.PhysicalIds.Where(x => !oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //List<PhysicalId<Guid>> UpdatedPhysicalIds = generalInfo.PhysicalIds.Where(x => oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //List<PhysicalId<Guid>> DeletedPhysicalIds = oldGeneralInfo.PhysicalIds.Where(x => !generalInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //for (int i = 0; i < NewPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // EmployeeExtraPropertyHistory newPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Created"); // // physicalIdsHistory.Add(newPhIdHistory); // //} // //for (int i = 0; i < UpdatedPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // PhysicalId<Guid> oldPhId = oldGeneralInfo.PhysicalIds.First(x => x.Id == curPhId.Id); // // EmployeeExtraPropertyHistory updatedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Updated"); // // foreach (var prop in generalInfoPhysicalIdAuditProps) // // { // // updatedPhIdHistory.PropertyChanges = new List<EmployeeTypePropertyChange>(); // // EmployeeTypePropertyChange propertyChange = new EmployeeTypePropertyChange(); // // object origVal = prop.GetValue(oldPhId); // // propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); // // object newVal = prop.GetValue(curPhId); // // propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); // // if (propertyChange.OriginalValue == propertyChange.NewValue) continue; // // propertyChange.PropertyName = prop.Name; // // if (prop.Name.EndsWith("Id")) // // { // // try // // { // // string valuePropName = prop.Name.TrimEnd('d', 'I'); // // propertyChange.PropertyName = valuePropName; // // var valueProp = typeof(PhysicalID).GetProperty(valuePropName); // // DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(oldPhId); // // if (_origValObj == null) _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); // // string _origVal = _origValObj.Value; // // propertyChange.OriginalValue = origVal == null ? "" : _origVal; // // DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(curPhId); // // if (_newValObj == null) _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); // // string _newVal = _newValObj.Value; // // propertyChange.NewValue = _newValObj == null ? "" : _newVal; // // } // // catch (Exception ex) // // { // // } // // } // // propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; // // updatedPhIdHistory.PropertyChanges.Add(propertyChange); // // } // // physicalIdsHistory.Add(updatedPhIdHistory); // //} // //for (int i = 0; i < DeletedPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // EmployeeExtraPropertyHistory deletedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Deleted"); // // physicalIdsHistory.Add(deletedPhIdHistory); // //} // entityChangeInfo.SetProperty("extraPropertiesHistory", allExtraPropertyHistories); //} #endregion AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } curPayGrade.Name = payGrade_Dto.Name; curPayGrade.NameLocalized = payGrade_Dto.NameLocalized; curPayGrade.Code = payGrade_Dto.Code; curPayGrade.Description = payGrade_Dto.Description; curPayGrade.PayGradeStatus = payGrade_Dto.PayGradeStatus; curPayGrade.PayGradeLevel = payGrade_Dto.PayGradeLevel; curPayGrade.PayRangeId = payGrade_Dto.PayRangeId; curPayGrade.PayRange = null; #region Child Entities PS_PayGradeComponent_Dto[] payGradeComponents = payGrade_Dto.PayGradeComponents.ToArray(); int[] curPayGradeComponentsIds = curPayGrade.PayGradeComponents != null && curPayGrade.PayGradeComponents.Count > 0 ? curPayGrade.PayGradeComponents.Select(x => x.PayComponent.Id).ToArray() : new int[0]; List <int> toDeleteSkills = new List <int>(); for (int i = 0; i < curPayGradeComponentsIds.Length; i++) { PS_PayGradeComponent curPayGradeComponent = curPayGrade.PayGradeComponents.First(x => x.PayComponent.Id == curPayGradeComponentsIds[i]); if (!payGradeComponents.Any(x => x.PayComponent.Id == curPayGradeComponentsIds[i])) { curPayGrade.PayGradeComponents.Remove(curPayGrade.PayGradeComponents.First(x => x.PayComponent.Id == curPayGradeComponentsIds[i])); toDeleteSkills.Add(curPayGradeComponentsIds[i]); } } for (int i = 0; i < payGradeComponents.Length; i++) { if (curPayGrade.PayGradeComponents == null) { curPayGrade.PayGradeComponents = new List <PS_PayGradeComponent>(); } if (!curPayGrade.PayGradeComponents.Any(x => x.PayComponentId == payGradeComponents[i].PayComponent.Id)) { curPayGrade.PayGradeComponents.Add(new PS_PayGradeComponent() { PayComponentId = payGradeComponents[i].PayComponent.Id, MaxAnnualLimit = payGradeComponents[i].MaxAnnualLimit }); } else { var _payGradeComponent = curPayGrade.PayGradeComponents.First(x => x.PayComponentId == payGradeComponents[i].PayComponent.Id); _payGradeComponent.MaxAnnualLimit = payGradeComponents[i].MaxAnnualLimit; //_functionLoc.FunctionValidityStart = posFunctions[i].FunctionValidityStart; //_functionLoc.FunctionValidityEnd = posFunctions[i].FunctionValidityEnd; //_functionLoc.Name = posFunctions[i].Name; //curFunction.PayGradeComponents.Remove(curFunction.PayGradeComponents.First(x => x.PayGradeId == _functionLoc.PayGradeId)); await PS_PayGradeAppService.PayComponentsRepository.UpdateAsync(_payGradeComponent); } } for (int i = 0; i < toDeleteSkills.Count; i++) { await PS_PayGradeAppService.PayComponentsRepository.DeleteAsync(x => x.PayComponentId == toDeleteSkills[i]); } #endregion PS_PayGrade_Dto updated = ObjectMapper.Map <PS_PayGrade, PS_PayGrade_Dto>(await PS_PayGradeAppService.Repository.UpdateAsync(curPayGrade)); updated = await PS_PayGradeAppService.GetAsync(updated.Id); return(StatusCode(200, updated)); } else { payGrade_Dto.Id = 0; payGrade_Dto.PayRange = null; if (payGrade_Dto.PayGradeComponents != null) { payGrade_Dto.PayGradeComponents.ForEach(x => { x.Id = 0; x.PayComponentId = x.PayComponent.Id; x.PayComponent = null; }); } PS_PayGrade_Dto added = await PS_PayGradeAppService.CreateAsync(payGrade_Dto); added = await PS_PayGradeAppService.GetAsync(added.Id); if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = added.Id.ToString(); entityChangeInfo.EntityTenantId = added.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Created; entityChangeInfo.EntityTypeFullName = typeof(PS_PayGrade).FullName; AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } return(StatusCode(200, added)); } } catch (Exception ex) { } } return(StatusCode(500)); }
public async Task <IActionResult> OnPostLocationTemplate() { try { if (ModelState.IsValid) { LocationTemplate_Dto location = JsonSerializer.Deserialize <LocationTemplate_Dto>(Request.Form["info"]); LocationAddress address = JsonSerializer.Deserialize <LocationAddress>(Request.Form["address"]); location.SetProperty("address", address); bool IsEditing = location.Id != Guid.Empty; if (IsEditing) { LocationTemplate curLocation = await LocationTemplateAppService.Repository.GetAsync(location.Id); curLocation.LocationName = location.LocationName; curLocation.LocationNameLocalized = location.LocationNameLocalized; curLocation.LocationCode = location.LocationCode; curLocation.Status = location.Status; curLocation.LocationCountryId = location.LocationCountryId; curLocation.LocationEmail = location.LocationEmail; curLocation.LocationFax = location.LocationFax; curLocation.LocationMobile = location.LocationMobile; curLocation.LocationPhone = location.LocationPhone; curLocation.LocationCountry = null; curLocation.UpdateExtraProperties(location.ExtraProperties); LocationTemplate_Dto updated = ObjectMapper.Map <LocationTemplate, LocationTemplate_Dto>(await LocationTemplateAppService.Repository.UpdateAsync(curLocation)); updated.LocationCountry = ObjectMapper.Map <DictionaryValue, DictionaryValue_Dto>(await DictionaryValuesRepo.GetAsync(x => x.Id == updated.LocationCountryId)); return(StatusCode(200, updated)); } else { location.Id = Guid.Empty; LocationTemplate_Dto added = await LocationTemplateAppService.CreateAsync(location); added.LocationCountry = ObjectMapper.Map <DictionaryValue, DictionaryValue_Dto>(await DictionaryValuesRepo.GetAsync(x => x.Id == added.LocationCountryId)); return(StatusCode(200, added)); } } } catch (Exception ex) { } return(StatusCode(500)); }
public async Task <IActionResult> OnPostPayComponent() { if (ModelState.IsValid) { try { var FormData = Request.Form; PS_PayComponent_Dto payComponent_Dto = JsonSerializer.Deserialize <PS_PayComponent_Dto>(FormData["info"]); bool IsEditing = payComponent_Dto.Id > 0; if (IsEditing) { PS_PayComponent curPayComponent = await PS_PayComponentAppService.Repository.GetAsync(payComponent_Dto.Id); if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = payComponent_Dto.Id.ToString(); entityChangeInfo.EntityTenantId = payComponent_Dto.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Updated; entityChangeInfo.EntityTypeFullName = typeof(PS_PayComponent).FullName; entityChangeInfo.PropertyChanges = new List <EntityPropertyChangeInfo>(); List <EntityPropertyChangeInfo> entityPropertyChanges = new List <EntityPropertyChangeInfo>(); var auditProps = typeof(PS_PayComponent).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); PS_PayComponent mappedInput = ObjectMapper.Map <PS_PayComponent_Dto, PS_PayComponent>(payComponent_Dto); foreach (var prop in auditProps) { EntityPropertyChangeInfo propertyChange = new EntityPropertyChangeInfo(); object origVal = prop.GetValue(curPayComponent); propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); object newVal = prop.GetValue(mappedInput); propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); if (propertyChange.OriginalValue == propertyChange.NewValue) { continue; } propertyChange.PropertyName = prop.Name; if (prop.Name.EndsWith("Id")) { try { string valuePropName = prop.Name.TrimEnd('d', 'I'); propertyChange.PropertyName = valuePropName; var valueProp = typeof(PS_PayComponent).GetProperty(valuePropName); DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(payComponent_Dto); if (_origValObj == null) { _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); } string _origVal = _origValObj.Value; propertyChange.OriginalValue = origVal == null ? "" : _origVal; DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(mappedInput); if (_newValObj == null) { _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); } string _newVal = _newValObj.Value; propertyChange.NewValue = _newValObj == null ? "" : _newVal; } catch (Exception ex) { } } propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; entityChangeInfo.PropertyChanges.Add(propertyChange); } #region ExtraProperties //List<EmployeeExtraPropertyHistory> allExtraPropertyHistories = new List<EmployeeExtraPropertyHistory>(); //if (department_Dto.ExtraProperties != curPayComponent.ExtraProperties) //{ // //GeneralInfo oldGeneralInfo = department.GetProperty<GeneralInfo>("generalInfo"); // //List<EmployeeExtraPropertyHistory> physicalIdsHistory = new List<EmployeeExtraPropertyHistory>(); // //var generalInfoPhysicalIdAuditProps = typeof(PhysicalID).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList(); // //List<PhysicalId<Guid>> NewPhysicalIds = generalInfo.PhysicalIds.Where(x => !oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //List<PhysicalId<Guid>> UpdatedPhysicalIds = generalInfo.PhysicalIds.Where(x => oldGeneralInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //List<PhysicalId<Guid>> DeletedPhysicalIds = oldGeneralInfo.PhysicalIds.Where(x => !generalInfo.PhysicalIds.Any(y => y.Id == x.Id)).ToList(); // //for (int i = 0; i < NewPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // EmployeeExtraPropertyHistory newPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Created"); // // physicalIdsHistory.Add(newPhIdHistory); // //} // //for (int i = 0; i < UpdatedPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // PhysicalId<Guid> oldPhId = oldGeneralInfo.PhysicalIds.First(x => x.Id == curPhId.Id); // // EmployeeExtraPropertyHistory updatedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Updated"); // // foreach (var prop in generalInfoPhysicalIdAuditProps) // // { // // updatedPhIdHistory.PropertyChanges = new List<EmployeeTypePropertyChange>(); // // EmployeeTypePropertyChange propertyChange = new EmployeeTypePropertyChange(); // // object origVal = prop.GetValue(oldPhId); // // propertyChange.OriginalValue = origVal == null ? "" : origVal.ToString(); // // object newVal = prop.GetValue(curPhId); // // propertyChange.NewValue = newVal == null ? "" : newVal.ToString(); // // if (propertyChange.OriginalValue == propertyChange.NewValue) continue; // // propertyChange.PropertyName = prop.Name; // // if (prop.Name.EndsWith("Id")) // // { // // try // // { // // string valuePropName = prop.Name.TrimEnd('d', 'I'); // // propertyChange.PropertyName = valuePropName; // // var valueProp = typeof(PhysicalID).GetProperty(valuePropName); // // DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(oldPhId); // // if (_origValObj == null) _origValObj = await DictionaryValuesRepo.GetAsync((Guid)origVal); // // string _origVal = _origValObj.Value; // // propertyChange.OriginalValue = origVal == null ? "" : _origVal; // // DictionaryValue _newValObj = (DictionaryValue)valueProp.GetValue(curPhId); // // if (_newValObj == null) _newValObj = await DictionaryValuesRepo.GetAsync((Guid)newVal); // // string _newVal = _newValObj.Value; // // propertyChange.NewValue = _newValObj == null ? "" : _newVal; // // } // // catch (Exception ex) // // { // // } // // } // // propertyChange.PropertyTypeFullName = prop.Name.GetType().FullName; // // updatedPhIdHistory.PropertyChanges.Add(propertyChange); // // } // // physicalIdsHistory.Add(updatedPhIdHistory); // //} // //for (int i = 0; i < DeletedPhysicalIds.Count; i++) // //{ // // PhysicalId<Guid> curPhId = generalInfo.PhysicalIds[i]; // // EmployeeExtraPropertyHistory deletedPhIdHistory = new EmployeeExtraPropertyHistory(2, "Physical Id", curPhId.IDNumber, "Deleted"); // // physicalIdsHistory.Add(deletedPhIdHistory); // //} // entityChangeInfo.SetProperty("extraPropertiesHistory", allExtraPropertyHistories); //} #endregion AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } curPayComponent.Name = payComponent_Dto.Name; curPayComponent.NameLocalized = payComponent_Dto.NameLocalized; curPayComponent.Code = payComponent_Dto.Code; curPayComponent.Description = payComponent_Dto.Description; curPayComponent.PayComponentStatus = payComponent_Dto.PayComponentStatus; curPayComponent.IsEarning = payComponent_Dto.IsEarning; curPayComponent.PayComponentValue = payComponent_Dto.PayComponentValue; curPayComponent.IsRecurring = payComponent_Dto.IsRecurring; curPayComponent.IsIncomeTaxTreatment = payComponent_Dto.IsIncomeTaxTreatment; curPayComponent.IsGOSITreatment = payComponent_Dto.IsGOSITreatment; curPayComponent.IsEOSBTreatment = payComponent_Dto.IsEOSBTreatment; curPayComponent.CanOverride = payComponent_Dto.CanOverride; curPayComponent.SelfServiceDescription = payComponent_Dto.SelfServiceDescription; curPayComponent.SelfServiceVisibility = payComponent_Dto.SelfServiceVisibility; curPayComponent.IsUsedForCompPlanning = payComponent_Dto.IsUsedForCompPlanning; curPayComponent.IsRecurringPaymentAndDeduction = payComponent_Dto.IsRecurringPaymentAndDeduction; curPayComponent.MaxDecimalPlaces = payComponent_Dto.MaxDecimalPlaces; curPayComponent.EffectiveDate = payComponent_Dto.EffectiveDate; curPayComponent.PayComponentTypeId = payComponent_Dto.PayComponentTypeId; curPayComponent.CurrencyId = payComponent_Dto.CurrencyId; curPayComponent.PayFrequencyId = payComponent_Dto.PayFrequencyId; PS_PayComponent_Dto updated = ObjectMapper.Map <PS_PayComponent, PS_PayComponent_Dto>(await PS_PayComponentAppService.Repository.UpdateAsync(curPayComponent)); return(StatusCode(200, updated)); } else { payComponent_Dto.Id = 0; payComponent_Dto.PayComponentType = null; payComponent_Dto.Currency = null; payComponent_Dto.PayFrequency = null; PS_PayComponent_Dto added = await PS_PayComponentAppService.CreateAsync(payComponent_Dto); added = await PS_PayComponentAppService.GetAsync(added.Id); if (AuditingManager.Current != null) { EntityChangeInfo entityChangeInfo = new EntityChangeInfo(); entityChangeInfo.EntityId = added.Id.ToString(); entityChangeInfo.EntityTenantId = added.TenantId; entityChangeInfo.ChangeTime = DateTime.Now; entityChangeInfo.ChangeType = EntityChangeType.Created; entityChangeInfo.EntityTypeFullName = typeof(PS_PayComponent).FullName; AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo); } return(StatusCode(200, added)); } } catch (Exception ex) { } } return(StatusCode(500)); }