Пример #1
0
        public void Add(RegistrationRequest registrationRequest)
        {
            var client  = applicationRestClient.CreateRestClient();
            var request = new RestRequest("/api/RegistrationRequest/AddRegistrationRequest", Method.POST);

            request.AddParameter("application/json; charset=utf-8", JsonConvert.SerializeObject(registrationRequest), ParameterType.RequestBody);

            var response = client.Post(request);

            if (response.ErrorException != null || response.IsSuccessful == false)
            {
                string message   = Constants.UNHANDLED_EXCEPTION_MESSAGE;
                var    exception = new ApplicationException(message, response.ErrorException);
                throw exception;
            }
        }
Пример #2
0
        public string CreateToken(string username, string password)
        {
            var client  = applicationRestClient.CreateRestClient(false);
            var request = new RestRequest("/api/Token/Create", Method.POST);

            request.AddParameter("username", username, ParameterType.QueryString);
            request.AddParameter("password", password, ParameterType.QueryString);

            var response = client.Post(request);

            if (response.ErrorException != null || response.IsSuccessful == false)
            {
                StringBuilder headers = new StringBuilder();
                if (response.Headers != null)
                {
                    foreach (var h in response.Headers)
                    {
                        headers.AppendLine(string.Concat(h.Name, " , ", h.Value, " , ", h.ContentType));
                    }
                }

                string statusCode = string.Format("StatusCode:{0} | Description:{1}", response.StatusCode, response.StatusDescription);
                ApplicationException exception;;
                if (logger != null)
                {
                    logger.LogError(response.ErrorException, response.ErrorMessage ?? response.ErrorException?.Message ?? statusCode);
                    logger.LogWarning(headers.ToString());
                    logger.LogWarning(statusCode);
                    exception = new ApplicationException();
                }
                else
                {
                    exception = new ApplicationException(response.ErrorMessage ?? response.ErrorException?.Message ?? statusCode, response.ErrorException);
                }

                throw exception;
            }

            return(response.Content);
        }