예제 #1
0
    public void FaceBookLogin()
    {
        GetMethods.GetUserId(email, (id) => {
            if (id != "0")             // The user exits in the data base

            // Verify if an Update is necessary.
            {
                UpdateMethods.UpdateUsersDatabase(id, userName, age, AppManeger.instance.userGender.ToString(), (result) => {
                    Debug.Log(string.Format("Update {0}", result));
                });

                string fileName = string.Format("Prefs_{0}", AppManeger.instance.userID);

                //GetMethods.GetUserPrefs(id, (prefsResult) => {PrefsResult(prefsResult);}); // Check if the user are in the Prefs Database

                if (SaveLoadData.FileExits(fileName))                 // If exit

                {
                    SaveLoadData.Load(fileName, SaveLoadData.DataType.UserPrefs); // load from device
                    GoToCheersPanel();                                            // Means the user has everyting setted;
                }
                else
                {
                    GetMethods.GetUserPrefs(id, (prefsResult) => { PrefsResult(prefsResult); });                   // Check if the user are in the Prefs Database
                }
            }
            else                // User don't exit in the data base

            {
                PostMethods.InsertUserIntoUsersDatabase(userName, age, email, gender, (result) => {
                    InsertUserResult(result);
                });
            }
        });
    }
        /// <summary>
        /// Test code for the class
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            int       pairNumber = 4;
            ColorPair testPair1  = new ColorPair(pairNumber);

            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Test.TestByColorCode(testPair1, Color.White, Color.Brown);

            pairNumber = 5;
            testPair1.changeByNumber(pairNumber);
            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Test.TestByColorCode(testPair1, Color.White, Color.SlateGray);

            pairNumber = 23;
            testPair1.changeByNumber(pairNumber);
            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Test.TestByColorCode(testPair1, Color.Violet, Color.Green);

            ColorPair testPair2 = new ColorPair(Color.Yellow, Color.Green);

            pairNumber = GetMethods.GetPairNumberFromColor(testPair2);
            Console.WriteLine("[In]Colors: {0}, [Out] PairNumber: {1}\n", testPair2, pairNumber);
            Test.TestByPairNumber(testPair2, 18);

            testPair2.changeByColor(Color.Red, Color.Blue);
            pairNumber = GetMethods.GetPairNumberFromColor(testPair2);
            Console.WriteLine("[In]Colors: {0}, [Out] PairNumber: {1}\n", testPair2, pairNumber);
            Test.TestByPairNumber(testPair2, 6);

            string manual = ColorCodeData.manualToString();

            Console.WriteLine(manual);
        }
예제 #3
0
        public ActionResult CreateUser(string name, string surname, string email, string password, string username,
                                       int roleId)
        {
            var isAdmin = CheckMethods.IsCurrentUserAdmin(User.Identity.Name);

            if (User.Identity.IsAuthenticated && isAdmin)
            {
                using (var db = new BlogDbContext())
                {
                    var user = new User();
                    user.Name     = name;
                    user.Surname  = surname;
                    user.Email    = email;
                    user.Username = username;
                    user.Password = GetMethods.GetHash(password);
                    user.RoleId   = roleId;
                    db.Users.Add(user);
                    db.SaveChanges();

                    return(View("~/Views/Admin/AdminMain.cshtml"));
                }
            }

            return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
        }
예제 #4
0
        public ActionResult UpdateUser(int userId, string name, string surname, string email, string password,
                                       string username, int roleId, bool isDeleted = false)
        {
            using (var db = new BlogDbContext())
            {
                var user = db.Users.FirstOrDefault(u => u.UserId == userId);
                if (user != null)
                {
                    user.Name     = name;
                    user.Surname  = surname;
                    user.Email    = email;
                    user.Username = username;
                    user.RoleId   = roleId;
                    if (!string.IsNullOrEmpty(password))
                    {
                        user.Password = GetMethods.GetHash(password);
                    }

                    user.IsDeleted = Convert.ToBoolean(isDeleted);
                    if (!isDeleted)
                    {
                        var posts = db.Posts.Where(p => p.UserId == userId).ToList();
                        RestoreUserPosts(posts);
                    }
                }

                db.SaveChanges();

                return(View("~/Views/Admin/AdminMain.cshtml"));
            }
        }
예제 #5
0
        internal ColorPair(int number)
        {
            ColorPair temp = GetMethods.GetColorFromPairNumber(number);

            this.majorColor = temp.majorColor;
            this.minorColor = temp.minorColor;
        }
