Пример #1
0
        private async Task <JArray> GetStatisticsAllStaffsByRangeAsync(DateTime fromDate, DateTime toDate)
        {
            string url = string.Format("/api/stats_lb_staff.json?" +
                                       "from_time={0}&" +
                                       "to_time={1}",
                                       HelperDate.RequestDateFromDate(fromDate),
                                       HelperDate.RequestDateFromDate(toDate));
            JArray json = null;

            using (var client = new HttpClient()
            {
                BaseAddress = _baseAddress
            })
            {
                client.DefaultRequestHeaders.Authorization = GetAuthHeader();
                var result = await client.GetAsync(url);

                var bytes = await result.Content.ReadAsByteArrayAsync();

                Encoding encoding = Encoding.GetEncoding("utf-8");
                string   data     = encoding.GetString(bytes, 0, bytes.Length);
                json = JArray.Parse(data);
                result.EnsureSuccessStatusCode();
            }

            return(json);
        }
Пример #2
0
        public void TestTimestampFromDateTime()
        {
            long expected = 1559553396;
            long actual   = HelperDate.TimestampFromDateTime(new DateTime(2019, 6, 3, 9, 16, 36));

            Assert.AreEqual(expected, actual);
        }
Пример #3
0
        private async Task <JObject> GetCasesForRangeAsycn(int staffId, DateTime fromDate, DateTime toDate, int page = 1, int limit = 100)
        {
            string url = string.Format("/api/cases.json?" +
                                       "page={0}&" +
                                       "limit={1}&" +
                                       "staff_id={2}&" +
                                       "from_time={3}&" +
                                       "to_time={4}",
                                       page,
                                       limit,
                                       staffId,
                                       HelperDate.TimestampFromDateTime(fromDate),
                                       HelperDate.TimestampFromDateTime(toDate));
            JObject json = null;

            using (var client = new HttpClient()
            {
                BaseAddress = _baseAddress
            })
            {
                client.DefaultRequestHeaders.Authorization = GetAuthHeader();
                var result = await client.GetAsync(url);

                var bytes = await result.Content.ReadAsByteArrayAsync();

                json = BytesToJson(bytes);
                result.EnsureSuccessStatusCode();
            }

            return(json);
        }
Пример #4
0
        public void TestRequestDateFromDate()
        {
            string expected = "01+May+2019+00%3A00%3A00+%2B0400";
            string actual   = string.Empty;

            actual = HelperDate.RequestDateFromDate(new DateTime(2019, 5, 1));

            Console.WriteLine(actual);

            Assert.AreEqual(expected, actual);
        }