Beispiel #1
0
        public IHttpActionResult Checkout(RentoRequest <Checkout> request)
        {
            Logger.Debug("Checkout", request);
            var response = new RentoResponse <int>(request);

            return(Ok(TryCatch(request, response, ValidateType.Active, async() =>
            {
                var daysPeriod = (request.Data.To - request.Data.From).Days;
                if (!ValidateRequirdField(request.Data.CarId, request.Data.Price)
                    ||
                    !ValidateRequirdField(request.Data.From, request.Data.To)
                    ||
                    (daysPeriod < 1)
                    ||
                    (request.Data.Flag == (int)CheckoutFlag.DeliverToMyLocation && (request.Data.Location == null || !ValidateRequirdField(request.Data.Location.Longitude, request.Data.Location.Latitude))))
                {
                    response.ErrorCode = ErrorCode.RequirdField;
                    return;
                }
                var checkOutId = await CarManager.Checkout(UserSession.Id, request.Data);
                switch (checkOutId)
                {
                case -1:
                    response.ErrorCode = ErrorCode.CustomerNonComplete;
                    return;

                case 0:
                    response.ErrorCode = ErrorCode.CarAlreadyReserved;
                    return;

                default:
                    await Database.MessageManager.Create(UserSession.Id, string.Format("{0} {1}",
                                                                                       request.Language == (int)Language.Arabic ?
                                                                                       "تم ارسال طلب استئجار سيارة من قبلكم بنجاح ورقم الحجر هو" :
                                                                                       "Car rent order request done successfully with number", checkOutId
                                                                                       ));
                    break;
                }
                response.Data = checkOutId;
            })));
        }