예제 #6
0
        internal void changeByNumber(int pairNumber)
        {
            ColorPair temp = GetMethods.GetColorFromPairNumber(pairNumber);

            this.majorColor = temp.majorColor;
            this.minorColor = temp.minorColor;
        }
예제 #7
0
        internal static void TestByPairNumber(ColorPair pair, int actual_number)
        {
            int pairNumber_calulated;

            pairNumber_calulated = GetMethods.GetPairNumberFromColor(pair);
            Debug.Assert(pairNumber_calulated == actual_number);
        }
예제 #8
0
        public JsonResult PostUserCreatePost(string title, string content)
        {
            var user     = ActionContext.Request.Headers.Authorization.Parameter;
            var userInfo = GetMethods.GetUserInformationByBase64(user);
            var res      = CreateNewPost(userInfo.UserId, title, content);

            if (res == 1)
            {
                return new JsonResult
                       {
                           Data = new{ status = "successful" }
                       }
            }
            ;

            var err = ErrorMethods.Handle500();

            JsonConvert.SerializeObject(err);
            return(new JsonResult
            {
                Data = err,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,

                ContentType = "application/json"
            });
        }
예제 #9
0
        public JsonResult GetPost(int id)
        {
            var post = GetMethods.GetPost(id);

            if (post == null)
            {
                var err = ErrorMethods.Handle404();
                JsonConvert.SerializeObject(err);
                return(new JsonResult
                {
                    Data = err,
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,

                    ContentType = "application/json"
                });
            }

            var jsonResult = new JsonResult
            {
                Data = post,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,

                ContentType = "application/json"
            };

            return(jsonResult);
        }
예제 #10
0
        public void NavigateToLogin()
        {
            //string url = ConfigurationManager.AppSettings["devURL"];
            string url = GetMethods.getEnvironment();

            PropertiesCollection.Driver.Navigate().GoToUrl(url);
        }
예제 #11
0
        public bool VerifyDetails()
        {
            SetMethods.ClickElement(By.Id("citizen-contact-details"), BrowserContext);
            var contactEmailHint     = GetMethods.IsElementDisplayed(By.Id("contact-us-email-times-hint"), BrowserContext);
            var contactTelephoneHint = GetMethods.IsElementDisplayed(By.Id("contact-us-telephone-times-hint"), BrowserContext);
            var isElementDisplayed   = contactEmailHint && contactTelephoneHint;

            return(isElementDisplayed);
        }
예제 #12
0
    void SelectUsers()
    {
        usersListOfDic = new List <Dictionary <string, string> >();

        GetMethods.GetUsersByFilter(AppManeger.instance.wantToMeet, AppManeger.instance.wantAge, AppManeger.instance.userID,
                                    (listResults) => {
            if (listResults[0].ContainsKey("Error"))
            {
                Debug.Log(listResults[0]["Error"]);

                isUsersNotOver = false;
                // === Clean info Panel===
                nameText.text = "Nome";
                ageText.text  = "";
                //=========================
            }
            else
            {
                GetMethods.SelectWhoSelectMe(AppManeger.instance.wantToMeet, AppManeger.instance.wantAge, AppManeger.instance.userID,
                                             (listResultsSelectMe) => {
                    if (listResultsSelectMe[0].ContainsKey("Error"))
                    {
                        Debug.Log(listResultsSelectMe[0]["Error"] + ". No one selected me");

                        // Show other users
                        usersListOfDic = listResults;
                        DisplayUsers();
                    }
                    else
                    {
                        // Remove users from listResults that are also in listResultsSelectMe
                        //ps: ListResultsSelectMe is always <= listResults
                        foreach (Dictionary <string, string> dic in listResultsSelectMe)
                        {
                            int i = 0;
                            foreach (Dictionary <string, string> dic2 in listResults)
                            {
                                if (dic["ID"] == dic2["ID"])                                                 // same id remove from he listResults
                                {
                                    listResults.RemoveAt(i);
                                    break;
                                }
                                i++;
                            }
                        }

                        listResults.AddRange(listResultsSelectMe);                                         //Add the users back
                        usersListOfDic = listResults;
                        DisplayUsers();
                    }
                }
                                             );// End of GetMethods.SelectWhoSelectMe
            }
        }
                                    ); // End of GetMethods.GetUsersByFilter
    }
