Beispiel #1
0
        public async Task <ResponseContent> ProcessOrderProposalCreationP(string clientId, Uri sellerId, string uuidString, string orderJson)
        {
            // Note B will never contain OrderItem level errors, and any issues that occur will be thrown as exceptions.
            // If C1 and C2 are used correctly, P should not fail except in very exceptional cases.
            OrderProposal order = OpenActiveSerializer.Deserialize <OrderProposal>(orderJson);

            if (order == null || order.GetType() != typeof(OrderProposal))
            {
                throw new OpenBookingException(new UnexpectedOrderTypeError(), "OrderProposal is required for P");
            }
            var(orderId, sellerIdComponents, seller) = await ConstructIdsFromRequest(clientId, sellerId, uuidString, OrderType.OrderProposal);

            using (await asyncDuplicateLock.LockAsync(GetParallelLockKey(orderId)))
            {
                return(ResponseContent.OpenBookingResponse(OpenActiveSerializer.Serialize(await ProcessFlowRequest(ValidateFlowRequest <OrderProposal>(orderId, sellerIdComponents, seller, FlowStage.P, order), order)), HttpStatusCode.Created));
            }
        }
Beispiel #2
0
        public async Task <ResponseContent> ProcessOrderProposalUpdate(string clientId, Uri sellerId, string uuidString, string orderProposalJson)
        {
            var orderId = new OrderIdComponents {
                ClientId = clientId, OrderType = OrderType.OrderProposal, uuid = ConvertToGuid(uuidString)
            };

            using (await asyncDuplicateLock.LockAsync(GetParallelLockKey(orderId)))
            {
                OrderProposal      orderProposal      = OpenActiveSerializer.Deserialize <OrderProposal>(orderProposalJson);
                SellerIdComponents sellerIdComponents = GetSellerIdComponentsFromApiKey(sellerId);

                if (orderProposal == null || orderProposal.GetType() != typeof(Order))
                {
                    throw new OpenBookingException(new UnexpectedOrderTypeError(), "OrderProposal is required for Order Cancellation");
                }

                // Check for PatchContainsExcessiveProperties
                OrderProposal orderProposalWithOnlyAllowedProperties = new OrderProposal
                {
                    OrderProposalStatus = orderProposal.OrderProposalStatus,
                    OrderCustomerNote   = orderProposal.OrderCustomerNote
                };
                if (OpenActiveSerializer.Serialize <OrderProposal>(orderProposal) != OpenActiveSerializer.Serialize <OrderProposal>(orderProposalWithOnlyAllowedProperties))
                {
                    throw new OpenBookingException(new PatchContainsExcessivePropertiesError());
                }

                // Check for PatchNotAllowedOnProperty
                if (orderProposal.OrderProposalStatus != OrderProposalStatus.CustomerRejected)
                {
                    throw new OpenBookingException(new PatchNotAllowedOnPropertyError(), "Only 'https://openactive.io/CustomerRejected' is permitted for this property.");
                }

                await ProcessOrderProposalCustomerRejection(orderId, sellerIdComponents, settings.OrderIdTemplate);

                return(ResponseContent.OpenBookingNoContentResponse());
            }
        }