コード例 #1
0
        public async Task <List <PS_PaySubGroup_Dto> > GetAllBySearchAsync(PS_PaySubGroup_Search_Dto data)
        {
            try
            {
                List <PS_PaySubGroup_Dto> result = await Task.Run(() => Repository
                                                                  .Include(x => x.PayGroup)
                                                                  .Include(x => x.LegalEntity)
                                                                  .Include(x => x.Frequency)
                                                                  .Include(x => x.PayrollPeriod)
                                                                  .ThenInclude(x => x.PayPeriods)
                                                                  .Include(x => x.AllowedBanks)
                                                                  .Select(MapToGetListOutputDto).ToList());

                for (int i = 0; i < result.Count; i++)
                {
                    if (!CustomHelpers.CheckIfMatches(result[i], data))
                    {
                        result.Remove(result[i]);
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #2
0
        public async Task <IActionResult> OnPostPaySubGroup()
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var FormData = Request.Form;

                    bool isSearching = JsonSerializer.Deserialize <bool>(FormData["isSearching"]);
                    if (isSearching)
                    {
                        PS_PaySubGroup_Search_Dto payGroupSearch_Dto = JsonSerializer.Deserialize <PS_PaySubGroup_Search_Dto>(FormData["info"]);

                        List <PS_PaySubGroup_Dto> result = new List <PS_PaySubGroup_Dto>();
                        result = await PS_PaySubGroupAppService.GetAllBySearchAsync(payGroupSearch_Dto);

                        return(StatusCode(200, result));
                    }
                    else
                    {
                        PS_PaySubGroup_Dto payGroup_Dto = JsonSerializer.Deserialize <PS_PaySubGroup_Dto>(FormData["info"]);

                        bool IsEditing = payGroup_Dto.Id > 0;
                        if (IsEditing)
                        {
                            PS_PaySubGroup curPaySubGroup = await PS_PaySubGroupAppService.GetPaySubGroupRawAsync(payGroup_Dto.Id);

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

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

                                PS_PaySubGroup mappedInput = ObjectMapper.Map <PS_PaySubGroup_Dto, PS_PaySubGroup>(payGroup_Dto);
                                foreach (var prop in auditProps)
                                {
                                    EntityPropertyChangeInfo propertyChange = new EntityPropertyChangeInfo();
                                    object origVal = prop.GetValue(curPaySubGroup);
                                    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_PaySubGroup).GetProperty(valuePropName);

                                    //        DictionaryValue _origValObj = (DictionaryValue)valueProp.GetValue(payGroup_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 != curPaySubGroup.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
                            }

                            //curPaySubGroup.Code = payGroup_Dto.Code;
                            curPaySubGroup.Name          = payGroup_Dto.Name;
                            curPaySubGroup.NameLocalized = payGroup_Dto.NameLocalized;
                            curPaySubGroup.Description   = payGroup_Dto.Description;

                            curPaySubGroup.PayGroupId    = payGroup_Dto.PayGroupId;
                            curPaySubGroup.Frequency     = null;
                            curPaySubGroup.FrequencyId   = payGroup_Dto.FrequencyId;
                            curPaySubGroup.LegalEntity   = null;
                            curPaySubGroup.LegalEntityId = payGroup_Dto.LegalEntityId;
                            curPaySubGroup.OrganizationStructureTemplateId = payGroup_Dto.OrganizationStructureTemplateId;
                            curPaySubGroup.IsBankPaymentAllowed            = payGroup_Dto.IsBankPaymentAllowed;
                            curPaySubGroup.IsCashPaymentAllowed            = payGroup_Dto.IsCashPaymentAllowed;
                            curPaySubGroup.IsChequePaymentAllowed          = payGroup_Dto.IsChequePaymentAllowed;
                            curPaySubGroup.AllowThirdPartyPayments         = payGroup_Dto.AllowThirdPartyPayments;

                            curPaySubGroup.PayrollPeriodId = payGroup_Dto.PayrollPeriodId;

                            #region Child Entities
                            #region Allowed Banks
                            if (payGroup_Dto.AllowedBanks != null)
                            {
                                //Getting New
                                PS_PaySubGroupBank_Dto[] PaySubGroupBanks = payGroup_Dto.AllowedBanks.ToArray();
                                //Getting Current
                                PS_PaySubGroupBank[]      curPaySubGroupBanksIds   = curPaySubGroup.AllowedBanks != null && curPaySubGroup.AllowedBanks.Count > 0 ? curPaySubGroup.AllowedBanks.ToArray() : new PS_PaySubGroupBank[0];
                                List <PS_PaySubGroupBank> toDeletePaySubGroupBanks = new List <PS_PaySubGroupBank>();
                                //Removing Removed
                                for (int i = 0; i < curPaySubGroupBanksIds.Length; i++)
                                {
                                    if (!PaySubGroupBanks.Any(x => x.BankId == curPaySubGroupBanksIds[i].BankId && x.IsThirdParty == curPaySubGroupBanksIds[i].IsThirdParty))
                                    {
                                        curPaySubGroup.AllowedBanks.Remove(curPaySubGroup.AllowedBanks.First(x => x.BankId == curPaySubGroupBanksIds[i].BankId));
                                        toDeletePaySubGroupBanks.Add(curPaySubGroupBanksIds[i]);
                                    }
                                }
                                //Adding & Updating New
                                for (int i = 0; i < PaySubGroupBanks.Length; i++)
                                {
                                    if (curPaySubGroup.AllowedBanks == null)
                                    {
                                        curPaySubGroup.AllowedBanks = new List <PS_PaySubGroupBank>();
                                    }
                                    if (!curPaySubGroup.AllowedBanks.Any(x => x.BankId == PaySubGroupBanks[i].BankId))
                                    {
                                        //PaySubGroupBanks[i].Id = 0;
                                        PS_PaySubGroupBank item = new PS_PaySubGroupBank()
                                        {
                                            BankId = PaySubGroupBanks[i].BankId, IsThirdParty = PaySubGroupBanks[i].IsThirdParty, PaySubGroupId = curPaySubGroup.Id
                                        };
                                        //curPaySubGroup.AllowedBanks.Add(item);

                                        await PS_PaySubGroupAppService.PaySubGroupBanksRepo.InsertAsync(item);
                                    }
                                    else
                                    {
                                    }
                                }
                                //Appending Deleted
                                for (int i = 0; i < toDeletePaySubGroupBanks.Count; i++)
                                {
                                    await PS_PaySubGroupAppService.PaySubGroupBanksRepo.DeleteAsync(x => x.BankId == toDeletePaySubGroupBanks[i].BankId && x.IsThirdParty == toDeletePaySubGroupBanks[i].IsThirdParty);
                                }
                            }
                            #endregion
                            #endregion

                            var preUpdate = await PS_PaySubGroupAppService.Repository.UpdateAsync(curPaySubGroup);

                            var updated = await PS_PaySubGroupAppService.GetPaySubGroupAsync(curPaySubGroup.Id);

                            if (AuditingManager.Current != null)
                            {
                                AuditingManager.Current.Log.EntityChanges.Add(entityChangeInfo);
                            }

                            return(StatusCode(200, updated));
                        }
                        else
                        {
                            payGroup_Dto.Id = 0;
                            payGroup_Dto.OrganizationStructureTemplateId = null;
                            payGroup_Dto.PayrollPeriod = null;

                            PS_PaySubGroup_Dto added = await PS_PaySubGroupAppService.CreateAsync(payGroup_Dto);

                            added = await PS_PaySubGroupAppService.GetPaySubGroupAsync(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_PaySubGroup).FullName;

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

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

            return(StatusCode(500));
        }