Beispiel #1
0
        public async Task <IActionResult> ProfilesAsync(string profileId)
        {
            if (manager == null)
            {
                manager = new SdsManager(await GetAccessTokenAsync());
            }

            var manageError = TempData["manageProfileError"];

            if (manageError != null)
            {
                ViewBag.manageProfileError = manageError;
            }

            ViewBag.profileId = profileId;

            var profileRequest = string.IsNullOrWhiteSpace(profileId) ?
                                 await manager.QueryAllProfilesAsync() :
                                 await manager.QueryProfileAsync(profileId);

            var profile = await profileRequest.Content.ReadAsStringAsync();

            var profileDes = JsonConvert.DeserializeObject(profile);
            var profileSer = JsonConvert.SerializeObject(profileDes, Formatting.Indented);

            ViewBag.profile = profileSer;

            if (!string.IsNullOrWhiteSpace(profileId))
            {
                var profileStatusRequest = await manager.QueryProfileStatusAsync(profileId);

                var profileStatus = await profileStatusRequest.Content.ReadAsStringAsync();

                var profileStatusDes = JsonConvert.DeserializeObject(profileStatus);
                var profileStatusSer = JsonConvert.SerializeObject(profileStatusDes, Formatting.Indented);
                ViewBag.profileStatus = profileStatusSer;
            }
            else
            {
                ViewBag.profileStatus = string.Empty;
            }

            return(View("Profiles"));
        }
Beispiel #2
0
        private async Task <JObject> GetProfileAsync(string profileType)
        {
            // find existing matching profile
            var profileName         = $"OneRoster{profileType.ToUpper()}Profile";
            HttpResponseMessage res = await manager.QueryAllProfilesAsync();

            var profiles = (JArray)JObject.Parse(await res.Content.ReadAsStringAsync())["value"];

            foreach (var profile in profiles)
            {
                if ((string)profile["displayName"] == profileName)
                {
                    return((JObject)profile);
                }
            }

            // create new profile
            var generatedProfile = await GenerateProfileAsync(profileType);

            HttpResponseMessage res2 = await manager.PostProfileAsync(generatedProfile);

            return(JObject.Parse(await res2.Content.ReadAsStringAsync()));
        }