public async Task WhenAsync(MergePatchSupplierProductDto c)
        {
            var idObj         = SupplierProductProxyUtils.ToIdString((c as IMergePatchSupplierProduct).SupplierProductId);
            var uriParameters = new SupplierProductUriParameters();

            uriParameters.Id = idObj;

            var req  = new SupplierProductPatchRequest(uriParameters, (MergePatchSupplierProductDto)c);
            var resp = await _ramlClient.SupplierProduct.Patch(req);

            SupplierProductProxyUtils.ThrowOnHttpResponseError(resp);
        }
        public async Task <ISupplierProductState> GetHistoryStateAsync(SupplierProductId supplierProductId, long version)
        {
            var idObj         = SupplierProductProxyUtils.ToIdString(supplierProductId);
            var uriParameters = new SupplierProductHistoryStateUriParameters();

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

            var req  = new SupplierProductHistoryStateGetRequest(uriParameters);
            var resp = await _ramlClient.SupplierProductHistoryState.Get(req);

            SupplierProductProxyUtils.ThrowOnHttpResponseError(resp);
            return((resp.Content == null) ? null : resp.Content.ToSupplierProductState());
        }
        public async Task <ISupplierProductEvent> GetStateEventAsync(SupplierProductId supplierProductId, long version)
        {
            var idObj         = SupplierProductProxyUtils.ToIdString(supplierProductId);
            var uriParameters = new SupplierProductStateEventUriParameters();

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

            var req  = new SupplierProductStateEventGetRequest(uriParameters);
            var resp = await _ramlClient.SupplierProductStateEvent.Get(req);

            SupplierProductProxyUtils.ThrowOnHttpResponseError(resp);
            return(resp.Content);
        }
        public async Task <ISupplierProductState> GetAsync(SupplierProductId supplierProductId)
        {
            ISupplierProductState state = null;
            var idObj         = SupplierProductProxyUtils.ToIdString(supplierProductId);
            var uriParameters = new SupplierProductUriParameters();

            uriParameters.Id = idObj;

            var req = new SupplierProductGetRequest(uriParameters);

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

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

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

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

            SupplierProductProxyUtils.ThrowOnHttpResponseError(resp);
            states = (resp.Content == null) ? null : resp.Content.Select(e => e.ToSupplierProductState());
            return(states);
        }
        public async Task WhenAsync(DeleteSupplierProductDto c)
        {
            var idObj         = SupplierProductProxyUtils.ToIdString((c as IDeleteSupplierProduct).SupplierProductId);
            var uriParameters = new SupplierProductUriParameters();

            uriParameters.Id = idObj;

            var q = new SupplierProductDeleteQuery();

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

            var req = new SupplierProductDeleteRequest(uriParameters);

            req.Query = q;

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

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

            q.Filter = SupplierProductProxyUtils.GetFilterQueryValueString(filter);
            var req = new SupplierProductsCountGetRequest();

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

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