Ejemplo n.º 1
0
        public async Task <IActionResult> OnDeleteCompensationMatrixTemplate()
        {
            List <OS_CompensationMatrixTemplate_Dto> entitites = JsonSerializer.Deserialize <List <OS_CompensationMatrixTemplate_Dto> >(Request.Form["compensationMatrices"]);

            try
            {
                for (int i = 0; i < entitites.Count; i++)
                {
                    OS_CompensationMatrixTemplate_Dto entity = entitites[i];
                    //await CompensationMatrixTemplatesAppService.Repository.DeleteAsync(leaveRequest.);
                    await OS_CompensationMatrixTemplateAppService.Repository.DeleteAsync(entity.Id);

                    if (AuditingManager.Current != null)
                    {
                        EntityChangeInfo entityChangeInfo = new EntityChangeInfo();
                        entityChangeInfo.EntityId           = entity.Id.ToString();
                        entityChangeInfo.EntityTenantId     = entity.TenantId;
                        entityChangeInfo.ChangeTime         = DateTime.Now;
                        entityChangeInfo.ChangeType         = EntityChangeType.Deleted;
                        entityChangeInfo.EntityTypeFullName = typeof(OS_CompensationMatrixTemplate).FullName;

                        AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo);
                    }
                }
                return(StatusCode(200));
            }
            catch (Exception ex)
            {
                return(StatusCode(500));
            }
        }
Ejemplo n.º 2
0
        public async Task <OS_CompensationMatrixTemplate_Dto> GetCompensationMatrixAsync(int compensationMatrixId)
        {
            OS_CompensationMatrixTemplate_Dto result = ObjectMapper.Map <OS_CompensationMatrixTemplate, OS_CompensationMatrixTemplate_Dto>(await CompensationMatrixRepository.GetAsync(compensationMatrixId, true));

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnPostCompensationMatrixTemplate()
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var FormData = Request.Form;

                    OS_CompensationMatrixTemplate_Dto compensationMatrixTemplate_Dto = JsonSerializer.Deserialize <OS_CompensationMatrixTemplate_Dto>(FormData["info"]);

                    bool IsEditing = compensationMatrixTemplate_Dto.Id > 0;
                    if (IsEditing)
                    {
                        OS_CompensationMatrixTemplate curCompensationMatrixTemplate = await OS_CompensationMatrixTemplateAppService.Repository.GetAsync(compensationMatrixTemplate_Dto.Id);

                        if (AuditingManager.Current != null)
                        {
                            EntityChangeInfo entityChangeInfo = new EntityChangeInfo();

                            entityChangeInfo.EntityId           = compensationMatrixTemplate_Dto.Id.ToString();
                            entityChangeInfo.EntityTenantId     = compensationMatrixTemplate_Dto.TenantId;
                            entityChangeInfo.ChangeTime         = DateTime.Now;
                            entityChangeInfo.ChangeType         = EntityChangeType.Updated;
                            entityChangeInfo.EntityTypeFullName = typeof(OS_CompensationMatrixTemplate).FullName;

                            entityChangeInfo.PropertyChanges = new List <EntityPropertyChangeInfo>();
                            List <EntityPropertyChangeInfo> entityPropertyChanges = new List <EntityPropertyChangeInfo>();
                            var auditProps = typeof(OS_CompensationMatrixTemplate).GetProperties().Where(x => Attribute.IsDefined(x, typeof(CustomAuditedAttribute))).ToList();

                            OS_CompensationMatrixTemplate mappedInput = ObjectMapper.Map <OS_CompensationMatrixTemplate_Dto, OS_CompensationMatrixTemplate>(compensationMatrixTemplate_Dto);
                            foreach (var prop in auditProps)
                            {
                                EntityPropertyChangeInfo propertyChange = new EntityPropertyChangeInfo();
                                object origVal = prop.GetValue(curCompensationMatrixTemplate);
                                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_CompensationMatrixTemplate).GetProperty(valuePropName);

                                        DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(compensationMatrixTemplate_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 != curCompensationMatrixTemplate.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);
                        }

                        curCompensationMatrixTemplate.Name                   = compensationMatrixTemplate_Dto.Name;
                        curCompensationMatrixTemplate.NameLocalized          = compensationMatrixTemplate_Dto.NameLocalized;
                        curCompensationMatrixTemplate.Code                   = compensationMatrixTemplate_Dto.Code;
                        curCompensationMatrixTemplate.ReviewPeriod           = compensationMatrixTemplate_Dto.ReviewPeriod;
                        curCompensationMatrixTemplate.ReviewPeriodDays       = compensationMatrixTemplate_Dto.ReviewPeriodDays;
                        curCompensationMatrixTemplate.ValidityFromDate       = compensationMatrixTemplate_Dto.ValidityFromDate;
                        curCompensationMatrixTemplate.ValidityToDate         = compensationMatrixTemplate_Dto.ValidityToDate;
                        curCompensationMatrixTemplate.Description            = compensationMatrixTemplate_Dto.Description;
                        curCompensationMatrixTemplate.CompensationMatrixData = compensationMatrixTemplate_Dto.CompensationMatrixData;

                        OS_CompensationMatrixTemplate_Dto updated = ObjectMapper.Map <OS_CompensationMatrixTemplate, OS_CompensationMatrixTemplate_Dto>(await OS_CompensationMatrixTemplateAppService.Repository.UpdateAsync(curCompensationMatrixTemplate));
                        updated = await OS_CompensationMatrixTemplateAppService.GetAsync(updated.Id);

                        return(StatusCode(200, updated));
                    }
                    else
                    {
                        compensationMatrixTemplate_Dto.Id = 0;

                        OS_CompensationMatrixTemplate_Dto added = await OS_CompensationMatrixTemplateAppService.CreateAsync(compensationMatrixTemplate_Dto);

                        added = await OS_CompensationMatrixTemplateAppService.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_CompensationMatrixTemplate).FullName;

                            AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo);
                        }

                        return(StatusCode(200, added));
                    }
                }
                catch (Exception ex)
                {
                }
            }

            return(StatusCode(500));
        }
