public async Task WhenAsync(MergePatchLotDto c)
        {
            var idObj         = (c as IMergePatchLot).LotId;
            var uriParameters = new LotUriParameters();

            uriParameters.Id = idObj;

            var req  = new LotPatchRequest(uriParameters, (MergePatchLotDto)c);
            var resp = await _ramlClient.Lot.Patch(req);

            LotProxyUtils.ThrowOnHttpResponseError(resp);
        }
        public async Task <ILotState> GetHistoryStateAsync(string lotId, long version)
        {
            var idObj         = lotId;
            var uriParameters = new LotHistoryStateUriParameters();

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

            var req  = new LotHistoryStateGetRequest(uriParameters);
            var resp = await _ramlClient.LotHistoryState.Get(req);

            LotProxyUtils.ThrowOnHttpResponseError(resp);
            return((resp.Content == null) ? null : resp.Content.ToLotState());
        }
        public async Task <ILotEvent> GetStateEventAsync(string lotId, long version)
        {
            var idObj         = lotId;
            var uriParameters = new LotStateEventUriParameters();

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

            var req  = new LotStateEventGetRequest(uriParameters);
            var resp = await _ramlClient.LotStateEvent.Get(req);

            LotProxyUtils.ThrowOnHttpResponseError(resp);
            return(resp.Content);
        }
        public async Task <ILotState> GetAsync(string lotId)
        {
            ILotState state         = null;
            var       idObj         = lotId;
            var       uriParameters = new LotUriParameters();

            uriParameters.Id = idObj;

            var req = new LotGetRequest(uriParameters);

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

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

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

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

            LotProxyUtils.ThrowOnHttpResponseError(resp);
            states = (resp.Content == null) ? null : resp.Content.Select(e => e.ToLotState());
            return(states);
        }
        public async Task WhenAsync(DeleteLotDto c)
        {
            var idObj         = (c as IDeleteLot).LotId;
            var uriParameters = new LotUriParameters();

            uriParameters.Id = idObj;

            var q = new LotDeleteQuery();

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

            var req = new LotDeleteRequest(uriParameters);

            req.Query = q;

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

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

            q.Filter = LotProxyUtils.GetFilterQueryValueString(filter);
            var req = new LotsCountGetRequest();

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

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