Exemplo n.º 1
0
        /// <summary>
        /// 計算運費
        /// </summary>
        /// <param name="deliveryItem">宅配資料</param>
        /// <returns>運費</returns>
        public double Calculate(DeliveryEntity deliveryItem)
        {
            if (deliveryItem == null)
            {
                throw new ArgumentException("請檢查 deliveryItem 參數");
            }

            if (deliveryItem.DeliveryType == DeliveryTypeEnum.TCat)
            {
                deliveryItem.SetDeliveryType(new Tcat());
                return(deliveryItem.Caculate(deliveryItem));
            }
            else if (deliveryItem.DeliveryType == DeliveryTypeEnum.KTJ)
            {
                deliveryItem.SetDeliveryType(new KTJ());
                return(deliveryItem.Caculate(deliveryItem));
            }
            else if (deliveryItem.DeliveryType == DeliveryTypeEnum.PostOffice)
            {
                deliveryItem.SetDeliveryType(new PostOffice());
                return(deliveryItem.Caculate(deliveryItem));
            }
            else
            {
                throw new ArgumentException("請檢查 deliveryItem.DeliveryType 參數");
            }
        }
        /// <summary>
        /// 計算指定宅配項目的運費。
        /// </summary>
        /// <param name="deliveryItem">宅配項目。</param>
        /// <returns>
        /// 運費。
        /// </returns>
        /// <exception cref="ArgumentException">請檢查 deliveryItem 參數。</exception>
        public double Calculate(DeliveryEntity deliveryItem)
        {
            if (deliveryItem?.DeliveryType != DeliveryTypeEnum.KTJ)
            {
                throw new ArgumentException($"請檢查 {nameof(deliveryItem)} 參數。", nameof(deliveryItem));
            }

            var dimensions = new List <double>
            {
                deliveryItem.ProductLength,
                deliveryItem.ProductWidth,
                deliveryItem.ProductHeight
            };

            double fee;
            double size = dimensions.Aggregate((current, next) => current * next);

            if (dimensions.Any(x => x > 50))
            {
                fee = size * 0.00001 * 110 + 50;

                return(fee);
            }

            fee = size * 0.00001 * 120;

            return(fee);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 計算費用
        /// </summary>
        /// <param name="entity">DeliveryEntity</param>
        /// <returns>費用</returns>
        public double CalculateFee(DeliveryEntity entity)
        {
            var weightFee = this.GetWeightFee(entity.ProductWeight);

            var volumeFee = this.GetVolumeFee(entity.ProductLength, entity.ProductWidth, entity.ProductHeight);

            return(Math.Max(weightFee, volumeFee));
        }
Exemplo n.º 4
0
        public async Task <TData <string> > SaveForm(DeliveryEntity entity)
        {
            TData <string> obj = new TData <string>();
            await deliveryService.SaveForm(entity);

            obj.Data = entity.Id.ParseToString();
            obj.Tag  = 1;
            return(obj);
        }
        public void Test_Calculate(DeliveryEntity deliveryItem, double expected)
        {
            // Arrange
            var sut = this.GetSystemUnderTestInstance();

            // Act
            double actual = sut.Calculate(deliveryItem);

            // Arrange
            actual.Should().Be(expected);
        }
        /// <summary>
        /// 計算運費
        /// </summary>
        /// <param name="deliveryItem">宅配資料</param>
        /// <returns>運費</returns>
        public double Calculate(DeliveryEntity deliveryItem)
        {
            if (deliveryItem == null)
            {
                throw new ArgumentException("請檢查 deliveryItem 參數");
            }

            var fee = this._calculatorService.Calculate(deliveryItem);

            return(fee);
        }
Exemplo n.º 7
0
        // Metodo encargado de actualizar pedido
        public async Task UpdateDelivery(DeliveryEntity deliveryEntity)
        {
            var toUpdateDelivery = (await firebase
                                    .Child("Delivery")
                                    .OnceAsync <DeliveryEntity>()).Where(a => a.Object.deliveryID == deliveryEntity.deliveryID).FirstOrDefault();

            await firebase
            .Child("Delivery")
            .Child(toUpdateDelivery.Key)
            .PutAsync(deliveryEntity);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is DeliveryEntity)
            {
                DeliveryEntity delivery = (DeliveryEntity)value;

                return(delivery.regState[int.Parse(delivery.actualState)].mainStatus);
            }

            return(null);
        }
        /// <summary>
        /// 計算運費
        /// </summary>
        /// <param name="deliveryItem">宅配資料</param>
        /// <returns>運費</returns>
        public double Calculate(DeliveryEntity deliveryItem)
        {
            if (deliveryItem == null)
            {
                throw new ArgumentException("請檢查 deliveryItem 參數");
            }

            ICalculateFeeService calculateFeeService =
                this._calculateFeeDictionary.FirstOrDefault(x => x.Key(deliveryItem.DeliveryType)).Value;

            return(calculateFeeService.CalculateFee(deliveryItem));
        }
