Пример #1
0
        public Delivery(long orderId, DeliveryResponseObject deliveryResponse, SveaHttpClient client)
        {
            Actions = new DeliveryActions(orderId, deliveryResponse, client);

            CreationDate     = deliveryResponse.CreationDate;
            CreditedAmount   = deliveryResponse.CreditedAmount;
            Credits          = deliveryResponse.Credits;
            DeliveryAmount   = deliveryResponse.DeliveryAmount;
            DueDate          = deliveryResponse.DueDate;
            Id               = deliveryResponse.Id;
            InvoiceId        = deliveryResponse.InvoiceId;
            Status           = deliveryResponse.Status;
            AvailableActions = deliveryResponse.Actions;

            OrderRows = deliveryResponse.OrderRows?.Select(x => new OrderRow(orderId, x, client)).ToList();
        }
Пример #2
0
        public DeliveryActions(long orderId, DeliveryResponseObject deliveryResponse, SveaHttpClient client)
        {
            foreach (var action in deliveryResponse.Actions)
            {
                switch (action)
                {
                case DeliveryActionType.CanCreditOrderRows:
                    CreditOrderRows = async payload =>
                    {
                        var response = await client
                                       .HttpPost <ResourceResponseObject <CreditResponseObject>, CreditResponseObject>(
                            new Uri($"/api/v1/orders/{orderId}/deliveries/{deliveryResponse.Id}/credits",
                                    UriKind.Relative), payload);

                        var resource = new ResourceResponse <CreditResponseObject, CreditResponse>(response, () => new CreditResponse(response.Resource));

                        return(resource);
                    };
                    break;

                case DeliveryActionType.CanCreditNewRow:
                    CreditNewRow = async payload =>
                    {
                        var response = await client
                                       .HttpPost <ResourceResponseObject <CreditResponseObject>, CreditResponseObject>(
                            new Uri($"/api/v1/orders/{orderId}/deliveries/{deliveryResponse.Id}/credits",
                                    UriKind.Relative), payload);

                        var resource = new ResourceResponse <CreditResponseObject, CreditResponse>(response, () => new CreditResponse(response.Resource));

                        return(resource);
                    };
                    break;

                case DeliveryActionType.CanCreditAmount:
                    CreditAmount = async payload =>
                    {
                        var response = await client.HttpPatch <CreditResponseObject>(
                            new Uri($"/api/v1/orders/{orderId}/deliveries/{deliveryResponse.Id}", UriKind.Relative),
                            payload);

                        return(new CreditResponse(response));
                    };
                    break;
                }
            }
        }