示例#1
0
        public async Task <List <TaxDto> > GetZoneTaxesByAddressId(int tenantId, long addressId, bool active)
        {
            List <TaxDto> taxDtos;

            if (addressId != (long)-1)
            {
                Address async = await this._addressRepository.GetAsync(addressId);

                IQueryable <Zone> all   = this._zoneRepository.GetAll();
                IQueryable <Zone> zones =
                    from p in all
                    where p.TenantId == tenantId
                    select p;
                bool flag = active;
                IQueryable <Zone> zones1    = zones.WhereIf <Zone>(flag, (Zone p) => p.IsActive == active);
                List <Zone>       listAsync = await System.Data.Entity.QueryableExtensions.Include <Zone, ICollection <ZoneTax> >(zones1, (Zone n) => n.Taxes).OrderBy <Zone>("Name", new object[0]).ToListAsync <Zone>();

                List <ZoneDto>  zoneDtos        = new List <ZoneDto>();
                CustomDbContext customDbContext = new CustomDbContext();
                foreach (Zone zone in listAsync)
                {
                    ZoneDto      zoneDto       = zone.MapTo <ZoneDto>();
                    object[]     sqlParameter  = new object[] { new SqlParameter("@ZoneId", (object)zoneDto.Id), new SqlParameter("@AddressId", (object)async.Id), null };
                    SqlParameter sqlParameter1 = new SqlParameter()
                    {
                        ParameterName = "@retVal",
                        SqlDbType     = SqlDbType.Int,
                        Direction     = ParameterDirection.Output,
                        Value         = 0
                    };
                    sqlParameter[2] = sqlParameter1;
                    if (customDbContext.Database.SqlQuery <int>("exec @retVal = Geo_AddressIdInZone @ZoneId, @AddressId", sqlParameter).Single <int>() != 1)
                    {
                        continue;
                    }
                    zoneDtos.Add(zoneDto);
                }
                customDbContext.Dispose();
                List <ZoneDto> zoneDtos1 = new List <ZoneDto>(zoneDtos.MapTo <List <ZoneDto> >());
                List <TaxDto>  taxDtos1  = new List <TaxDto>();
                List <long>    nums      = new List <long>();
                foreach (ZoneDto zoneDto1 in zoneDtos1)
                {
                    foreach (ZoneTaxDto taxis in zoneDto1.Taxes)
                    {
                        TaxDto taxDto = taxis.Tax.MapTo <TaxDto>();
                        if (nums.Contains(taxDto.Id))
                        {
                            continue;
                        }
                        nums.Add(taxDto.Id);
                        taxDtos1.Add(taxDto);
                    }
                }
                taxDtos = new List <TaxDto>(taxDtos1.Distinct <TaxDto>().MapTo <List <TaxDto> >());
            }
            else
            {
                IRepository <TenantDetail, long> repository = this._tenantDetailRepository;
                TenantDetail tenantDetail = await repository.FirstOrDefaultAsync((TenantDetail x) => x.TenantId == tenantId);

                TenantDetail      tenantDetail1 = tenantDetail;
                IQueryable <Zone> all1          = this._zoneRepository.GetAll();
                IQueryable <Zone> zones2        =
                    from p in all1
                    where p.TenantId == tenantId
                    select p;
                bool flag1 = active;
                IQueryable <Zone> zones3     = zones2.WhereIf <Zone>(flag1, (Zone p) => p.IsActive == active);
                List <Zone>       listAsync1 = await System.Data.Entity.QueryableExtensions.Include <Zone, ICollection <ZoneTax> >(zones3, (Zone n) => n.Taxes).OrderBy <Zone>("Name", new object[0]).ToListAsync <Zone>();

                List <ZoneDto>  zoneDtos2        = new List <ZoneDto>();
                CustomDbContext customDbContext1 = new CustomDbContext();
                foreach (Zone zone1 in listAsync1)
                {
                    ZoneDto      zoneDto2      = zone1.MapTo <ZoneDto>();
                    object[]     objArray      = new object[] { new SqlParameter("@ZoneId", (object)zoneDto2.Id), new SqlParameter("@CompanyAddressId", (object)tenantDetail1.Id), null };
                    SqlParameter sqlParameter2 = new SqlParameter()
                    {
                        ParameterName = "@retVal",
                        SqlDbType     = SqlDbType.Int,
                        Direction     = ParameterDirection.Output,
                        Value         = 0
                    };
                    objArray[2] = sqlParameter2;
                    if (customDbContext1.Database.SqlQuery <int>("exec @retVal = Geo_CompanyAddressIdInZone @ZoneId, @CompanyAddressId", objArray).Single <int>() != 1)
                    {
                        continue;
                    }
                    zoneDtos2.Add(zoneDto2);
                }
                customDbContext1.Dispose();
                List <ZoneDto> zoneDtos3 = new List <ZoneDto>(zoneDtos2.MapTo <List <ZoneDto> >());
                List <TaxDto>  taxDtos2  = new List <TaxDto>();
                List <long>    nums1     = new List <long>();
                foreach (ZoneDto zoneDto3 in zoneDtos3)
                {
                    foreach (ZoneTaxDto zoneTaxDto in zoneDto3.Taxes)
                    {
                        TaxDto taxDto1 = zoneTaxDto.Tax.MapTo <TaxDto>();
                        if (nums1.Contains(taxDto1.Id))
                        {
                            continue;
                        }
                        nums1.Add(taxDto1.Id);
                        taxDtos2.Add(taxDto1);
                    }
                }
                taxDtos = new List <TaxDto>(taxDtos2.Distinct <TaxDto>().MapTo <List <TaxDto> >());
            }
            return(taxDtos);
        }
