Esempio n. 1
0
        public TestContext(ITestConfiguration configuration, IOktaSdkHelper oktaHelper)
        {
            _oktaHelper    = oktaHelper;
            _configuration = configuration;

            TestUserProfile = new TestUserProfile();
        }
        public async Task <IActionResult> Post([FromBody] dynamic data)
        {
            try
            {
                TestUserProfile profileToReturn = await _profileRepository.GetProfileByEmailAsync(data.email);

                return(Ok(profileToReturn));
            }
            catch
            {
                try
                {
                    TestUserProfile userProfileToAdd = new TestUserProfile();
                    userProfileToAdd.Name         = data.name;
                    userProfileToAdd.UserEmail    = data.email;
                    userProfileToAdd.UserPassword = data.password;
                    await _profileRepository.AddAsync(userProfileToAdd);

                    TestUserProfile profileToReturn = await _profileRepository.GetProfileByEmailAsync(userProfileToAdd.UserEmail);

                    await _rankingRepository.CreateListOfPlayerRanksByProfileId(profileToReturn.TestUserProfileId, _playerRepository, _rankingRepository);

                    return(Ok(profileToReturn));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(null);
                }
            }
        }
Esempio n. 3
0
        public static Person GeneratePersonSchema(TestUserProfile userProfile)
        {
            string region;

            switch (userProfile.Hometown)
            {
            case "Perlis":
            case "Kedah":
            case "Penang":
            case "Perak":
                region = "Northern Region";
                break;

            case "Kuala Lumpur":
            case "Selangor":
            case "Negeri Sembilan":
            case "Putrajaya":
                region = "Central Region";
                break;

            case "Melaka":
            case "Johor":
                region = "Southern Region";
                break;

            case "Pahang":
            case "Kelantan":
            case "Terengganu":
                region = "East Coast";
                break;

            case "Labuan":
            case "Sabah":
            case "Sarawak":
                region = "East Malaysia";
                break;

            default:
                region = "Unknown";
                break;
            }

            var request     = HttpContext.Current.Request;
            var userPageURL = string.Format("{0}://{1}/User?id={2}", request.Url.Scheme, request.Url.Authority, userProfile.Id);

            return(new Person()
            {
                Name = userProfile.Name,
                Address = new PostalAddress()
                {
                    AddressCountry = "Malaysia",
                    AddressLocality = userProfile.Hometown,
                    AddressRegion = region
                },
                BirthDate = DateTimeOffset.ParseExact(userProfile.BirthdayMYFormat, "dd/MM/yyyy", new CultureInfo("en-MY")),
                Url = new Uri(userPageURL)
            });
        }
Esempio n. 4
0
        /// <summary>
        /// Load the user profiles accociated with the given array of user IDs.
        /// </summary>
        /// <param name="userIDs">The users to retrieve profiles for.</param>
        /// <param name="callback">Callback to handle the user profiles.</param>
        public override void LoadUsers(string[] userIDs, Action <IUserProfile[]> callback)
        {
            var profiles = new IUserProfile[userIDs.Length];

            for (var i = 0; i < profiles.Length; i++)
            {
                profiles[i] = new TestUserProfile();
            }

            CloudOnceUtils.SafeInvoke(callback, profiles);
        }
        public async Task <IActionResult> Get(string requestedProfileEmail)
        {
            try
            {
                TestUserProfile profileToReturn = await _profileRepository.GetProfileByEmailAsync(requestedProfileEmail);

                return(Ok(profileToReturn));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Email Not Found");
                return(null);
            }
        }
        public async Task <IActionResult> Delete(int id, TestUserProfile deletedProfile, IFormCollection collection)
        {
            try
            {
                var profileToDelete = await _profileRepository.GetByIdAsync(id);

                await _profileRepository.DeleteAsync(profileToDelete);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                var notDeletedPlayer = await _profileRepository.GetByIdAsync(id);

                return(View(notDeletedPlayer));
            }
        }
        public async Task <IActionResult> Edit(int id, TestUserProfile editedProfile, IFormCollection collection)
        {
            if (!ModelState.IsValid)
            {
                return(View(editedProfile));
            }
            try
            {
                await _profileRepository.UpdateAsync(editedProfile);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                //todo log exception
            }
            return(View(editedProfile));
        }