Exemplo n.º 10
0
 public DeliveryServiceModel(DeliveryEntity entity)
 {
     this.id              = entity.id;
     this.BaseCost        = entity.BaseCost;
     this.Distance        = entity.Distance;
     this.Floor           = entity.Floor;
     this.WeekendDelivery = entity.WeekendDelivery;
     this.GoldRated       = entity.GoldRated;
     this.HasCoupen       = entity.HasCoupen;
     this.TotalCost       = entity.TotalCost;
     this.NewCustomer     = entity.NewCustomer;
 }
        /// <summary>
        /// 計算運費。
        /// </summary>
        /// <param name="deliveryItem">宅配資料。</param>
        /// <returns>
        /// 運費。
        /// </returns>
        /// <exception cref="ArgumentNullException">deliveryItem - 請檢查 deliveryItem 參數。</exception>
        public double Calculate(DeliveryEntity deliveryItem)
        {
            if (deliveryItem == null)
            {
                throw new ArgumentNullException(nameof(deliveryItem), $"請檢查 {nameof(deliveryItem)} 參數。");
            }

            var    strategy = StrategyFactory.CreateStrategy(deliveryItem.DeliveryType);
            double fee      = strategy.Calculate(deliveryItem);

            return(fee);
        }
        public void Test_Calculate(DeliveryEntity deliveryItem, double expected)
        {
            //// Arrange
            var actual = 0d;
            var target = new DeliveryService();

            //// Act
            actual = target.Calculate(deliveryItem);

            //// Arrange
            expected.Should().Be(actual);
        }