Ejemplo n.º 4
0
        public async Task <JsonResult> OnGetDataAuditTrail()
        {
            dynamic        result         = new ExpandoObject();
            List <dynamic> DS             = new List <dynamic>();
            List <dynamic> secondaryDS    = new List <dynamic>();
            List <dynamic> tertiaryDS     = new List <dynamic>();
            var            departmentLogs = AuditLogsRepo.WithDetails().Where(x => x.Url == HttpContext.Request.Path.Value && x.EntityChanges != null && x.EntityChanges.Count > 0).ToList();

            List <OS_CompensationMatrixTemplate_Dto> Entities = await OS_CompensationMatrixTemplateAppService.GetAllCompensationMatrixTemplatesAsync();

            TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;

            for (int i = 0; i < departmentLogs.Count; i++)
            {
                AuditLog auditLog = departmentLogs[i];
                if (auditLog.EntityChanges == null || auditLog.EntityChanges.Count == 0)
                {
                    continue;
                }
                var entityChanges = auditLog.EntityChanges.ToList();
                for (int j = 0; j < entityChanges.Count; j++)
                {
                    EntityChange entityChange = entityChanges[j];

                    dynamic changeRow = new ExpandoObject();
                    changeRow.AuditLogId     = entityChange.Id;
                    changeRow.EntityChangeId = entityChange.Id;

                    OS_CompensationMatrixTemplate_Dto department = Entities.First(x => x.Id.ToString() == entityChange.EntityId);
                    changeRow.Id     = department.Id;
                    changeRow.Name   = department.Name;
                    changeRow.Date   = entityChange.ChangeTime.ToShortDateString();
                    changeRow.Time   = entityChange.ChangeTime.ToShortTimeString();
                    changeRow.User   = auditLog.UserName;
                    changeRow.Status = entityChange.ChangeType.GetDisplayName();

                    DS.Add(changeRow);

                    dynamic generalTypeRow = new ExpandoObject();
                    generalTypeRow.EntityChangeId = entityChange.Id;
                    generalTypeRow.TypeId         = 1;
                    generalTypeRow.Type           = "General";
                    generalTypeRow.Name           = "";
                    generalTypeRow.Status         = "Updated";

                    changeRow.Type = "General";
                    //changeRow.Name = "";
                    changeRow.ChangeStatus = "Updated";

                    secondaryDS.Add(generalTypeRow);

                    var generalPropertyChanges = entityChange.PropertyChanges.ToList();

                    for (int k = 0; k < generalPropertyChanges.Count; k++)
                    {
                        EntityPropertyChange propertyChange = generalPropertyChanges[k];
                        dynamic propertyChangeRow           = new ExpandoObject();
                        propertyChangeRow.TypeId         = 1;
                        propertyChangeRow.EntityChangeId = propertyChange.EntityChangeId;
                        propertyChangeRow.Field          = textInfo.ToTitleCase(propertyChange.PropertyName.ToSentenceCase());
                        propertyChangeRow.NewValue       = propertyChange.NewValue != "null" && propertyChange.NewValue != "\"\"" ? propertyChange.NewValue.TrimStart('"').TrimEnd('"') : "—";
                        propertyChangeRow.OriginalValue  = propertyChange.OriginalValue != "null" && propertyChange.OriginalValue != "\"\"" ? propertyChange.OriginalValue.TrimStart('"').TrimEnd('"') : "—";;

                        changeRow.Field         = textInfo.ToTitleCase(propertyChange.PropertyName.ToSentenceCase());
                        changeRow.NewValue      = propertyChange.NewValue != "null" && propertyChange.NewValue != "\"\"" ? propertyChange.NewValue.TrimStart('"').TrimEnd('"') : "—";
                        changeRow.OriginalValue = propertyChange.OriginalValue != "null" && propertyChange.OriginalValue != "\"\"" ? propertyChange.OriginalValue.TrimStart('"').TrimEnd('"') : "—";;

                        tertiaryDS.Add(propertyChangeRow);
                    }

                    //List<EmployeeExtraPropertyHistory> extraPropertyHistories = entityChange.GetProperty<List<EmployeeExtraPropertyHistory>>("extraPropertiesHistory");
                    //if (extraPropertyHistories != null && extraPropertyHistories.Count > 0)
                    //{
                    //    foreach (EmployeeExtraPropertyHistory extraPropertyHistory in extraPropertyHistories)
                    //    {
                    //        dynamic typeRow = new ExpandoObject();
                    //        typeRow.EntityChangeId = entityChange.Id;
                    //        typeRow.TypeId = extraPropertyHistory.TypeId;
                    //        typeRow.Type = extraPropertyHistory.Type;
                    //        typeRow.Name = extraPropertyHistory.Name;
                    //        typeRow.Status = extraPropertyHistory.Status;

                    //        secondaryDS.Add(typeRow);

                    //        var propertyChanges = extraPropertyHistory.PropertyChanges.ToList();

                    //        for (int k = 0; k < propertyChanges.Count; k++)
                    //        {
                    //            EmployeeTypePropertyChange propertyChange = propertyChanges[k];
                    //            dynamic propertyChangeRow = new ExpandoObject();
                    //            propertyChangeRow.TypeId = extraPropertyHistory.TypeId;
                    //            propertyChangeRow.EntityChangeId = typeRow.EntityChangeId;
                    //            propertyChangeRow.Field = textInfo.ToTitleCase(propertyChange.PropertyName.ToSentenceCase());
                    //            propertyChangeRow.NewValue = propertyChange.NewValue != "null" && propertyChange.NewValue != "\"\"" ? propertyChange.NewValue.TrimStart('"').TrimEnd('"') : "—";
                    //            propertyChangeRow.OriginalValue = propertyChange.OriginalValue != "null" && propertyChange.OriginalValue != "\"\"" ? propertyChange.OriginalValue.TrimStart('"').TrimEnd('"') : "—"; ;

                    //            tertiaryDS.Add(propertyChangeRow);
                    //        }
                    //    }
                    //}
                }
            }
            result.ds          = DS;
            result.secondaryDS = secondaryDS;
            result.tertiaryDS  = tertiaryDS;

            var secondaryGrid = new JsonResult(result);

            return(secondaryGrid);
        }