Ejemplo n.º 1
0
        private void ThrowAndLogException(CreateReportOrder createReportOrder, ErrorCode errorCodeType, string errorMessage = null)
        {
            var createOrderException = new HttpError(HttpStatusCode.BadRequest, errorCodeType.ToString(), errorMessage);

            createReportOrder.Error = createOrderException.ToString();
            _commandBus.Send(createReportOrder);

            throw createOrderException;
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Get(string name)
        {
            var drink = await this.repository.GetByName(name);

            if (drink == null)
            {
                var httpError = new HttpError("drink_not_found", $"Cannot get drink {name} because it cannot be found", string.Empty);
                this.logger.Error(httpError.ToString());
                return(this.NotFound(httpError));
            }

            return(this.Ok(drink));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Post([FromBody] Drink drink)
        {
            var existingDrink = await this.repository.GetByName(drink.Name);

            if (existingDrink != null)
            {
                var httpError = new HttpError("drink_exists", $"Cannot add drink {drink.Name} because it already exists", string.Empty);
                this.logger.Error(httpError.ToString());
                return(this.BadRequest(httpError));
            }

            await this.repository.Save(drink);

            return(this.Ok(drink));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Put(string name, [FromBody] Drink drink)
        {
            var existingDrink = await this.repository.GetByName(name);

            if (existingDrink == null)
            {
                var httpError = new HttpError("drink_not_found", $"You cannot update drink {name} because it cannot be found", string.Empty);
                this.logger.Error(httpError.ToString());
                return(this.NotFound(httpError));
            }

            existingDrink.Quantity = drink.Quantity;
            await this.repository.Save(existingDrink);

            return(this.Ok(drink));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Delete(string name)
        {
            var drink = await this.repository.GetByName(name);

            if (drink == null)
            {
                var httpError = new HttpError("drink_not_found", $"Cannot delete drink {name} because it cannot be found", string.Empty);
                this.logger.Error(httpError.ToString());
                return(this.NotFound(httpError));
            }

            await this.repository.Delete(name);

            return(this.Ok(new OkResponse {
                Message = "Ok"
            }));
        }
Ejemplo n.º 6
0
        internal InitializePayPalCheckoutResponse InitializePayPalCheckoutIfNecessary(
            Guid accountId, bool isPrepaid, Guid orderId, Contract.Requests.CreateOrderRequest request,
            decimal bookingFees, string companyKey, CreateReportOrder createReportOrder, string absoluteRequestUri)
        {
            if (isPrepaid &&
                request.Settings.ChargeTypeId == ChargeTypes.PayPal.Id)
            {
                var paypalWebPaymentResponse = _payPalServiceFactory.GetInstance(companyKey).InitializeWebPayment(accountId, orderId, absoluteRequestUri, request.Estimate.Price, bookingFees, request.ClientLanguageCode);

                if (paypalWebPaymentResponse.IsSuccessful)
                {
                    return(paypalWebPaymentResponse);
                }

                var createOrderException = new HttpError(HttpStatusCode.BadRequest, ErrorCode.CreateOrder_RuleDisable.ToString(), paypalWebPaymentResponse.Message);

                createReportOrder.Error = createOrderException.ToString();
                _commandBus.Send(createReportOrder);
                throw createOrderException;
            }

            return(null);
        }