public async Task WhenAsync(MergePatchSellableInventoryItemDto c)
        {
            var idObj         = SellableInventoryItemProxyUtils.ToIdString((c as IMergePatchSellableInventoryItem).SellableInventoryItemId);
            var uriParameters = new SellableInventoryItemUriParameters();

            uriParameters.Id = idObj;

            var req  = new SellableInventoryItemPatchRequest(uriParameters, (MergePatchSellableInventoryItemDto)c);
            var resp = await _ramlClient.SellableInventoryItem.Patch(req);

            SellableInventoryItemProxyUtils.ThrowOnHttpResponseError(resp);
        }
        public async virtual Task <ISellableInventoryItemEntryState> GetSellableInventoryItemEntryAsync(InventoryItemId sellableInventoryItemId, long entrySeqId)
        {
            var uriParameters = new SellableInventoryItemEntryUriParameters();

            uriParameters.SellableInventoryItemId = ((new ValueObjectTextFormatter <InventoryItemId>())).ToString(sellableInventoryItemId);
            uriParameters.EntrySeqId = entrySeqId;

            var req  = new SellableInventoryItemEntryGetRequest(uriParameters);
            var resp = await _ramlClient.SellableInventoryItemEntry.Get(req);

            SellableInventoryItemProxyUtils.ThrowOnHttpResponseError(resp);
            return((resp.Content == null) ? null : resp.Content.ToSellableInventoryItemEntryState());
        }
        public async Task <ISellableInventoryItemState> GetHistoryStateAsync(InventoryItemId sellableInventoryItemId, long version)
        {
            var idObj         = SellableInventoryItemProxyUtils.ToIdString(sellableInventoryItemId);
            var uriParameters = new SellableInventoryItemHistoryStateUriParameters();

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

            var req  = new SellableInventoryItemHistoryStateGetRequest(uriParameters);
            var resp = await _ramlClient.SellableInventoryItemHistoryState.Get(req);

            SellableInventoryItemProxyUtils.ThrowOnHttpResponseError(resp);
            return((resp.Content == null) ? null : resp.Content.ToSellableInventoryItemState());
        }
        public async Task <ISellableInventoryItemEvent> GetStateEventAsync(InventoryItemId sellableInventoryItemId, long version)
        {
            var idObj         = SellableInventoryItemProxyUtils.ToIdString(sellableInventoryItemId);
            var uriParameters = new SellableInventoryItemStateEventUriParameters();

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

            var req  = new SellableInventoryItemStateEventGetRequest(uriParameters);
            var resp = await _ramlClient.SellableInventoryItemStateEvent.Get(req);

            SellableInventoryItemProxyUtils.ThrowOnHttpResponseError(resp);
            return(resp.Content);
        }
        public async Task <ISellableInventoryItemState> GetAsync(InventoryItemId sellableInventoryItemId)
        {
            ISellableInventoryItemState state = null;
            var idObj         = SellableInventoryItemProxyUtils.ToIdString(sellableInventoryItemId);
            var uriParameters = new SellableInventoryItemUriParameters();

            uriParameters.Id = idObj;

            var req = new SellableInventoryItemGetRequest(uriParameters);

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

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

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

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

            SellableInventoryItemProxyUtils.ThrowOnHttpResponseError(resp);
            states = (resp.Content == null) ? null : resp.Content.Select(e => e.ToSellableInventoryItemState());
            return(states);
        }
        public async Task WhenAsync(DeleteSellableInventoryItemDto c)
        {
            var idObj         = SellableInventoryItemProxyUtils.ToIdString((c as IDeleteSellableInventoryItem).SellableInventoryItemId);
            var uriParameters = new SellableInventoryItemUriParameters();

            uriParameters.Id = idObj;

            var q = new SellableInventoryItemDeleteQuery();

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

            var req = new SellableInventoryItemDeleteRequest(uriParameters);

            req.Query = q;

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

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

            q.Filter = SellableInventoryItemProxyUtils.GetFilterQueryValueString(filter);
            var req = new SellableInventoryItemsCountGetRequest();

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

            SellableInventoryItemProxyUtils.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));
        }