示例#2
0
        public async Task <decimal> GetZoneEmergencyDeliveryFeesByAddressId(int tenantId, long addressId, bool active)
        {
            decimal num;

            if (addressId != (long)-1)
            {
                Address async = await this._addressRepository.GetAsync(addressId);

                IQueryable <Zone> all   = this._zoneRepository.GetAll();
                IQueryable <Zone> zones =
                    from p in all
                    where p.TenantId == tenantId
                    select p;
                bool        flag      = active;
                List <Zone> listAsync = await zones.WhereIf <Zone>(flag, (Zone p) => p.IsActive == active).OrderBy <Zone>("Name", new object[0]).ToListAsync <Zone>();

                List <ZoneDto>  zoneDtos        = new List <ZoneDto>();
                CustomDbContext customDbContext = new CustomDbContext();
                foreach (Zone zone in listAsync)
                {
                    ZoneDto      zoneDto       = zone.MapTo <ZoneDto>();
                    object[]     sqlParameter  = new object[] { new SqlParameter("@ZoneId", (object)zoneDto.Id), new SqlParameter("@AddressId", (object)async.Id), null };
                    SqlParameter sqlParameter1 = new SqlParameter()
                    {
                        ParameterName = "@retVal",
                        SqlDbType     = SqlDbType.Int,
                        Direction     = ParameterDirection.Output,
                        Value         = 0
                    };
                    sqlParameter[2] = sqlParameter1;
                    if (customDbContext.Database.SqlQuery <int>("exec @retVal = Geo_AddressIdInZone @ZoneId, @AddressId", sqlParameter).Single <int>() != 1)
                    {
                        continue;
                    }
                    zoneDtos.Add(zoneDto);
                }
                customDbContext.Dispose();
                List <ZoneDto> zoneDtos1 = new List <ZoneDto>(zoneDtos.MapTo <List <ZoneDto> >());
                List <decimal> nums      = new List <decimal>();
                foreach (ZoneDto zoneDto1 in zoneDtos1)
                {
                    IRepository <EmergencyDeliveryFee, long> repository = this._emergencyDeliveryFeeRepository;
                    List <EmergencyDeliveryFee> allListAsync            = await repository.GetAllListAsync((EmergencyDeliveryFee m) => m.ZoneId == (long?)zoneDto1.Id);

                    foreach (EmergencyDeliveryFee emergencyDeliveryFee in allListAsync)
                    {
                        if (emergencyDeliveryFee.Fee <= decimal.Zero)
                        {
                            continue;
                        }
                        nums.Add(emergencyDeliveryFee.Fee);
                    }
                }
                if (!nums.Any <decimal>())
                {
                    num = new decimal(0);
                }
                else
                {
                    List <decimal> nums1 = nums;
                    num = nums1.Sum <decimal>((decimal d) => d);
                }
            }
            else
            {
                IRepository <TenantDetail, long> repository1 = this._tenantDetailRepository;
                TenantDetail tenantDetail = await repository1.FirstOrDefaultAsync((TenantDetail x) => x.TenantId == tenantId);

                TenantDetail      tenantDetail1 = tenantDetail;
                IQueryable <Zone> all1          = this._zoneRepository.GetAll();
                IQueryable <Zone> zones1        =
                    from p in all1
                    where p.TenantId == tenantId
                    select p;
                bool        flag1      = active;
                List <Zone> listAsync1 = await zones1.WhereIf <Zone>(flag1, (Zone p) => p.IsActive == active).OrderBy <Zone>("Name", new object[0]).ToListAsync <Zone>();

                List <ZoneDto>  zoneDtos2        = new List <ZoneDto>();
                CustomDbContext customDbContext1 = new CustomDbContext();
                foreach (Zone zone1 in listAsync1)
                {
                    ZoneDto      zoneDto2      = zone1.MapTo <ZoneDto>();
                    object[]     objArray      = new object[] { new SqlParameter("@ZoneId", (object)zoneDto2.Id), new SqlParameter("@CompanyAddressId", (object)tenantDetail1.Id), null };
                    SqlParameter sqlParameter2 = new SqlParameter()
                    {
                        ParameterName = "@retVal",
                        SqlDbType     = SqlDbType.Int,
                        Direction     = ParameterDirection.Output,
                        Value         = 0
                    };
                    objArray[2] = sqlParameter2;
                    if (customDbContext1.Database.SqlQuery <int>("exec @retVal = Geo_CompanyAddressIdInZone @ZoneId, @CompanyAddressId", objArray).Single <int>() != 1)
                    {
                        continue;
                    }
                    zoneDtos2.Add(zoneDto2);
                }
                customDbContext1.Dispose();
                List <ZoneDto> zoneDtos3 = new List <ZoneDto>(zoneDtos2.MapTo <List <ZoneDto> >());
                List <decimal> nums2     = new List <decimal>();
                foreach (ZoneDto zoneDto3 in zoneDtos3)
                {
                    IRepository <EmergencyDeliveryFee, long> repository2 = this._emergencyDeliveryFeeRepository;
                    List <EmergencyDeliveryFee> emergencyDeliveryFees    = await repository2.GetAllListAsync((EmergencyDeliveryFee m) => m.ZoneId == (long?)zoneDto3.Id);

                    foreach (EmergencyDeliveryFee emergencyDeliveryFee1 in emergencyDeliveryFees)
                    {
                        if (emergencyDeliveryFee1.Fee <= decimal.Zero)
                        {
                            continue;
                        }
                        nums2.Add(emergencyDeliveryFee1.Fee);
                    }
                }
                if (!nums2.Any <decimal>())
                {
                    num = new decimal(0);
                }
                else
                {
                    List <decimal> nums3 = nums2;
                    num = nums3.Sum <decimal>((decimal d) => d);
                }
            }
            return(num);
        }