Exemplo n.º 1
0
        private async Task <Check> PerformCheck(int environmentId, Check check, CityRequest requestModel)
        {
            check.State.Status = StatusesEnum.CRITICAL;

            var address = new EnvironmentHelper().GetApiUrl(environmentId);
            var query   = $"{address}/api/delivery/settlements";

            //var requestModel = new CityRequest
            //{
            //    AreaId = 57,
            //    DeliveryMethodKey = 3,
            //    DistrictId = 0,
            //    LanguageId = 2,
            //    SearchString = "хар"
            //};

            var response = _httpService.PerformPostRequest(query, timeOut, requestModel);

            var result = response.Result;

            if (!result.IsSuccessStatusCode)
            {
                check.State.Description = "Полученный статус-код для населенных пунктов: " + result.StatusCode;
                return(check);
            }

            try
            {
                var responseContent = await result.Content.ReadAsStringAsync();

                var settlementsResponseModel = JsonConvert.DeserializeObject <ApiResponse <List <SettlementModel> > >(responseContent);

                if (!settlementsResponseModel.Success)
                {
                    var errorsStr = string.Join(".", settlementsResponseModel.Errors);
                    check.State.Description = "Ошибка получения населенных пунктов: " + errorsStr;
                    return(check);
                }

                if (settlementsResponseModel?.Data?.Count == 0)
                {
                    check.State.Description = "Получен пустой список населенных пунктов";
                    return(check);
                }
            }
            catch (Exception e)
            {
                check.State.Description = "Исключение во время получения населенных пунктов: " + e.Message;
            }

            check.State.Status      = StatusesEnum.OK;
            check.State.Description = "Проблем не обнаружено";

            return(check);
        }
Exemplo n.º 2
0
        private async Task <Check> PerformCheck(int environmentId, Check check, DeliveryPointsRequest requestModel)
        {
            check.State.Status = StatusesEnum.CRITICAL;

            var address = new EnvironmentHelper().GetApiUrl(environmentId);
            var query   = $"{address}/api/delivery/points";

            var response = _httpService.PerformPostRequest(query, timeOut, requestModel);

            var result = response.Result;

            if (!result.IsSuccessStatusCode)
            {
                check.State.Description = "Полученный статус-код для точек выдачи: " + result.StatusCode;
                return(check);
            }

            try
            {
                var responseContent = await result.Content.ReadAsStringAsync();

                var settlementsResponseModel = JsonConvert.DeserializeObject <ApiResponse <List <DeliveryPointModel> > >(responseContent);

                if (!settlementsResponseModel.Success)
                {
                    var errorsStr = string.Join(".", settlementsResponseModel.Errors);
                    check.State.Description = "Ошибка получения точек выдачи: " + errorsStr;
                    return(check);
                }

                if (settlementsResponseModel?.Data?.Count == 0)
                {
                    check.State.Description = "Получен пустой список точек выдачи";
                    return(check);
                }
            }
            catch (Exception e)
            {
                check.State.Description = "Исключение во время получения точек выдачи: " + e.Message;
            }

            check.State.Status      = StatusesEnum.OK;
            check.State.Description = "Проблем не обнаружено";

            return(check);
        }