Exemple #1
0
        public double GetPrice(int weightId, int sizeId)
        {
            var        weight     = context.ParcelWeight.SingleOrDefault(x => x.Id == weightId);
            var        size       = context.ParcelSize.SingleOrDefault(x => x.Id == sizeId);
            var        sizeList   = parcelService.FindAllParcelSizes();
            var        priceList  = parcelService.FindAllParcelPrices();
            ParcelSize returnSize = null;

            foreach (var parc in sizeList)
            {
                if (size.Breadth <= parc.Breadth && size.Height <= parc.Height && size.Depth <= parc.Depth)
                {
                    returnSize = parc;
                    break;
                }
            }
            if (returnSize is null)
            {
                return(0.0);
            }

            ParcelPrice returnPrice = null;

            foreach (var parc in priceList)
            {
                if (parc.Size == size && parc.Weight.Weight == parc.Weight.Weight)
                {
                    returnPrice = parc;
                    break;
                }
            }


            return(returnPrice.Price);
        }