Пример #1
0
        public virtual async Task <OfmQueryResult <TOfmForGet> > Delete(TId id)
        {
            var ofmQueryResult = new OfmQueryResult <TOfmForGet>();
            var uri            = new Uri(
                AppConfiguration.GetValue <string>("FittifyApiBaseUrl")
                + AppConfiguration.GetValue <string>("MappedFittifyApiActions:" + MappedControllerActionKey)
                + "/" + id
                );
            var httpResponse = await HttpRequestExecuter.Delete(uri, AppConfiguration, HttpContextAccessor);

            //var contentString = httpResponse.Content.ReadAsStringAsync();
            ofmQueryResult.HttpStatusCode      = httpResponse.StatusCode;
            ofmQueryResult.HttpResponseHeaders = httpResponse.Headers.ToList();

            if (!Regex.Match(((int)ofmQueryResult.HttpStatusCode).ToString(), FittifyRegularExpressions.HttpStatusCodeStartsWith2).Success)
            {
                ofmQueryResult.ErrorMessagesPresented = httpResponse.ContentAsType <IReadOnlyDictionary <string, object> >();
            }
            return(ofmQueryResult);
        }
Пример #2
0
        public virtual async Task <OfmQueryResult <TOfmForGet> > GetSingle <TGetResourceParameters>(TId id, TGetResourceParameters resourceParameters) where TGetResourceParameters : class
        {
            var ofmQueryResult = new OfmQueryResult <TOfmForGet>();

            var uri = new Uri(
                AppConfiguration.GetValue <string>("FittifyApiBaseUrl")
                + AppConfiguration.GetValue <string>("MappedFittifyApiActions:" + MappedControllerActionKey)
                + "/" + id + resourceParameters.ToQueryParameterString()
                );
            var httpResponse = await HttpRequestExecuter.GetSingle(uri, AppConfiguration, HttpContextAccessor);

            var contentAsString = await httpResponse.Content.ReadAsStringAsync();

            ofmQueryResult.HttpStatusCode      = httpResponse.StatusCode;
            ofmQueryResult.HttpResponseHeaders = httpResponse.Headers.ToList();

            if (!Regex.Match(((int)ofmQueryResult.HttpStatusCode).ToString(), FittifyRegularExpressions.HttpStatusCodeStartsWith2).Success)
            {
                try
                {
                    ofmQueryResult.ErrorMessagesPresented =
                        httpResponse.ContentAsType <IReadOnlyDictionary <string, object> >();
                }
                catch (Exception ex)
                {
                    ofmQueryResult.ErrorMessagesPresented = new Dictionary <string, object>()
                    {
                        { "Exception", contentAsString }
                    };
                    //throw;
                }
            }
            else
            {
                ofmQueryResult.OfmForGet = httpResponse.ContentAsType <TOfmForGet>();
            }
            return(ofmQueryResult);
        }