Exemplo n.º 1
0
        public static async Task <Person> GetPerson(int personId)
        {
            RockApi rapi = new RockApi();

            rapi.CleanUpClient();

            if (App.IsUserLoggedIn)
            {
                rapi = new RockApi();
                if (rapi.Client == null)
                {
                    rapi.Client = rapi.CreateClient();
                }
            }

            var client = rapi.Client;

            var person   = new Person();
            var response = await client.GetAsync(string.Format("People/{0}", personId));

            using (HttpContent content = response.Content)
            {
                var result   = content.ReadAsStringAsync();
                var settings = new JsonSerializerSettings
                {
                    NullValueHandling     = NullValueHandling.Ignore,
                    MissingMemberHandling = MissingMemberHandling.Ignore
                };

                person = JsonConvert.DeserializeObject <Person>(await result, settings);
            }

            return(person);
        }
Exemplo n.º 2
0
        public static async Task <List <Person> > GetAllDirectory()
        {
            RockApi rapi = new RockApi();

            rapi.CleanUpClient();

            if (App.IsUserLoggedIn)
            {
                rapi = new RockApi();
                if (rapi.Client == null)
                {
                    rapi.Client = rapi.CreateClient();
                }
            }

            var querystring = "People/DataView/8";

            var response = rapi.Client.GetAsync(querystring).Result;

            var settings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore
            };

            var reader = await response.Content.ReadAsStringAsync();

            var jsonResult = JsonConvert.DeserializeObject <List <Person> >(reader, settings);

            return(jsonResult);
        }
Exemplo n.º 3
0
        public static async Task <Family> GetFamily(int familyId)
        {
            RockApi rapi = new RockApi();

            rapi.CleanUpClient();

            if (App.IsUserLoggedIn)
            {
                rapi = new RockApi();
                if (rapi.Client == null)
                {
                    rapi.Client = rapi.CreateClient();
                }
            }

            var querystring = string.Format("Groups/GetFamily/{0}", familyId.ToString());

            var response = rapi.Client.GetAsync(querystring).Result;

            var settings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore
            };

            var reader = await response.Content.ReadAsStringAsync();

            var jsonResult = JsonConvert.DeserializeObject <Family>(reader, settings);

            return(jsonResult);
        }
Exemplo n.º 4
0
        public static async Task <Person> GetFromContext(int personId)
        {
            RockApi rapi = new RockApi();

            rapi.CleanUpClient();

            if (App.IsUserLoggedIn)
            {
                rapi = new RockApi();
                if (rapi.Client == null)
                {
                    rapi.Client = rapi.CreateClient();
                }
            }

            var client = rapi.Client;

            var person = new Person();

            var httpRequestMessage = new HttpRequestMessage(HttpMethod.Options, string.Format("People/SetContext/{0}", personId));

            var response = await client.SendAsync(httpRequestMessage);

            var responseCookies = rapi.Cookies.GetCookies(rapi.baseAddress).Cast <Cookie>();


            var personResponse = await client.GetAsync("People/GetCurrentPerson");

            using (var content = personResponse.Content)
            {
                var result   = content.ReadAsStringAsync();
                var settings = new JsonSerializerSettings
                {
                    NullValueHandling     = NullValueHandling.Ignore,
                    MissingMemberHandling = MissingMemberHandling.Ignore
                };

                person = JsonConvert.DeserializeObject <Person>(await result, settings);
            }

            rapi.CleanUpClient();
            rapi = new RockApi();

            return(person);
        }