mercredi 10 février 2016

System.reflection.targetexception non-static method requires a target

        public IQueryable<DebitorProductCautionsEx> GetEx(
                Expression<Func<DebitorProductCautions, bool>> filter = null,
                SearchDto search = null,
                int? lawyerID = null,
                bool? IsInDetailTab = null
                )
            {
                filter = filter ?? (p => true);
                search = search ?? new SearchDto();
                IsInDetailTab = IsInDetailTab ?? false;

//this line about authorization
                var hyDepList = context.Department.Where(p => p.ID == UserData.iDepartmentId && p.ID != 0)
                                                  .RecursiveSelect(p => context.Department.Where(pd => pd.ParentID == p.ID)
                                                                                                .AsQueryable<Department>())
                                                   .Select(p => p.DepartmentBankCode)
                                                   .Distinct()
                                                   .ToList();
//this line about authorization
                var associatedDepartmenList = (from depID in context.DepartmentUserAssociation
                                                  .Where(p => p.AssociateAccountUserID == UserData.iUserId && p.AssociateAccountUserID != 0)
                                                  .Select(p => p.DepartmentID)
                                               join dep in context.Department on depID equals dep.ID
                                               select dep.DepartmentBankCode).Distinct().ToList();

                var query = from item in dbSet.Where(filter)
                            join debitor in context.Debitor on item.DebitorID equals 1819
                            //kurumsal
                            from debitorProducts in context.DebitorProducts.Where(p => !p.IsDeleted && p.DebitorID == debitor.ID).OrderBy(a => a.TrackingDate).Take(1).DefaultIfEmpty()
                            from product in context.Product.Where(p => !p.IsDeleted && p.ID == debitorProducts.ProductID).DefaultIfEmpty()
                            //bireysel
                            from debitorProducts2 in context.DebitorProducts.Where(p => !p.IsDeleted && p.ID == item.DebitorProductsID).DefaultIfEmpty()

//kurumsal from product2 in context.Product.Where(p => !p.IsDeleted && p.ID == debitorProducts2.ProductID).DefaultIfEmpty() from delegationDebitorProduct in context.MainLawyerDelegationDebitorProduct.Where(p => (p.DebitorProductID.HasValue && ((debitor.MistralCustomerStatusID == 3 || debitor.MistralCustomerStatusID == 8) ? p.DebitorProductID == debitorProducts2.ID : p.DebitorProductID == debitorProducts.ID))).DefaultIfEmpty() from delegation in context.MainLawyerDelegation.Where(p => !p.IsDeleted && p.ID == delegationDebitorProduct.MainLawyerDelegationID).DefaultIfEmpty() from debitorType in context.DebitorType.Where(p => !p.IsDeleted && p.ID == debitor.DebitorTypeID).DefaultIfEmpty() from exchangeType in context.ExchangeType.Where(p => !p.IsDeleted && (item.ExchangeTypeID.HasValue && p.ID == (int)item.ExchangeTypeID)).DefaultIfEmpty()

                            from insertedAccountUser in context.AccountUser.Where(p => p.ID == item.InsertedBy).DefaultIfEmpty()
                            from insertedAccountPerson in context.AccountPerson.Where(p => p.ID == insertedAccountUser.PersonID).DefaultIfEmpty()
                            from updatedAccountUser in context.AccountUser.Where(p => p.ID == item.UpdatedBy).DefaultIfEmpty()
                            from updatedAccountPerson in context.AccountPerson.Where(p => p.ID == updatedAccountUser.PersonID).DefaultIfEmpty()
                            where
                             (!search.DebitorID.HasValue || debitor.ID == search.DebitorID)
                             && (search.DebitorNo == null || debitor.DebitorNo == search.DebitorNo)
                             && (search.TCKNOrTaxOfficeNumber == null || debitor.TCKN == search.TCKNOrTaxOfficeNumber || debitor.TaxOfficeNumber == search.TCKNOrTaxOfficeNumber)
                             && (search.FirstName == null || debitor.Name.Contains(search.FirstName))
                             && (search.Surname == null || debitor.Surname.Contains(search.Surname))
                             && (search.BankCode == null || context.DebitorProducts.Any(p => !p.IsDeleted && p.DebitorID == debitor.ID && p.TrackingUnitCode == search.BankCode))
                             && (search.PhoneNo == null || context.DebitorPhones.Any(p => !p.IsDeleted && p.DebitorID == debitor.ID && p.PhoneNo.Contains(search.PhoneNo)))
                             && (search.ExecutionFileNo1 == null || context.ExecutionTracking.Any(p => !p.IsDeleted && p.DebitorID == debitor.ID && p.ExecutionFileNo.StartsWith(search.ExecutionFileNo1.ToString())))
                             && (search.ExecutionFileNo2 == null || context.ExecutionTracking.Any(p => !p.IsDeleted && p.DebitorID == debitor.ID && p.ExecutionFileNo.EndsWith(search.ExecutionFileNo2.ToString())))
                             && (!search.LawyerID.HasValue || !delegationDebitorProduct.IsDeleted && delegation.Status == (int)LawyerConfirmStatus.Accept && (delegation.MainLawyerID == search.LawyerID || delegation.ObserverLawyerID == search.LawyerID))
                             && (!lawyerID.HasValue || !delegationDebitorProduct.IsDeleted && delegation.Status == (int)LawyerConfirmStatus.Accept && (delegation.MainLawyerID == lawyerID || delegation.ObserverLawyerID == lawyerID))
                             && ((!(context.AccountRole.Where(p => p.KimyonCode == "B" || p.KimyonCode == "SP" || p.KimyonCode == "SM").Select(p => p.ID).Contains(UserData.iRoleId))) || hyDepList.Contains(debitorProducts.TrackingUnitCode.ToString()))
                             && ((!(context.AccountRole.Where(p => p.KimyonCode == "MM" || p.KimyonCode == "MTL" || p.KimyonCode == "MP").Select(p => p.ID).Contains(UserData.iRoleId))) || associatedDepartmenList.Contains(debitorProducts.TrackingUnitCode.ToString()))
                            select new DebitorProductCautionsEx
                            {
                                ID = item.ID,
                                DebitorID = debitor.ID,
                                DebitorProductsID = item.DebitorProductsID,
                                ExchangeTypeID = item.ExchangeTypeID,
                                NotaryName = item.NotaryName,
                                ReferenceNo = item.ReferenceNo,
                                DailyChargeNo = item.DailyChargeNo,
                                CautionDate = item.CautionDate,
                                CautionPeriod = item.CautionPeriod,
                                NotificationDate = item.NotificationDate,
                                BankStatementDate = item.BankStatementDate,
                                BSMVRate = item.BSMVRate,
                                KKDFRate = item.KKDFRate,
                                CautionAmount = item.CautionAmount,
                                CapitalAmount = item.CapitalAmount,
                                InterestAmount = item.InterestAmount,
                                CommissionAmount = item.CommissionAmount,
                                LegalWageCutAmount = item.LegalWageCutAmount,
                                CautionCashAmount = item.CautionCashAmount,
                                CautionNonCashAmount = item.CautionNonCashAmount,
                                TotalDebt = item.TotalDebt,
                                MistralCustomerStatusID = debitor.MistralCustomerStatusID,
                                DebitorNo = debitor.DebitorNo,
                                DebitorName = (debitor.MistralCustomerStatusID == 3 || debitor.MistralCustomerStatusID == 8) ? debitor.Name.Replace(" ", "") + " " + debitor.Surname.Replace(" ", "") : debitor.Name,
                                DebitorSurname = debitor.Surname,
                                TCKN = debitor.TCKN,
                                NCN = debitor.NCN,
                                isKurumsal = (debitor.MistralCustomerStatusID != 3 && debitor.MistralCustomerStatusID != 8),
                                ProductName = (debitor.MistralCustomerStatusID == 3 || debitor.MistralCustomerStatusID == 8) ? product2.ProductName : (item.DebitorProductsID == 0 ? "KURUMSAL KREDİ" : product.ProductName),
                                ExchangeType = exchangeType.Description,
                                BSMV = (debitor.MistralCustomerStatusID == 3 || debitor.MistralCustomerStatusID == 8) ? (item.InterestAmount.HasValue ? Math.Truncate(((item.InterestAmount.Value * 5) / 100) * 100) / 100 : 0) : 0,
                                KKDF = (debitor.MistralCustomerStatusID == 3 || debitor.MistralCustomerStatusID == 8) ? (item.InterestAmount.HasValue ? Math.Truncate(((item.InterestAmount.Value * 15) / 100) * 100) / 100 : 0) : 0,
                                UpdateDate = item.UpdateDate,
                                InsertedBy = item.InsertedBy,
                                UpdatedBy = item.UpdatedBy,
                                InsertDate = item.InsertDate,
                                IsDeleted = item.IsDeleted,
                                InsertedName = insertedAccountPerson.FirstName.Trim() + " " + insertedAccountPerson.LastName.Trim(),
                                UpdatedName = updatedAccountPerson.FirstName.Trim() + " " + updatedAccountPerson.LastName.Trim()
                            };

                if (IsInDetailTab.Value)
                {
                    return query;
                }

                var bireysel = new List<int>(); // Müşteri Tipi Bireysel olan ihtar ID'leri listesi.
                var kurumsal = new Dictionary<string, int>(); // Müşteri Tipi Kurumsal olan İhtarların DebitorId ve Yevmiye No'ya göre gruplanmış listesi.

    //PROBLEM THIS LINE non-static method
                foreach (var item in **query.OrderByDescending(p => p.ID).ToList()**)
                {
                    var deb = context.Debitor.FirstOrDefault(p => p.ID == item.DebitorID);
                    if (deb != null && (deb.MistralCustomerStatusID == 3 || deb.MistralCustomerStatusID == 8))
                    {
                        bireysel.Add(item.ID);
                        continue;
                    }
                    var key = string.Concat(item.DebitorID, "-", item.DailyChargeNo);
                    if (kurumsal.ContainsKey(key))
                        continue;
                    kurumsal.Add(key, item.ID);
                }
                var datKurumsal = query.Where(p => kurumsal.Values.Contains(p.ID));
                var datBireysel = query.Where(p => bireysel.Contains(p.ID));

                return datBireysel.Union(datKurumsal);
            }





Aucun commentaire:

Enregistrer un commentaire