Esempio n. 1
0
        public static async Task <List <TransactionsAddReply> > TransactionsAdd(List <QueueModel> transactionlist)
        {
            Uri     route   = new Uri("/api/pos/transactionsAdd", UriKind.Relative);
            ApiAuth apiAuth = new ApiAuth {
                APIKey = Store.QueueGetAPIKey().value, POSCode = Utils.POSId
            };
            TransactionsAdd transactionsadd = new TransactionsAdd
            {
                apiAuth      = apiAuth,
                transactions = transactionlist
            };

            var jsonString = JsonConvert.SerializeObject(transactionsadd);
            var content    = new StringContent(jsonString, Encoding.UTF8, "application/json");
            List <TransactionsAddReply> responseBody = null;

            using (HttpResponseMessage response = await ApiClient.PostAsync(route, content))
            {
                if (response.IsSuccessStatusCode)
                {
                    responseBody = response.Content.ReadAsAsync <List <TransactionsAddReply> >().Result;
                }
                else
                {
                    var message = response.ReasonPhrase + ": " + response.Content.ReadAsStringAsync().Result;
                    content.Dispose();
                    throw new HttpRequestException(message);
                }
            }
            content.Dispose();
            return(responseBody);
        }
Esempio n. 2
0
        public static async Task <List <ActionsGetReply> > ActionsGet()
        {
            Uri     route   = new Uri("/api/pos/ActionsGet", UriKind.Relative);
            ApiAuth ApiAuth = new ApiAuth {
                APIKey = Store.QueueGetAPIKey().value, POSCode = Utils.POSId
            };
            var jsonString = JsonConvert.SerializeObject(new { apiAuth = ApiAuth });
            var content    = new StringContent(jsonString, Encoding.UTF8, "application/json");
            List <ActionsGetReply> responseBody = null;

            try
            {
                using (HttpResponseMessage response = await ApiClient.PostAsync(route, content).ConfigureAwait(true))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        responseBody = response.Content.ReadAsAsync <List <ActionsGetReply> >().Result;
                    }
                    else
                    {
                        var message = response.ReasonPhrase + ": " + response.Content.ReadAsStringAsync().Result;
                        content.Dispose();
                        throw new HttpRequestException(message);
                    }
                }
            }
            catch (HttpRequestException ex)
            {
                throw new HttpRequestException("", ex);
            }
            catch (Exception ex)
            {
                throw new Exception("Unhandled exception in ActionsGet", ex);
            }
            finally
            {
                if (content != null)
                {
                    content.Dispose();
                }
            }
            return(responseBody);
        }
Esempio n. 3
0
        public static async Task <bool> ActionAck(ActionAck actionack)
        {
            Uri     route   = new Uri("/api/pos/ActionAck", UriKind.Relative);
            ApiAuth ApiAuth = new ApiAuth {
                APIKey = Store.QueueGetAPIKey().value, POSCode = Utils.POSId
            };
            var jsonString = JsonConvert.SerializeObject(new { apiAuth = ApiAuth, actionAck = actionack });

            //var content = new StringContent(jsonString, Encoding.UTF8, "application/json");
            //List<ApiModel.ActionsGetReply> responseBody = null;
            using (StringContent content = new StringContent(jsonString, Encoding.UTF8, "application/json"))
                using (HttpResponseMessage response = await ApiClient.PostAsync(route, content).ConfigureAwait(true))
                {
                    if (!response.IsSuccessStatusCode)
                    {
                        var message = response.ReasonPhrase + ": " + response.Content.ReadAsStringAsync().Result;
                        throw new HttpRequestException(message);
                    }
                    //content.Dispose();
                    return(true);
                }
        }