Example #1
0
        public User Login()
        {
            userIO.CenterText(userIO.zwitterAscii);
            userIO.PadLeft("Login\n", 2, ConsoleColor.Cyan);
            UpdateSearchLists();

            userIO.PadLeft("Enter Email", 2);
            string eMail = userIO.GetUserString();
            User   user  = GetUserByEmail(eMail);

            if (!CheckEmailInSystem(eMail))
            {
                userIO.PadLeft("Email not found. Press enter to continue.", 2, ConsoleColor.DarkYellow);
                Console.ReadLine();
                return(user);
            }

            userIO.PadLeft("Enter Password", 2);
            string password = GetPassword();

            //check if email and pass are correct
            if (password != user.Password)
            {
                userIO.PadLeft("Password incorrect, press enter to continue", 2, ConsoleColor.DarkRed);
                Console.ReadLine();
                return(user);
            }

            user.LoggedIn = true;
            LoadUserPosts(user);
            return(user);
        }
Example #2
0
        public void DeletePost(User user)
        {
            List <Post> posts = LoadPosts();

            int selection = ShowPostsSelection(user.allPosts, "  Delete zweet\n  ___________");

            if (selection == -1)
            {
                userIO.CenterText(userIO.zwitterAscii);
                userIO.PadLeft("No zweets to be deleted, press enter to continue", 2, ConsoleColor.DarkYellow);
                Console.ReadLine();
            }
            else if (selection == user.allPosts.Count)
            {
                return; //user pressed back
            }
            else
            {
                userIO.PadLeft("Are you sure you want to delete this zweet? y/n", 2, ConsoleColor.DarkRed);

                if (userIO.AskYesNoQ())
                {
                    int  postId       = user.allPosts[selection].PostId;
                    Post postToDelete = posts.Find(x => x.PostId == postId);
                    posts.Remove(postToDelete);        //remove from all posts

                    user.allPosts.RemoveAt(selection); //remove from userlist

                    UpdateDb(posts);

                    userIO.CenterText(userIO.zwitterAscii);

                    userIO.PadLeft("Your zweet was succesfully deleted!, press enter to continue", 2, ConsoleColor.Green);
                    Console.ReadLine();
                }
            }
        }