public HttpResponseMessage GetSumPrice(OrderPriceModel carForPrice)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
                }

                OrderPriceModel carSumPrice = priceRepository.priceForOrderIfAvaliable(carForPrice);
                return(Request.CreateResponse(HttpStatusCode.Created, carSumPrice));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);

                if (ex is DateNotAvaliableException)
                {
                    return(Request.CreateResponse(HttpStatusCode.Forbidden, errors));
                }

                return(Request.CreateResponse(HttpStatusCode.InternalServerError, errors));
            }
        }
        public static OrderPriceModel ToObject(SqlDataReader reader)
        {
            OrderPriceModel orderPriceModel = new OrderPriceModel();

            orderPriceModel.carNumber     = reader[0].ToString();
            orderPriceModel.rentStartDate = DateTime.Parse(reader[1].ToString());
            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);
        }
Ejemplo n.º 3
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);
        }