Exemplo n.º 13
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // Extraigo la fecha inicial del pedido
            if (value is DeliveryEntity)
            {
                DeliveryEntity delivery = (DeliveryEntity)value;

                return(delivery.regState[int.Parse(delivery.actualState)].dateInitial);
            }

            return(null);
        }
        public void Calculate_當傳入參數deliveryItem為Null時_應拋出ArgumentNullException的例外狀況()
        {
            // Arrange
            DeliveryEntity deliveryItem = null;
            var            message      = $"請檢查 deliveryItem 參數。{Environment.NewLine}參數名稱: deliveryItem";
            var            sut          = this.GetSystemUnderTestInstance();

            // Act
            Action action = () => sut.Calculate(deliveryItem);

            // Assert
            action.ShouldThrow <ArgumentNullException>().And.Message.Should().Be(message);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 計算黑貓指定宅配項目的運費。
        /// </summary>
        /// <param name="deliveryItem">宅配項目。</param>
        /// <returns>運費。</returns>
        /// <exception cref="ArgumentException">deliveryItem</exception>
        private static double CalculateTCatShippingFee(DeliveryEntity deliveryItem)
        {
            if (deliveryItem?.DeliveryType != DeliveryTypeEnum.TCat)
            {
                throw new ArgumentException($"請檢查 {nameof(deliveryItem)} 參數。", nameof(deliveryItem));
            }

            double fee = deliveryItem.ProductWeight > 20
                         ? 400d
                         : 100 + deliveryItem.ProductWeight * 10;

            return(fee);
        }
        public void CalculatePostOfficeShippingFee_當傳入參數deliveryItem為Null時_應拋出ArgumentException的例外狀況()
        {
            // Arrange
            DeliveryEntity deliveryItem = null;
            var            message      = $"請檢查 deliveryItem 參數。{Environment.NewLine}參數名稱: deliveryItem";
            var            sut          = new PrivateType(typeof(DeliveryServiceByDelegate));

            // Act
            Action action = () => sut.InvokeStatic("CalculatePostOfficeShippingFee", deliveryItem);

            // Assert
            action.ShouldThrow <ArgumentException>().And.Message.Should().Be(message);
        }
Exemplo n.º 17
0
        public DeliveryDetailView(DeliveryEntity argDeliveryEntity, int argDeliveryIndex)
        {
            InitializeComponent();

            deliveryEntity = argDeliveryEntity;
            BindingContext = deliveryEntity;

            deliveryIndex = argDeliveryIndex;

            _pickerState.SelectedIndex = int.Parse(deliveryEntity.actualState);

            _listStates.ItemsSource = CoffeeSingleton.Instance.deliveryListSingleton[deliveryIndex].regState;
        }
Exemplo n.º 18
0
        /// <summary>
        /// 計算運費
        /// </summary>
        /// <param name="deliveryItem">宅配資料</param>
        /// <returns>運費</returns>
        public double Calculate(DeliveryEntity deliveryItem)
        {
            if (deliveryItem == null)
            {
                throw new ArgumentException("請檢查 deliveryItem 參數");
            }

            var fee = default(double);

            if (deliveryItem.DeliveryType == DeliveryTypeEnum.TCat)
            {
                var weight = deliveryItem.ProductWeight;
                if (weight > 20)
                {
                    fee = 400d;
                }
                else
                {
                    fee = 100 + weight * 10;
                }
                return(fee);
            }
            else if (deliveryItem.DeliveryType == DeliveryTypeEnum.KTJ)
            {
                var length = deliveryItem.ProductLength;
                var width  = deliveryItem.ProductWidth;
                var height = deliveryItem.ProductHeight;

                var size = length * width * height;

                if (length > 50 || width > 50 || height > 50)
                {
                    fee = size * 0.00001 * 110 + 50;
                }
                else
                {
                    fee = size * 0.00001 * 120;
                }

                return(fee);
            }
            else if (deliveryItem.DeliveryType == DeliveryTypeEnum.PostOffice)
            {
                throw new NotImplementedException();
            }
            else
            {
                throw new ArgumentException("請檢查 deliveryItem.DeliveryType 參數");
            }
        }
Exemplo n.º 19
0
        public async Task SaveForm(DeliveryEntity entity)
        {
            if (entity.Id.IsNullOrZero())
            {
                await entity.Create();

                await this.BaseRepository().Insert(entity);
            }
            else
            {
                await entity.Modify();

                await this.BaseRepository().Update(entity);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// 計算郵局指定宅配項目的運費。
        /// </summary>
        /// <param name="deliveryItem">宅配項目。</param>
        /// <returns>運費。</returns>
        /// <exception cref="ArgumentException">deliveryItem</exception>
        private static double CalculatePostOfficeShippingFee(DeliveryEntity deliveryItem)
        {
            if (deliveryItem?.DeliveryType != DeliveryTypeEnum.PostOffice)
            {
                throw new ArgumentException($"請檢查 {nameof(deliveryItem)} 參數。", nameof(deliveryItem));
            }

            double feeByWeight     = deliveryItem.ProductWeight * 10 + 80;
            double feeByVolumetric =
                deliveryItem.ProductLength * deliveryItem.ProductWidth * deliveryItem.ProductHeight * 0.00001 * 110;

            double fee = Math.Max(feeByWeight, feeByVolumetric);

            return(fee);
        }
        /// <summary>
        /// 計算運費
        /// </summary>
        /// <param name="deliveryItem">宅配資料</param>
        /// <returns>運費</returns>
        public double Calculate(DeliveryEntity deliveryItem)
        {
            var fee    = 0d;
            var weight = deliveryItem.ProductWeight;

            if (weight > 20)
            {
                fee = 400d;
            }
            else
            {
                fee = 100 + (weight * 10);
            }

            return(fee);
        }
Exemplo n.º 22
0
        public DeliveryServiceModel Save(DeliveryServiceModel deliveryServiceModel)
        {
            var entity = new DeliveryEntity();

            entity.BaseCost        = deliveryServiceModel.BaseCost;
            entity.Distance        = deliveryServiceModel.Distance;
            entity.Floor           = deliveryServiceModel.Floor;
            entity.WeekendDelivery = deliveryServiceModel.WeekendDelivery;
            entity.GoldRated       = deliveryServiceModel.GoldRated;
            entity.HasCoupen       = deliveryServiceModel.HasCoupen;
            entity.TotalCost       = deliveryServiceModel.TotalCost;

            this._context.DeliveryEntities.Add(entity);
            this._context.SaveChanges();
            return(new DeliveryServiceModel(entity));
        }
        /// <summary>
        /// 計算費用
        /// </summary>
        /// <param name="entity">DeliveryEntity</param>
        /// <returns>費用</returns>
        public double CalculateFee(DeliveryEntity entity)
        {
            var fee    = 0d;
            var weight = entity.ProductWeight;

            if (weight > 20)
            {
                fee = 400d;
            }
            else
            {
                fee = 100 + (weight * 10);
            }

            return(fee);
        }
Exemplo n.º 24
0
        public async Task UpdateOrderAddress(Guid orderId, DeliveryEntity delivery)
        {
            string sql = $"Update {TableDescription.TableName.Delivery} set " +
                         $"{TableDescription.Delivery.City} = @{nameof(DeliveryEntity.City)}, " +
                         $"{TableDescription.Delivery.Country} = @{nameof(DeliveryEntity.Country)}, " +
                         $"{TableDescription.Delivery.Street} = @{nameof(DeliveryEntity.Street)} " +
                         $"Where {TableDescription.Delivery.DeliveryId} = @{nameof(DeliveryEntity.DeliveryId)};";

            DbConnection connection = await _connectionnWrapper.GetConnectionAsync();

            _ = await connection.ExecuteAsync(sql, new
            {
                DeliveryId = orderId,
                City       = delivery.City,
                Country    = delivery.Country,
                Street     = delivery.Street
            });
        }
Exemplo n.º 25
0
        /// <summary>
        /// 計算運費。
        /// </summary>
        /// <param name="deliveryItem">宅配資料。</param>
        /// <returns>
        /// 運費。
        /// </returns>
        /// <exception cref="ArgumentNullException">deliveryItem - deliveryItem</exception>
        /// <exception cref="ArgumentException">DeliveryType - DeliveryType</exception>
        public double Calculate(DeliveryEntity deliveryItem)
        {
            if (deliveryItem == null)
            {
                throw new ArgumentNullException(nameof(deliveryItem), $"請檢查 {nameof(deliveryItem)} 參數。");
            }

            if (_strategies.TryGetValue(deliveryItem.DeliveryType, out var strategyDelegate) == false)
            {
                throw new ArgumentException(
                          $"請檢查 {nameof(deliveryItem.DeliveryType)} 參數。",
                          nameof(deliveryItem.DeliveryType));
            }

            double fee = strategyDelegate(deliveryItem);

            return(fee);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // Extraigo la fecha inicial del pedido
            if (value is DeliveryEntity)
            {
                DeliveryEntity delivery   = (DeliveryEntity)value;
                List <string>  statesList = new List <string>();

                // Recorro el objeto y extraigo el nombre de los estados
                foreach (var item in delivery.regState)
                {
                    statesList.Add(item.mainStatus);
                }

                return(statesList);
            }

            return(null);
        }
        public void Calculate_當傳入參數DeliveryType為TCat且ProductWeight小於20時_應回傳相對的運費()
        {
            // Arrange
            var deliveryItem = new DeliveryEntity()
            {
                ProductLength = 60,
                ProductWidth  = 60,
                ProductHeight = 80,
                ProductWeight = 15,
                DeliveryType  = DeliveryTypeEnum.TCat
            };
            double expected = 250;
            var    sut      = this.GetSystemUnderTestInstance();

            // Act
            double actual = sut.Calculate(deliveryItem);

            // Assert
            actual.Should().Be(expected);
        }
        public void CalculatePostOfficeShippingFee_當傳入參數DeliveryType為PostOffice且依重量計算的運費小於依材積計算的運費時_應回傳依材積計算的運費()
        {
            // Arrange
            var deliveryItem = new DeliveryEntity()
            {
                ProductLength = 60,
                ProductWidth  = 60,
                ProductHeight = 80,
                ProductWeight = 15,
                DeliveryType  = DeliveryTypeEnum.PostOffice
            };
            double expected = 316.8;
            var    sut      = new PrivateType(typeof(DeliveryServiceByDelegate));

            // Act
            double actual = (double)sut.InvokeStatic("CalculatePostOfficeShippingFee", deliveryItem);

            // Assert
            actual.Should().Be(expected);
        }
        public void Calculate_當傳入參數DeliveryType為未定義宅配策略的值時_應拋出ArgumentException的例外狀況()
        {
            // Arrange
            var deliveryItem = new DeliveryEntity()
            {
                ProductLength = 30,
                ProductWidth  = 40,
                ProductHeight = 50,
                ProductWeight = 25,
                DeliveryType  = (DeliveryTypeEnum)99
            };
            var message = $"請檢查 DeliveryType 參數。{Environment.NewLine}參數名稱: DeliveryType";
            var sut     = this.GetSystemUnderTestInstance();

            // Act
            Action action = () => sut.Calculate(deliveryItem);

            // Assert
            action.ShouldThrow <ArgumentException>().And.Message.Should().Be(message);
        }
        public void CalculatePostOfficeShippingFee_當傳入參數DeliveryType不為PostOffice時_應拋出ArgumentException的例外狀況()
        {
            // Arrange
            var deliveryItem = new DeliveryEntity()
            {
                ProductLength = 30,
                ProductWidth  = 40,
                ProductHeight = 50,
                ProductWeight = 25,
                DeliveryType  = (DeliveryTypeEnum)99
            };
            var message = $"請檢查 deliveryItem 參數。{Environment.NewLine}參數名稱: deliveryItem";
            var sut     = new PrivateType(typeof(DeliveryServiceByDelegate));

            // Act
            Action action = () => sut.InvokeStatic("CalculatePostOfficeShippingFee", deliveryItem);

            // Assert
            action.ShouldThrow <ArgumentException>().And.Message.Should().Be(message);
        }