public async Task WhenAsync(MergePatchInventoryItemDto c)
        {
            var idObj         = InventoryItemProxyUtils.ToIdString((c as IMergePatchInventoryItem).InventoryItemId);
            var uriParameters = new InventoryItemUriParameters();

            uriParameters.Id = idObj;

            var req  = new InventoryItemPatchRequest(uriParameters, (MergePatchInventoryItemDto)c);
            var resp = await _ramlClient.InventoryItem.Patch(req);

            InventoryItemProxyUtils.ThrowOnHttpResponseError(resp);
        }
        public async virtual Task <IInventoryItemEntryState> GetInventoryItemEntryAsync(InventoryItemId inventoryItemId, long entrySeqId)
        {
            var uriParameters = new InventoryItemEntryUriParameters();

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

            var req  = new InventoryItemEntryGetRequest(uriParameters);
            var resp = await _ramlClient.InventoryItemEntry.Get(req);

            InventoryItemProxyUtils.ThrowOnHttpResponseError(resp);
            return((resp.Content == null) ? null : resp.Content.ToInventoryItemEntryState());
        }
        public async Task <IInventoryItemState> GetHistoryStateAsync(InventoryItemId inventoryItemId, long version)
        {
            var idObj         = InventoryItemProxyUtils.ToIdString(inventoryItemId);
            var uriParameters = new InventoryItemHistoryStateUriParameters();

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

            var req  = new InventoryItemHistoryStateGetRequest(uriParameters);
            var resp = await _ramlClient.InventoryItemHistoryState.Get(req);

            InventoryItemProxyUtils.ThrowOnHttpResponseError(resp);
            return((resp.Content == null) ? null : resp.Content.ToInventoryItemState());
        }
        public async Task <IInventoryItemEvent> GetStateEventAsync(InventoryItemId inventoryItemId, long version)
        {
            var idObj         = InventoryItemProxyUtils.ToIdString(inventoryItemId);
            var uriParameters = new InventoryItemStateEventUriParameters();

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

            var req  = new InventoryItemStateEventGetRequest(uriParameters);
            var resp = await _ramlClient.InventoryItemStateEvent.Get(req);

            InventoryItemProxyUtils.ThrowOnHttpResponseError(resp);
            return(resp.Content);
        }
        public async Task <IInventoryItemState> GetAsync(InventoryItemId inventoryItemId)
        {
            IInventoryItemState state = null;
            var idObj         = InventoryItemProxyUtils.ToIdString(inventoryItemId);
            var uriParameters = new InventoryItemUriParameters();

            uriParameters.Id = idObj;

            var req = new InventoryItemGetRequest(uriParameters);

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

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

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

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

            InventoryItemProxyUtils.ThrowOnHttpResponseError(resp);
            states = (resp.Content == null) ? null : resp.Content.Select(e => e.ToInventoryItemState());
            return(states);
        }
        public async Task WhenAsync(DeleteInventoryItemDto c)
        {
            var idObj         = InventoryItemProxyUtils.ToIdString((c as IDeleteInventoryItem).InventoryItemId);
            var uriParameters = new InventoryItemUriParameters();

            uriParameters.Id = idObj;

            var q = new InventoryItemDeleteQuery();

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

            var req = new InventoryItemDeleteRequest(uriParameters);

            req.Query = q;

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

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

            q.Filter = InventoryItemProxyUtils.GetFilterQueryValueString(filter);
            var req = new InventoryItemsCountGetRequest();

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

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