Beispiel #1
0
        internal static MarkAsReceivedModel MarkAsReceived(IServerAuthentication restClientAuthenticator, MarkAsReceivedModel model, string controllerName)
        {
            var baseAddress        = restClientAuthenticator.GetBaseAddress();
            var authorizationToken = restClientAuthenticator.GetToken();

            var tries      = 0;
            var keepTrying = true;

            using (var restClient = new HttpClient())
            {
                restClient.BaseAddress = new Uri(baseAddress);
                restClient.DefaultRequestHeaders.Accept.Clear();
                restClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                while (keepTrying)
                {
                    restClient.DefaultRequestHeaders.Add("Authorization", authorizationToken);

                    var response = restClient.PostAsJsonAsync <MarkAsReceivedModel>(string.Format(ApiClientGenericObjectResources.PostRequestUri, controllerName), model).Result;

                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        authorizationToken = restClientAuthenticator.GetToken(true);

                        tries++;
                        keepTrying = tries < 4;
                    }
                    else
                    {
                        keepTrying = false;

                        if (response.IsSuccessStatusCode)
                        {
                            MarkAsReceivedModel MarkAsReceivedModel = response.Content.ReadAsAsync <MarkAsReceivedModel>().Result;

                            return(MarkAsReceivedModel);
                        }
                        else
                        {
                            var additionalInformation = response.Content.ReadAsStringAsync().Result;

                            throw new ApplicationException(string.Format("{0}{1}", string.Format(ApiClientGenericObjectResources.UnsuccessfulResponseMessage, HttpStatusCode.BadRequest.ToString()), additionalInformation));
                        }
                    }
                }
                throw new ApplicationException(string.Format(ApiClientGenericObjectResources.UnsuccessfulResponseMessage, HttpStatusCode.Unauthorized.ToString()));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets a list of T objects from the server.
        /// </summary>
        /// <param name="restClientAuthenticator"></param>
        /// <param name="controllerName"></param>
        /// <param name="parameterList"></param>
        /// <returns></returns>
        public static ListModel <T> Search(IServerAuthentication restClientAuthenticator, string controllerName, IUrlParameters criteria)
        {
            var baseAddress        = restClientAuthenticator.GetBaseAddress();
            var authorizationToken = restClientAuthenticator.GetToken();

            var tries      = 0;
            var keepTrying = true;

            using (var restClient = new HttpClient())
            {
                restClient.BaseAddress = new Uri(baseAddress);
                restClient.DefaultRequestHeaders.Accept.Clear();
                restClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                while (keepTrying)
                {
                    restClient.DefaultRequestHeaders.Add("Authorization", authorizationToken);

                    HttpResponseMessage response = restClient.GetAsync(string.Format(ApiClientGenericObjectResources.SearchRequestUri, controllerName, "/search?", criteria.GetAsUrlParameters())).Result;

                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        authorizationToken = restClientAuthenticator.GetToken(true);

                        tries++;
                        keepTrying = tries < 4;
                    }
                    else
                    {
                        keepTrying = false;

                        if (response.IsSuccessStatusCode)
                        {
                            ListModel <T> genericList = response.Content.ReadAsAsync <ListModel <T> >().Result;

                            return(genericList);
                        }
                        else
                        {
                            throw new ApplicationException(string.Format(ApiClientGenericObjectResources.UnsuccessfulResponseMessage, response.StatusCode.ToString()));
                        }
                    }
                }
                throw new ApplicationException(string.Format(ApiClientGenericObjectResources.UnsuccessfulResponseMessage, HttpStatusCode.Unauthorized.ToString()));
            }
        }