예제 #13
0
        public JsonResult GetAllPosts()
        {
            var allPosts = GetMethods.GetAllPosts();

            return(new JsonResult
            {
                Data = allPosts,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
예제 #14
0
        public ActionResult ShowAll()
        {
            using (var db = new BlogDbContext())
            {
                var posts = db.Posts.Where(p => p.IsDeleted == false).OrderByDescending(p => p.PublishDate)
                            .ToList();
                posts = GetMethods.GetInitializedUserList(posts);
                ViewData["Layout"] = GetMethods.GetLayout(User.Identity.Name);

                return(View("~/Views/Main/AllPosts.cshtml", posts));
            }
        }
예제 #15
0
        public ActionResult UserDeleteComment(int postId, int commentId)
        {
            string username = User.Identity.Name;
            var    userId   = GetMethods.GetUserId(username);

            if (CheckMethods.IsUsersComment(userId, commentId))
            {
                DeleteComment(commentId);
                return(RedirectToAction("ShowPost", "MainPage", new { postId = postId }));
            }
            return(RedirectToAction("AccessDenied", "Error"));
        }
예제 #16
0
        public void ThenAllTheAnswersShouldBeMatch()
        {
            var reponses = _scenarioContext.Get <IEnumerable <SuitabilityResponse> >("Responses");

            foreach (var expectedResponse in reponses)
            {
                var displayedAnswer = GetMethods.GetText(By.CssSelector($"#{expectedResponse.QuestionKey} strong"), _browserContext);
                if (expectedResponse.Answer == AnswerType.NotSure)
                {
                    displayedAnswer.Should().Be("I'm not sure");
                }
                else
                {
                    displayedAnswer.Should().Be(expectedResponse.Answer.ToString());
                }

                if (!string.IsNullOrEmpty(expectedResponse.Details?.Trim()))
                {
                    var displayedNotes = GetMethods.GetText(By.CssSelector($"#{expectedResponse.QuestionKey}_Notes span"), _browserContext);
                    displayedNotes.Should().Be(expectedResponse.Details.ToString());
                }
            }

            //Verify the expected data by comparing them against database
            var request  = _testContext.Get($"persons/username/{_testContext.TestUserSecrets.Representative}/suitability-answers");
            var response = _testContext.Client().Execute(request);
            var model    = ApiRequestHelper.DeserialiseSnakeCaseJsonToResponse <List <PersonSuitabilityAnswerResponse> >(response.Content);
            var answers  = model.First(h => h.Hearing_id.ToString() == _testContext.HearingId).Answers;

            foreach (var expectedResponse in reponses)
            {
                var answer = answers.Single(a => a.Key == expectedResponse.QuestionKey);
                switch (expectedResponse.Answer)
                {
                case AnswerType.Yes:
                    answer.Answer.Should().Be(answer.Key == RepresentativeQuestionKeys.AboutYourComputer ? "Yes" : "true");
                    break;

                case AnswerType.No:
                    answer.Answer.Should().Be(answer.Key == RepresentativeQuestionKeys.AboutYourComputer ? "Yes" : "false");
                    break;

                case AnswerType.NotSure:
                    answer.Answer.Should().Be("Not sure");
                    break;
                }
                if (!string.IsNullOrEmpty(expectedResponse.Details?.Trim()))
                {
                    answer.Extended_answer.Should().Be(expectedResponse.Details.Trim().ToString());
                }
            }
        }
예제 #17
0
 public void Setup()
 {
     _client = new RestClient
     {
         BaseUrl = new Uri(Constants.API_BASE_URL)
     };
     _client.AddDefaultHeader(Constants.G_TOKEN_NAME, Constants.G_TOKEN_VALUE);
     _client.Authenticator = new HttpBasicAuthenticator(Constants.AUTHORIZATION_NAME, Constants.AUTHORIZATION_PASSWORD);
     _gen  = new GeneralMethods();
     _post = new PostMethods(_client);
     _get  = new GetMethods(_client);
     _del  = new DeleteMethods(_client);
 }
예제 #18
0
 public ActionResult Profile()
 {
     using (var db = new BlogDbContext())
     {
         var login     = User.Identity.Name;
         var userId    = db.Users.Where(u => u.Username.Equals(login)).Select(u => u.UserId).FirstOrDefault();
         var userPosts = db.Posts.Where(p => p.UserId == userId && p.IsDeleted == false)
                         .OrderByDescending(p => p.PublishDate).ToList();
         userPosts          = GetMethods.GetInitializedUserList(userPosts);
         ViewData["Layout"] = GetMethods.GetLayout(login);
         return(View("~/Views/User/Profile.cshtml", userPosts));
     }
 }
예제 #19
0
        public ActionResult ShowPost(int postId)
        {
            using (var db = new BlogDbContext())
            {
                var post     = db.Posts.FirstOrDefault(p => p.PostId == postId);
                var user     = db.Users.FirstOrDefault(u => u.UserId == post.UserId);
                var comments = db.Comments.Where(c => c.PostId == postId).ToList();
                comments     = GetMethods.GetInitializedUserList(comments);
                ViewBag.User = user;

                ViewBag.Comments   = comments;
                ViewData["Layout"] = GetMethods.GetLayout(User.Identity.Name);
                return(View("~/Views/Main/ShowPost.cshtml", post));
            }
        }
예제 #20
0
        public ActionResult OpenUserUpdatePost(int postid)
        {
            using (BlogDbContext db = new BlogDbContext())
            {
                var username = User.Identity.Name;
                if (CheckMethods.IsUsersPost(postid, username))
                {
                    ViewData["Layout"] = GetMethods.GetLayout(User.Identity.Name);
                    var post = db.Posts.FirstOrDefault(p => p.PostId == postid);
                    return(View("~/Views/User/UserUpdatePost.cshtml", post));
                }

                return(RedirectToAction("AccessDenied", "Error"));
            }
        }
예제 #21
0
        public void VideoHasStarted()
        {
            BrowserContext.Retry(() =>
            {
                double currentTime;
                if (!double.TryParse(GetMethods.GetAttributeValue(_videoContent, BrowserContext, "currentTime"),
                                     out currentTime))
                {
                    throw new Exception();
                }

                if (currentTime > 0)
                {
                    return;
                }
                throw new Exception($"Video current time is {currentTime}, it hasn't started automatically");
            });
        }
예제 #22
0
    void InsertUserResult(string result)
    {
        if (result == "Success" || result == "success")          // Finish to insert user into data base

        {
            Debug.Log(string.Format("Users was {0} insert into users database", result));
            GetMethods.GetUserId(email, (id) => {
                if (id != "0")                  // The user exits in the data base

                {
                    AppManeger.instance.userID = id;
                    GetMethods.GetUserPrefs(id, (prefsResult) => {
                        PrefsResult(prefsResult);
                    });                     // Check if the user are in the Prefs Database
                }
            });
        }
        else
        {
            Debug.Log(result);
        }
    }
예제 #23
0
        public ActionResult UserUpdateComment(int postId, int commentId)
        {
            using (BlogDbContext db = new BlogDbContext())
            {
                string username = User.Identity.Name;
                var    userId   = GetMethods.GetUserId(username);
                if (!CheckMethods.IsUsersComment(userId, commentId))
                {
                    return(RedirectToAction("AccessDenied", "Error"));
                }
                string commentToUpdate = db.Comments.Where(c => c.CommentId == commentId).Select(c => c.Content).FirstOrDefault();
                ViewBag.CommentToUpdate = commentToUpdate;
                var post     = db.Posts.FirstOrDefault(p => p.PostId == postId);
                var user     = db.Users.FirstOrDefault(u => u.UserId == post.UserId);
                var comments = db.Comments.Where(c => c.PostId == postId).ToList();
                comments     = GetMethods.GetInitializedUserList(comments);
                ViewBag.User = user;

                ViewBag.Comments   = comments;
                ViewData["Layout"] = GetMethods.GetLayout(User.Identity.Name);
                return(View("~/Views/Main/ShowPost.cshtml", post));
            }
        }
예제 #24
0
 public void ValidateErrorMessage(int errorCounter)
 {
     GetMethods.GetElements(By.CssSelector("span.govuk-error-message"), _browserContext).Count().Should().Be(errorCounter);
 }
 public List <Seance> GetSeancesFromServer()
 {
     return(GetMethods.Seances());
 }
 public List <Article> GetArticlesFromServer()
 {
     return(GetMethods.Articles());
 }
 public List <Movie> GetMoviesFromServer()
 {
     return(GetMethods.Movies());
 }
예제 #28
0
 private string UseMyCameraAndMicrophoneAccordion()
 {
     SetMethods.ClickElement(UseMyCameraAndMicrophone, BrowserContext);
     return(GetMethods.GetText(UseMyCameraAndMicrophone, BrowserContext));
 }
예제 #29
0
        public void GivenHearingDueDateIsInTheFuture()
        {
            var hearingDueDate = GetMethods.IsElementDisplayed(By.CssSelector("#form-container strong"), _context);

            hearingDueDate.Should().BeTrue();
        }
 public List <Hall> GetHallsFromServer()
 {
     return(GetMethods.Halls());
 }