public async Task WhenAsync(MergePatchShipmentDto c)
        {
            var idObj         = (c as IMergePatchShipment).ShipmentId;
            var uriParameters = new ShipmentUriParameters();

            uriParameters.Id = idObj;

            var req  = new ShipmentPatchRequest(uriParameters, (MergePatchShipmentDto)c);
            var resp = await _ramlClient.Shipment.Patch(req);

            ShipmentProxyUtils.ThrowOnHttpResponseError(resp);
        }
        public async virtual Task <IShipmentReceiptState> GetShipmentReceiptAsync(string shipmentId, string receiptSeqId)
        {
            var uriParameters = new ShipmentReceiptUriParameters();

            uriParameters.ShipmentId   = shipmentId;
            uriParameters.ReceiptSeqId = receiptSeqId;

            var req  = new ShipmentReceiptGetRequest(uriParameters);
            var resp = await _ramlClient.ShipmentReceipt.Get(req);

            ShipmentProxyUtils.ThrowOnHttpResponseError(resp);
            return((resp.Content == null) ? null : resp.Content.ToShipmentReceiptState());
        }
        public async virtual Task <IItemIssuanceState> GetItemIssuanceAsync(string shipmentId, string itemIssuanceSeqId)
        {
            var uriParameters = new ItemIssuanceUriParameters();

            uriParameters.ShipmentId        = shipmentId;
            uriParameters.ItemIssuanceSeqId = itemIssuanceSeqId;

            var req  = new ItemIssuanceGetRequest(uriParameters);
            var resp = await _ramlClient.ItemIssuance.Get(req);

            ShipmentProxyUtils.ThrowOnHttpResponseError(resp);
            return((resp.Content == null) ? null : resp.Content.ToItemIssuanceState());
        }
        public async Task <IShipmentState> GetHistoryStateAsync(string shipmentId, long version)
        {
            var idObj         = shipmentId;
            var uriParameters = new ShipmentHistoryStateUriParameters();

            uriParameters.Id      = idObj;
            uriParameters.Version = version.ToString();

            var req  = new ShipmentHistoryStateGetRequest(uriParameters);
            var resp = await _ramlClient.ShipmentHistoryState.Get(req);

            ShipmentProxyUtils.ThrowOnHttpResponseError(resp);
            return((resp.Content == null) ? null : resp.Content.ToShipmentState());
        }
        public async Task <IShipmentEvent> GetStateEventAsync(string shipmentId, long version)
        {
            var idObj         = shipmentId;
            var uriParameters = new ShipmentStateEventUriParameters();

            uriParameters.Id      = idObj;
            uriParameters.Version = version.ToString();

            var req  = new ShipmentStateEventGetRequest(uriParameters);
            var resp = await _ramlClient.ShipmentStateEvent.Get(req);

            ShipmentProxyUtils.ThrowOnHttpResponseError(resp);
            return(resp.Content);
        }
        public async Task <IShipmentState> GetAsync(string shipmentId)
        {
            IShipmentState state         = null;
            var            idObj         = shipmentId;
            var            uriParameters = new ShipmentUriParameters();

            uriParameters.Id = idObj;

            var req = new ShipmentGetRequest(uriParameters);

            var resp = await _ramlClient.Shipment.Get(req);

            ShipmentProxyUtils.ThrowOnHttpResponseError(resp);
            state = (resp.Content == null) ? null : resp.Content.ToShipmentState();
            return(state);
        }
        public async Task <IEnumerable <IShipmentState> > GetAsync(ICriterion filter, IList <string> orders = null, int firstResult = 0, int maxResults = int.MaxValue, IList <string> fields = null)
        {
            IEnumerable <IShipmentState> states = null;
            var q = new ShipmentsGetQuery();

            q.FirstResult = firstResult;
            q.MaxResults  = maxResults;
            q.Sort        = ShipmentProxyUtils.GetOrdersQueryValueString(orders);
            q.Fields      = ShipmentProxyUtils.GetReturnedFieldsQueryValueString(fields, QueryFieldValueSeparator);
            q.Filter      = ShipmentProxyUtils.GetFilterQueryValueString(filter);
            var req = new ShipmentsGetRequest();

            req.Query = q;
            var resp = await _ramlClient.Shipments.Get(req);

            ShipmentProxyUtils.ThrowOnHttpResponseError(resp);
            states = (resp.Content == null) ? null : resp.Content.Select(e => e.ToShipmentState());
            return(states);
        }
        public async Task WhenAsync(DeleteShipmentDto c)
        {
            var idObj         = (c as IDeleteShipment).ShipmentId;
            var uriParameters = new ShipmentUriParameters();

            uriParameters.Id = idObj;

            var q = new ShipmentDeleteQuery();

            q.CommandId   = c.CommandId;
            q.RequesterId = c.RequesterId;
            q.Version     = Convert.ToString(c.Version);

            var req = new ShipmentDeleteRequest(uriParameters);

            req.Query = q;

            var resp = await _ramlClient.Shipment.Delete(req);

            ShipmentProxyUtils.ThrowOnHttpResponseError(resp);
        }
        public async virtual Task <long> GetCountAsync(ICriterion filter)
        {
            var q = new ShipmentsCountGetQuery();

            q.Filter = ShipmentProxyUtils.GetFilterQueryValueString(filter);
            var req = new ShipmentsCountGetRequest();

            req.Query = q;
            var resp = await _ramlClient.ShipmentsCount.Get(req);

            ShipmentProxyUtils.ThrowOnHttpResponseError(resp);
            string str = await resp.RawContent.ReadAsStringAsync();

            if (str.StartsWith("\""))
            {
                str = str.Substring(1);
            }
            if (str.EndsWith("\""))
            {
                str = str.Substring(0, str.Length - 1);
            }
            return(long.Parse(str));
        }