Пример #1
0
        public async Task <string> CheckForSpecificPrice(CheckSpecificPriceInputDto input)
        {
            string   str;
            Customer customer;
            Address  address;
            decimal  num1;
            bool     flag;
            bool     flag1;
            bool     flag2;

            if (input.ProductId <= 0 || input.ForCustomerId <= 0)
            {
                str = "";
            }
            else
            {
                Product async = await this._productRepository.GetAsync((long)input.ProductId);

                Product product = async;
                IRepository <ProductSpecificPrice, long> repository = this._specificPriceRepository;
                List <ProductSpecificPrice> allListAsync            = await repository.GetAllListAsync((ProductSpecificPrice x) => x.ProductId == product.Id);

                List <ProductSpecificPrice> productSpecificPrices = allListAsync;
                bool flag3 = false;
                if (productSpecificPrices.Any <ProductSpecificPrice>())
                {
                    List <string> strs  = new List <string>();
                    string        empty = string.Empty;
                    List <string> upchargeForUsersOrganizationUnits = new List <string>();
                    string        empty1 = string.Empty;
                    if (input.ForCustomerId <= 0)
                    {
                        customer = null;
                    }
                    else
                    {
                        Customer async1 = await this._customerRepository.GetAsync((long)input.ForCustomerId);

                        customer = async1;
                    }
                    Customer customer1 = customer;
                    if (input.ForCustomerAddressId <= 0)
                    {
                        address = null;
                    }
                    else
                    {
                        Address address1 = await this._addressRepository.GetAsync((long)input.ForCustomerAddressId);

                        address = address1;
                    }
                    Address     address2  = address;
                    int         countryId = 0;
                    List <long> nums      = new List <long>();
                    if (address2 != null)
                    {
                        countryId = address2.CountryId;
                    }
                    if (customer1 != null && customer1.UserId.HasValue)
                    {
                        FuelWerx.Authorization.Users.UserManager userManager = this._userManager;
                        User userByIdAsync = await userManager.GetUserByIdAsync(customer1.UserId.Value);

                        List <Abp.Organizations.OrganizationUnit> organizationUnitsAsync = await this._userManager.GetOrganizationUnitsAsync(userByIdAsync);

                        nums = (
                            from ou in organizationUnitsAsync
                            select ou.Id).ToList <long>();
                        strs = await this._organizationUnitAppService.GetDiscountForUsersOrganizationUnits(customer1.Id);

                        if (strs.Any <string>())
                        {
                            empty = strs[0];
                        }
                        upchargeForUsersOrganizationUnits = await this._organizationUnitAppService.GetUpchargeForUsersOrganizationUnits(customer1.Id);

                        if (upchargeForUsersOrganizationUnits.Any <string>())
                        {
                            empty1 = upchargeForUsersOrganizationUnits[0];
                        }
                        if (nums.Any <long>())
                        {
                            customer1 = null;
                            flag3     = true;
                        }
                    }
                    string[] strArrays = new string[0];
                    if (!string.IsNullOrEmpty(input.ProductOptionIds))
                    {
                        string productOptionIds = input.ProductOptionIds;
                        productOptionIds.Split(new char[] { ',' });
                    }
                    IEnumerable <ProductSpecificPrice> productSpecificPrices1 = productSpecificPrices.WhereIf <ProductSpecificPrice>(input.Quantity > 0, (ProductSpecificPrice p) => {
                        int?startingAtQuantity = p.StartingAtQuantity;
                        int quantity           = input.Quantity;
                        if (startingAtQuantity.GetValueOrDefault() > quantity)
                        {
                            return(false);
                        }
                        return(startingAtQuantity.HasValue);
                    }).Where <ProductSpecificPrice>((ProductSpecificPrice p) => {
                        if (p.ForCurrency == input.ForCurrency)
                        {
                            return(true);
                        }
                        return(p.ForCurrency == null);
                    }).WhereIf <ProductSpecificPrice>(customer1 != null, (ProductSpecificPrice p) => {
                        long?forCustomerId = p.ForCustomerId;
                        long id            = customer1.Id;
                        if (forCustomerId.GetValueOrDefault() != id)
                        {
                            return(false);
                        }
                        return(forCustomerId.HasValue);
                    }).Where <ProductSpecificPrice>((ProductSpecificPrice p) => {
                        int?forCountryId = p.ForCountryId;
                        int num          = countryId;
                        if ((forCountryId.GetValueOrDefault() == num ? forCountryId.HasValue : false))
                        {
                            return(true);
                        }
                        forCountryId = p.ForCountryId;
                        return(!forCountryId.HasValue);
                    });
                    bool flag4 = !nums.Any <long>();
                    IEnumerable <ProductSpecificPrice> productSpecificPrices2 = productSpecificPrices1.WhereIf <ProductSpecificPrice>(flag4, (ProductSpecificPrice p) => !p.ForOrganizationalUnitId.HasValue);
                    flag = (!nums.Any <long>() ? false : nums.Count == 1);
                    IEnumerable <ProductSpecificPrice> productSpecificPrices3 = productSpecificPrices2.WhereIf <ProductSpecificPrice>(flag, (ProductSpecificPrice p) => {
                        if (p.ForOrganizationalUnitId.HasValue && p.ForOrganizationalUnitId.Value == nums[0])
                        {
                            return(true);
                        }
                        return(!p.ForOrganizationalUnitId.HasValue);
                    });
                    flag1 = (!nums.Any <long>() ? false : nums.Count > 1);
                    List <ProductSpecificPrice> list = productSpecificPrices3.WhereIf <ProductSpecificPrice>(flag1, (ProductSpecificPrice p) => {
                        if (p.ForOrganizationalUnitId.HasValue && nums.Contains(p.ForOrganizationalUnitId.Value))
                        {
                            return(true);
                        }
                        return(!p.ForOrganizationalUnitId.HasValue);
                    }).ToList <ProductSpecificPrice>();
                    if (!list.Any <ProductSpecificPrice>())
                    {
                        str = "";
                    }
                    else
                    {
                        if (list.Count > 1 & flag3 && nums.Any <long>() && nums.Count == 1)
                        {
                            List <ProductSpecificPrice> productSpecificPrices4 = list;
                            list = list.Where <ProductSpecificPrice>((ProductSpecificPrice x) => {
                                long?forOrganizationalUnitId = x.ForOrganizationalUnitId;
                                long item = nums[0];
                                if (forOrganizationalUnitId.GetValueOrDefault() != item)
                                {
                                    return(false);
                                }
                                return(forOrganizationalUnitId.HasValue);
                            }).ToList <ProductSpecificPrice>();
                            if (!list.Any <ProductSpecificPrice>() && input.ForCustomerId > 0)
                            {
                                list = productSpecificPrices4.Where <ProductSpecificPrice>((ProductSpecificPrice x) => {
                                    long?forCustomerId = x.ForCustomerId;
                                    long num           = (long)input.ForCustomerId;
                                    if (forCustomerId.GetValueOrDefault() != num)
                                    {
                                        return(false);
                                    }
                                    return(forCustomerId.HasValue);
                                }).ToList <ProductSpecificPrice>();
                            }
                        }
                        if (!list.Any <ProductSpecificPrice>())
                        {
                            str = "";
                        }
                        else
                        {
                            DateTime?availableFrom = list.First <ProductSpecificPrice>().AvailableFrom;
                            DateTime?availableTo   = list.First <ProductSpecificPrice>().AvailableTo;
                            bool     flag5         = false;
                            if (!availableFrom.HasValue && !availableTo.HasValue)
                            {
                                flag5 = true;
                            }
                            else if (availableFrom.HasValue && availableTo.HasValue && availableFrom.Value <= DateTime.Now && availableTo.Value >= DateTime.Now)
                            {
                                flag5 = true;
                            }
                            if (!flag5)
                            {
                                str = "";
                            }
                            else
                            {
                                decimal cost = list.First <ProductSpecificPrice>().Cost;
                                if (empty.Length > 0)
                                {
                                    if (empty.Contains("$"))
                                    {
                                        num1 = decimal.Parse(cost.ToString()) - decimal.Parse(empty.Replace("$", ""));
                                        cost = decimal.Parse(num1.ToString());
                                    }
                                    else if (empty.Contains("%"))
                                    {
                                        num1 = decimal.Parse(cost.ToString()) - (decimal.Parse(cost.ToString()) * decimal.Parse(empty.Replace("%", "").ToString()));
                                        cost = decimal.Parse(num1.ToString("#.##"));
                                    }
                                }
                                if (empty1.Length > 0)
                                {
                                    if (empty1.Contains("$"))
                                    {
                                        num1 = decimal.Parse(cost.ToString()) + decimal.Parse(empty1.Replace("$", ""));
                                        cost = decimal.Parse(num1.ToString());
                                    }
                                    else if (empty1.Contains("%"))
                                    {
                                        num1 = decimal.Parse(cost.ToString()) + (decimal.Parse(cost.ToString()) * decimal.Parse(empty1.Replace("%", "").ToString()));
                                        cost = decimal.Parse(num1.ToString("#.##"));
                                    }
                                }
                                decimal?discount = list.First <ProductSpecificPrice>().Discount;
                                if (discount.HasValue)
                                {
                                    decimal?nullable = discount;
                                    num1  = new decimal();
                                    flag2 = (nullable.GetValueOrDefault() > num1 ? nullable.HasValue : false);
                                    if (flag2)
                                    {
                                        if (decimal.Parse(discount.ToString()) >= new decimal(0.999))
                                        {
                                            cost = decimal.Parse(cost.ToString()) - decimal.Parse(discount.ToString());
                                        }
                                        else
                                        {
                                            num1 = decimal.Parse(cost.ToString()) - (decimal.Parse(cost.ToString()) * decimal.Parse(discount.ToString()));
                                            cost = decimal.Parse(num1.ToString("#.##"));
                                        }
                                    }
                                }
                                str = cost.ToString();
                            }
                        }
                    }
                }
                else
                {
                    str = "";
                }
            }
            return(str);
        }