Beispiel #3
0
        /// Sets changed to appointment request reasons, whether it has changed or no.
        public static AppointmentRequestReasonReceivedModel MarkAsReceived(IServerAuthentication restClientAuthenticator, AppointmentRequestReasonReceivedModel model)
        {
            var baseAddress        = restClientAuthenticator.GetBaseAddress();
            var authorizationToken = restClientAuthenticator.GetToken();

            var tries      = 0;
            var keepTrying = true;

            using (var restClient = new HttpClient())
            {
                restClient.BaseAddress = new Uri(baseAddress);
                restClient.DefaultRequestHeaders.Accept.Clear();
                restClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                while (keepTrying)
                {
                    restClient.DefaultRequestHeaders.Add("Authorization", authorizationToken);
                    try
                    {
                        var response = restClient.PostAsJsonAsync(string.Format(ApiClientGenericObjectResources.PostRequestUri, controllerName), model).Result;

                        if (response.StatusCode == HttpStatusCode.Unauthorized)
                        {
                            authorizationToken = restClientAuthenticator.GetToken(true);

                            tries++;
                            keepTrying = tries < 4;
                        }
                        else
                        {
                            keepTrying = false;

                            var additionalInformation = response.Content.ReadAsStringAsync().Result;
                            model = JsonConvert.DeserializeObject <AppointmentRequestReasonReceivedModel>(additionalInformation);

                            return(model);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException(ex.GetBaseException().Message);
                    }
                }
                throw new ApplicationException(string.Format(ApiClientGenericObjectResources.UnsuccessfulResponseMessage, HttpStatusCode.Unauthorized.ToString()));
            }
        }
Beispiel #4
0
        public static AccountSettingsModel Get(IServerAuthentication restClientAuthenticator)
        {
            var baseAddress        = restClientAuthenticator.GetBaseAddress();
            var authorizationToken = restClientAuthenticator.GetToken();

            var tries      = 0;
            var keepTrying = true;

            using (var restClient = new HttpClient())
            {
                restClient.BaseAddress = new Uri(baseAddress);
                restClient.DefaultRequestHeaders.Accept.Clear();
                restClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                while (keepTrying)
                {
                    restClient.DefaultRequestHeaders.Add("Authorization", authorizationToken);

                    HttpResponseMessage response = restClient.GetAsync(string.Format("api/{0}", ControllerName)).Result;

                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        authorizationToken = restClientAuthenticator.GetToken(true);

                        tries++;
                        keepTrying = tries < 4;
                    }
                    else
                    {
                        keepTrying = false;

                        if (response.IsSuccessStatusCode)
                        {
                            AccountSettingsModel accountSettingsModel = response.Content.ReadAsAsync <AccountSettingsModel>().Result;

                            return(accountSettingsModel);
                        }
                        else
                        {
                            throw new HttpRequestException(string.Format(ApiClientGenericObjectResources.UnsuccessfulResponseMessage, response.StatusCode.ToString()));
                        }
                    }
                }
                throw new HttpRequestException(string.Format(ApiClientGenericObjectResources.UnsuccessfulResponseMessage, HttpStatusCode.Unauthorized.ToString()));
            }
        }
Beispiel #5
0
        /// <summary>
        /// Gets a T object from the server.
        /// </summary>
        /// <param name="restClientAuthenticator"></param>
        /// <param name="controllerName"></param>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static T Get(IServerAuthentication restClientAuthenticator, string controllerName, string ID, string externalIdParameterName = "externalId")
        {
            if (string.IsNullOrWhiteSpace(ID))
            {
                var additionalInformation = string.Format(ApiClientGenericObjectResources.AdditionalInformation, ApiClientGenericObjectResources.IdNotNullable);
                throw new ApplicationException(string.Format("{0}{1}", string.Format(ApiClientGenericObjectResources.UnsuccessfulResponseMessage, HttpStatusCode.BadRequest.ToString()), additionalInformation));
            }

            var baseAddress        = restClientAuthenticator.GetBaseAddress();
            var authorizationToken = restClientAuthenticator.GetToken();

            var tries      = 0;
            var keepTrying = true;

            using (var restClient = new HttpClient())
            {
                restClient.BaseAddress = new Uri(baseAddress);
                restClient.DefaultRequestHeaders.Accept.Clear();
                restClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                while (keepTrying)
                {
                    restClient.DefaultRequestHeaders.Add("Authorization", authorizationToken);

                    HttpResponseMessage response = restClient.GetAsync
                                                       (string.Format(
                                                           ApiClientGenericObjectResources.GetRequestUri,
                                                           controllerName,
                                                           "?",
                                                           externalIdParameterName,
                                                           "=",
                                                           ID
                                                           )
                                                       ).Result;

                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        authorizationToken = restClientAuthenticator.GetToken(true);

                        tries++;
                        keepTrying = tries < 4;
                    }
                    else
                    {
                        keepTrying = false;

                        if (response.IsSuccessStatusCode)
                        {
                            T genericObject = response.Content.ReadAsAsync <T>().Result;

                            return(genericObject);
                        }
                        else
                        {
                            throw new ApplicationException(string.Format(ApiClientGenericObjectResources.UnsuccessfulResponseMessage, response.StatusCode.ToString()));
                        }
                    }
                }
                throw new ApplicationException(string.Format(ApiClientGenericObjectResources.UnsuccessfulResponseMessage, HttpStatusCode.Unauthorized.ToString()));
            }
        }
