コード例 #1
0
        public ServiceResponseObject <ComputationResponse> PriceComputation(PriceComputationViewModel model)
        {
            ServiceResponseObject <ComputationResponse> response = new ServiceResponseObject <ComputationResponse>();

            if (model.CargeType == "Выбор" || model.DangerClassType == "Выбор")
            {
                ModelState.AddModelError(string.Empty, "Укажите характер груза или класс опасности");
            }

            if (ModelState.IsValid)
            {
                OrderMethods BoxData = new OrderMethods(_boxContext, _userManager);
                var          price   = BoxData.PriceComputation(model);
                response.Message      = "Успешно!";
                response.ResponseData = new ComputationResponse {
                    Price = price
                };
                response.Status = ResponseResult.OK;
                return(response);
            }
            response.Status = ResponseResult.Error;
            List <string> errors = ModelState.Values.Aggregate(
                new List <string>(),
                (a, c) =>
            {
                a.AddRange(c.Errors.Select(r => r.ErrorMessage));
                return(a);
            },
                a => a
                );

            response.ResponseData = new ComputationResponse();
            response.Message      = errors[0];
            return(response);
        }
コード例 #2
0
ファイル: OrderMethods.cs プロジェクト: daryalove/MvcBox
        /// <summary>
        /// Вычисление предварительной цены заказа
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public double PriceComputation(PriceComputationViewModel model)
        {
            //try
            //{
            //    var dangerClass = Rates[1].RateTypes.Find(f => f.Name == model.DangerClassType);
            //    var carge = Rates[0].RateTypes.Find(f => f.Name == model.CargeType) ;

            //    var price = model.Length * model.Weight * (carge.Price) * (dangerClass.Index);
            //    if (model.IsInsured)
            //    {
            //        price += (Rates[2].RateTypes[0].Index) * model.CargeValue;
            //    }

            //    //var result = Math.Ceiling(price);
            //    return price;
            //}
            //catch (Exception)
            //{
            //    return 0.00;
            //}
            return(0.00);
        }