Esempio n. 8
0
        public async Task SetActivePasswordUserAsync()
        {
            // create user dynamically +Guid
            var guid      = Guid.NewGuid();
            var username  = $"mary-embedded-siw-{guid}@example.com";
            var firstName = $"Mary";
            var password  = "******";


            var oktaUser = await _oktaHelper.CreateActiveUser(username, firstName, password);

            TestUserProfile = new TestUserProfile()
            {
                FirstName = firstName,
                LastName  = "Lastname",
                Email     = oktaUser.Profile.Email,
                Password  = password
            };
        }
        public async Task <IActionResult> Create(TestUserProfile newProfile, IFormCollection collection)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(newProfile));
                }

                await _profileRepository.AddAsync(newProfile);


                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                //todo log exception
            }
            return(View(newProfile));
        }
Esempio n. 10
0
        public ActionResult GetChartData()
        {
            DateTime      today        = DateTime.Today;
            JsonReturnObj jsonReturn   = new JsonReturnObj();
            List <string> hometownList = new List <string>()
            {
                //"Johor",
                //"Kedah",
                //"Kelantan",
                "Kuala Lumpur",
                "Labuan",
                //"Melaka",
                //"Negeri Sembilan",
                //"Pahang",
                //"Penang",
                //"Perak",
                //"Perlis",
                "Putrajaya",
                "Sabah",
                "Sarawak",
                //"Selangor",
                //"Terengganu"
            };

            try
            {
                //Get App Token
                string     appTokenURL  = $"https://graph.facebook.com/oauth/access_token?client_id={APP_ID}&client_secret={APP_SECRET}&grant_type=client_credentials";
                FBAppToken appTokenObj  = JsonConvert.DeserializeObject <FBAppToken>(WebRequestHelper.Get(appTokenURL));
                string     access_token = appTokenObj.AccessToken;

                //Get list of test users
                string testUserURL         = $"https://graph.facebook.com/v3.2/{APP_ID}/accounts/test-users?access_token={access_token}";
                string testUsersJson       = WebRequestHelper.Get(testUserURL);
                TestUserQueryResult result = JsonConvert.DeserializeObject <TestUserQueryResult>(testUsersJson);
                if (result.Error != null)
                {
                    throw new Exception(result.Error);
                }

                //Get list of test users profile
                Random rnd = new Random();
                List <TestUserProfile> userProfileList = new List <TestUserProfile>();
                foreach (TestUser user in result.TestUserList)
                {
                    string          profileURL  = $"https://graph.facebook.com/v3.2/{user.Id}/?fields=id,name,birthday,gender,hometown&access_token={user.AccessToken}";
                    TestUserProfile userProfile = JsonConvert.DeserializeObject <TestUserProfile>(WebRequestHelper.Get(profileURL));

                    char[] genderCharArray = userProfile.Gender.ToCharArray();
                    genderCharArray[0] = char.ToUpper(genderCharArray[0]);
                    userProfile.Gender = new string(genderCharArray);

                    DateTime birthday = DateTime.ParseExact(userProfile.Birthday, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                    userProfile.BirthdayMYFormat = birthday.ToString("dd/MM/yyyy");
                    userProfile.Hometown         = hometownList[rnd.Next(hometownList.Count)];
                    userProfileList.Add(userProfile);
                }

                //Populate JSON data for barchart
                BarChartData   barChartData   = GetBarChartDataFromUserProfileList(userProfileList, today);
                RadarChartData radarChartData = GetRadarChartDataFromUserProfileList(userProfileList, hometownList);

                jsonReturn.BarChartData   = barChartData;
                jsonReturn.RadarChartData = radarChartData;

                jsonReturn.IsSuccess = true;
            }
            catch (Exception ex)
            {
                jsonReturn.IsSuccess = false;
                jsonReturn.ErrorMsg  = ex.Message;
            }
            return(Json(jsonReturn, "application/json"));
        }