Beispiel #6
0
        public static ListModel <FormModel> Search(
            IServerAuthentication restClientAuthenticator,
            string formStatus            = "",
            string creationDateOperator  = "",
            DateTime?utcCreationDate1    = null,
            DateTime?utcCreationDate2    = null,
            string completedDateOperator = "",
            DateTime?utcCompletedDate1   = null,
            DateTime?utcCompletedDate2   = null,
            string closedDateOperator    = "",
            DateTime?utcClosedDate1      = null,
            DateTime?utcClosedDate2      = null,
            string patientFirstName      = "",
            string patientLastName       = "",
            bool?FormLayoutActive        = null,
            string patientExternalId     = "",
            int page              = 1,
            int itemsPerPage      = 10,
            bool onlyProfileForms = false)
        {
            var criteria = new SearchCriteria();

            criteria.Add("formStatus", formStatus);
            criteria.Add("creationDateOperator", creationDateOperator);
            criteria.Add("utcCreationDate1", utcCreationDate1.ToString());
            criteria.Add("utcCreationDate2", utcCreationDate2.ToString());
            criteria.Add("completedDateOperator", completedDateOperator);
            criteria.Add("utcCompletedDate1", utcCompletedDate1.ToString());
            criteria.Add("utcCompletedDate2", utcCompletedDate2.ToString());
            criteria.Add("dateClosedOperator", closedDateOperator);
            criteria.Add("utcClosedDate1", utcClosedDate1.ToString());
            criteria.Add("utcClosedDate2", utcClosedDate2.ToString());
            criteria.Add("patientFirstName", patientFirstName);
            criteria.Add("patientLastName", patientLastName);
            criteria.Add("FormLayoutActive", FormLayoutActive.ToString());
            criteria.Add("page", page.ToString());
            criteria.Add("itemsPerPage", itemsPerPage.ToString());
            criteria.Add("patientExternalId", patientExternalId);
            criteria.Add("onlyProfileForms", onlyProfileForms.ToString());

            var baseAddress        = restClientAuthenticator.GetBaseAddress();
            var authorizationToken = restClientAuthenticator.GetToken();

            var tries      = 0;
            var keepTrying = true;

            using (var restClient = new HttpClient())
            {
                restClient.BaseAddress = new Uri(baseAddress);
                restClient.DefaultRequestHeaders.Accept.Clear();
                restClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                while (keepTrying)
                {
                    restClient.DefaultRequestHeaders.Add("Authorization", authorizationToken);
                    HttpResponseMessage response = restClient.GetAsync(string.Format(ApiClientGenericObjectResources.SearchRequestUri, controllerName, "/search?", criteria.GetAsUrlParameters())).Result;

                    if (response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        authorizationToken = restClientAuthenticator.GetToken(true);

                        tries++;
                        keepTrying = tries < 4;
                    }
                    else
                    {
                        keepTrying = false;

                        if (response.IsSuccessStatusCode)
                        {
                            ListModel <FormModel> formModelList = response.Content.ReadAsAsync <ListModel <FormModel> >().Result;

                            return(formModelList);
                        }
                        else
                        {
                            throw new HttpRequestException(string.Format(ApiClientGenericObjectResources.UnsuccessfulResponseMessage, response.StatusCode.ToString()));
                        }
                    }
                }
                throw new HttpRequestException(string.Format(ApiClientGenericObjectResources.UnsuccessfulResponseMessage, HttpStatusCode.Unauthorized.ToString()));
            }
        }