Пример #2
0
        public async Task <List <string> > GetUpchargeForUsersOrganizationUnits(long customerId)
        {
            decimal?      nullable;
            decimal       num;
            bool          flag;
            bool          flag1;
            List <string> strs      = new List <string>();
            decimal?      nullable1 = null;
            decimal?      nullable2 = null;
            Customer      customer  = await this._customerRepository.FirstOrDefaultAsync(customerId);

            if (customer != null && customer.UserId.HasValue)
            {
                FuelWerx.Authorization.Users.UserManager userManager = this._userManager;
                User userByIdAsync = await userManager.GetUserByIdAsync(customer.UserId.Value);

                List <OrganizationUnit> organizationUnitsAsync = await this._userManager.GetOrganizationUnitsAsync(userByIdAsync);

                List <long> list = (
                    from s in organizationUnitsAsync
                    select s.Id).ToList <long>();
                if (list.Any <long>())
                {
                    IRepository <OrganizationUnitProperties, long> repository = this._organizationUnitPropertiesRepository;
                    List <OrganizationUnitProperties> allListAsync            = await repository.GetAllListAsync((OrganizationUnitProperties x) => list.Contains(x.OrganizationUnitId));

                    List <OrganizationUnitProperties> organizationUnitProperties = allListAsync;
                    if (organizationUnitProperties.Any <OrganizationUnitProperties>())
                    {
                        List <OrganizationUnitProperties>        organizationUnitProperties1 = organizationUnitProperties;
                        IEnumerable <OrganizationUnitProperties> organizationUnitProperties2 = organizationUnitProperties1.Where <OrganizationUnitProperties>((OrganizationUnitProperties oup) =>
                        {
                            if (!oup.Upcharge.HasValue)
                            {
                                return(false);
                            }
                            if (oup.Upcharge.Value <= decimal.Zero)
                            {
                                return(false);
                            }
                            return(oup.Upcharge.Value <= new decimal(0.999));
                        });
                        nullable1 = (
                            from oup in organizationUnitProperties2
                            select oup.Upcharge).Sum();
                        List <OrganizationUnitProperties>        organizationUnitProperties3 = organizationUnitProperties;
                        IEnumerable <OrganizationUnitProperties> organizationUnitProperties4 = organizationUnitProperties3.Where <OrganizationUnitProperties>((OrganizationUnitProperties oup) =>
                        {
                            if (!oup.Upcharge.HasValue)
                            {
                                return(false);
                            }
                            if (oup.Upcharge.Value <= decimal.Zero)
                            {
                                return(false);
                            }
                            return(oup.Upcharge.Value > new decimal(0.999));
                        });
                        nullable2 = (
                            from oup in organizationUnitProperties4
                            select oup.Upcharge).Sum();
                    }
                }
            }
            if (nullable1.HasValue)
            {
                nullable = nullable1;
                num      = new decimal();
                flag1    = (nullable.GetValueOrDefault() > num ? nullable.HasValue : false);
                if (flag1)
                {
                    strs.Add(string.Concat(nullable1.ToString(), "%"));
                }
            }
            if (nullable2.HasValue)
            {
                nullable = nullable2;
                num      = new decimal();
                flag     = (nullable.GetValueOrDefault() > num ? nullable.HasValue : false);
                if (flag)
                {
                    strs.Add(string.Concat("$", nullable2.ToString()));
                }
            }
            return(strs);
        }