public IActionResult GetSumPrice(OrderPriceModel carForPrice)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(BadRequest(errors));
                }

                OrderPriceModel carSumPrice = priceRepository.priceForOrderIfAvaliable(carForPrice);
                return(StatusCode(StatusCodes.Status201Created, carSumPrice));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);

                if (ex is DateNotAvaliableException)
                {
                    return(StatusCode(StatusCodes.Status403Forbidden, errors));
                }

                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Exemplo n.º 2
0
        public OrderPriceModel priceForOrderIfAvaliable(OrderPriceModel carForPrice)
        {
            bool isAvaliable = CheckIfCarAvaliable(carForPrice.carNumber, carForPrice.rentStartDate, carForPrice.rentEndDate) == true;

            if (isAvaliable == true)
            {
                FullCarDataModel myCarsForRentModel = GetCarDayPrice(carForPrice.carNumber);

                carForPrice.orderDays = ((carForPrice.rentEndDate - carForPrice.rentStartDate).Days);
                carForPrice.carPrice  = PriceLogic.CarPrice(carForPrice.rentStartDate, carForPrice.rentEndDate, myCarsForRentModel.carDayPrice);
            }
            else
            {
                throw new DateNotAvaliableException("The Car Is Not Avaliable at this dates");
            }
            return(carForPrice);
        }
        public static OrderPriceModel ToObject(SqlDataReader reader)
        {
            DateTime dateValue;

            OrderPriceModel orderPriceModel = new OrderPriceModel();

            orderPriceModel.carNumber = reader[0].ToString();
            if (DateTime.TryParse(reader[1].ToString(), out dateValue))
            {
                orderPriceModel.rentStartDate = DateTime.Parse(reader[1].ToString());
            }

            if (DateTime.TryParse(reader[2].ToString(), out dateValue))
            {
                orderPriceModel.rentEndDate = DateTime.Parse(reader[2].ToString());
            }
            orderPriceModel.carPrice  = decimal.Parse(reader[3].ToString());
            orderPriceModel.orderDays = int.Parse(reader[4].ToString());

            Debug.WriteLine("orderPriceModel: " + orderPriceModel.ToString());
            return(orderPriceModel);
        }