Beispiel #1
0
        public static void Userprofile()
        {
            string result = JsonHandling.JsonRead("../../../Users.json");


            dynamic dynJson = JsonConvert.DeserializeObject(result);

            Console.WriteLine("User Profile");
            Console.WriteLine("-------------------------");


            foreach (var item in dynJson)
            {
                if (item.id == UserProfile.currentId)
                {
                    string s = $"Username:\t{item.name}" + "\n" + $"Age:\t\t{item.age}" + "\n" + $"Phone:   \t{item.phone}" + "\n" + $"Email:\t\t{item.email}" + "\n" + $"Balance:\t{item.balance} $";
                    Console.WriteLine(s);
                }
            }
            Console.WriteLine("\n[Enter] - Main Menu");
            Console.WriteLine("[1] - Add balance");

            string userInput = Console.ReadLine();

            if (userInput == "1")
            {
                Console.WriteLine("How much do you want to add?: ");
                int input = Convert.ToInt32(Console.ReadLine());

                UserProfile.Balance(input, true);
            }
            userInput = null;
        }
        public static double ReceivedMoney()
        {
            string result  = JsonHandling.JsonRead("../../../ReceivedMoney.json");
            var    dynJson = JObject.Parse(result);

            // this is test value for receivedMoney
            receivedMoney = Convert.ToDouble(dynJson["receivedMoney"]);
            return(receivedMoney);
        }
Beispiel #3
0
        public static void UserChooseOption()
        {
            // userInterface: Rohullah Karimi 2020
            string result  = JsonHandling.JsonRead("../../../Users.json");
            double balance = 0.0;

            dynamic dynJson = JsonConvert.DeserializeObject(result);

            foreach (var item in dynJson)
            {
                if (item.id == UserProfile.currentId)
                {
                    balance = item.balance;
                }
            }
            string option;

            Console.WriteLine("Choose your option\n [1] Completed line \n [2] Choose your numbers");
            Console.WriteLine("\n[Enter] - Main Menu");
            option = Console.ReadLine();
            if (option == "1")
            {
                if (balance >= 2.0)
                {
                    UserChooseNumbers.ProgramGuessNumbersForUser();
                    UserChooseNumbers.AddToJson();
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Not enough balance");
                    Console.ReadLine();
                }
            }
            else if (option == "2")
            {
                if (balance >= 2.0)
                {
                    UserChooseNumbers.AskUserForFiveNumbers();
                    UserChooseNumbers.AddToJson();
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Not enough balance");
                    Console.ReadLine();
                }
            }
            else
            {
                Console.WriteLine("Choose 1 or 2 to continue");
            }
            Console.Clear();
        }
        public static void Balance(double amount, bool add)

        {
            double      newBalance = 0;
            List <User> list       = new List <User>();

            string result = JsonHandling.JsonRead("../../../Users.json");

            dynamic dynJson = JsonConvert.DeserializeObject(result);

            foreach (var item in dynJson)
            {
                if (item.id == currentId && add)
                {
                    newBalance = item.balance + amount;
                }
                else if (item.id == currentId && !add)
                {
                    newBalance = item.balance - amount;
                    LotteryDay.receivedMoney = LotteryDay.receivedMoney + amount;

                    ReceivedMoney moneyObject = new ReceivedMoney();
                    moneyObject.receivedMoney = LotteryDay.receivedMoney;

                    string jsonString2 = JsonConvert.SerializeObject(moneyObject, Formatting.Indented);
                    JsonHandling.JsonWrite("../../../ReceivedMoney.json", jsonString2);
                }
                else
                {
                    newBalance = item.balance;
                }
                User userOld = new User();
                userOld.name     = item.name;
                userOld.password = item.password;
                userOld.age      = item.age;
                userOld.phone    = item.phone;
                userOld.email    = item.email;
                userOld.balance  = newBalance;


                list.Add(userOld);
            }
            string jsonString = JsonConvert.SerializeObject(list, Formatting.Indented);

            JsonHandling.JsonWrite("../../../Users.json", jsonString);
            User.NextId = 0;
        }
        public static void SignIn(string username, string password)
        {
            string result = JsonHandling.JsonRead("../../../Users.json");

            dynamic dynJson = JsonConvert.DeserializeObject(result);

            foreach (var item in dynJson)
            {
                if (item.name == username && item.password == password)
                {
                    currentId = item.id;
                    UserInterface.successfulSignIn = true;
                    //Console.WriteLine(Convert.ToString(item.id));
                }
            }

            if (UserInterface.successfulSignIn == false)
            {
                Console.WriteLine("Wrong username or password");
            }
        }
Beispiel #6
0
        public static void MainMenu()
        {
            string            LotteryNumbers = JsonHandling.JsonRead("../../../LotteryDay.json");
            List <LotteryDay> lineList       = JsonConvert.DeserializeObject <List <LotteryDay> >(LotteryNumbers);

            LotteryDay lastObj = lineList[lineList.Count - 1];

            Console.WriteLine("Main menu");
            Console.WriteLine("-------------------------");
            Console.WriteLine(
                "[1] - My Profile\n" +
                "[2] - History\n" +
                "[3] - Buy Lottery line\n" +
                "[4] - Sign Out"
                );
            Console.WriteLine("\nLatest numbers: " + String.Join(", ", lastObj.lineNumber));
            string userInput = Console.ReadLine();

            if (userInput == "1")
            {
                Console.Clear();
                Userprofile();
            }
            else if (userInput == "2")
            {
                Console.Clear();
                UserHistory();
            }

            else if (userInput == "3")
            {
                Console.Clear();
                UserChooseOption();
            }
            else if (userInput == "4")
            {
                UserProfile.SignOut();
            }
            Console.Clear();
        }
Beispiel #7
0
        public static void UserHistory()
        {
            List <UserChooseNumbers> LottoNumberList = new List <UserChooseNumbers>();

            string result = JsonHandling.JsonRead("../../../UserLotteryNumbers.json");

            LottoNumberList = JsonConvert.DeserializeObject <List <UserChooseNumbers> >(result);


            Console.WriteLine($"Date\t\tNumbers\t\t\tStatus");
            Console.WriteLine("-------------------------------------------------");

            foreach (var item in LottoNumberList)
            {
                if (item.userID == UserProfile.currentId)
                {
                    string status;
                    if (item.status == true)
                    {
                        status = "Win";
                    }
                    else if (item.status == false)
                    {
                        status = "Loss";
                    }
                    else
                    {
                        status = "Not drawn";
                    }

                    string s = $"{item.date}" + $"\t" + $"{String.Join(", ", item.userLotteryNumber)}" + "     \t" + $"{status}";
                    Console.Write(s);
                    Console.WriteLine();
                }
            }
            Console.WriteLine("\n[Enter] - Main Menu");
            Console.ReadLine();
            Console.Clear();
        }
        public static void LotteryNumber()
        {
            LotteryDay receivedMoney = new LotteryDay();

            double getMoneyValue = LotteryDay.ReceivedMoney();

            if (getMoneyValue >= 10)
            {
                // guess the 5 numbers
                int[]  zombieLottolineNumber = new int[5];
                Random randomNumbers         = new Random();


                List <int> listNumbers = new List <int>();
                int        num;
                for (int round = 0; round < 5; round++)
                {
                    do
                    {
                        num = randomNumbers.Next(1, 25);
                    } while (listNumbers.Contains(num));
                    listNumbers.Add(num);

                    zombieLottolineNumber[round] = num;
                }
                //Console.WriteLine("ZombieLotto line number: " + "{0}", string.Join(", ", zombieLottolineNumber));
                zombieLottoLineNumber = zombieLottolineNumber;

                ReceivedMoney moneyObject = new ReceivedMoney();
                moneyObject.receivedMoney = 0.0;

                string jsonString = JsonConvert.SerializeObject(moneyObject, Formatting.Indented);
                JsonHandling.JsonWrite("../../../ReceivedMoney.json", jsonString);

                AddToJson();
                UserHistory.CheckNumbers();
            }
        }
        public static void SignUp(string signUpUsername, string signUpPassword, int signUpAge, string signUpPhone, string signUpEmail)
        {
            List <User> list = new List <User>();

            string result = JsonHandling.JsonRead("../../../Users.json");

            dynamic dynJson = JsonConvert.DeserializeObject(result);

            foreach (var item in dynJson)
            {
                User userOld = new User();
                userOld.name     = item.name;
                userOld.password = item.password;
                userOld.age      = item.age;
                userOld.phone    = item.phone;
                userOld.email    = item.email;

                list.Add(userOld);
            }
            //-- New user account --
            User user = new User();

            user.name     = signUpUsername;
            user.password = signUpPassword;
            user.age      = signUpAge;
            user.age      = signUpAge;
            user.phone    = signUpPhone;
            user.email    = signUpEmail;

            list.Add(user);

            //-- Writes all users into json file
            string jsonString = JsonConvert.SerializeObject(list, Formatting.Indented);

            JsonHandling.JsonWrite("../../../Users.json", jsonString);
            User.NextId = 0;
        }
        public static void CheckNumbers()
        {
            string LotteryNumbers = JsonHandling.JsonRead("../../../LotteryDay.json");

            string UserNumbers = JsonHandling.JsonRead("../../../UserLotteryNumbers.json");


            //-- check status (false, true, null) --
            List <UserChooseNumbers> List = new List <UserChooseNumbers>();

            List <UserChooseNumbers> listJson = JsonConvert.DeserializeObject <List <UserChooseNumbers> >(UserNumbers);

            foreach (var item in listJson)
            {
                if (item.status == null)
                {
                    List.Add(item);
                }
            }


            //-- fetch last object from LotteryDay.json & the numbers --
            List <int> LotteryList = new List <int>();

            List <LotteryDay> lineList = JsonConvert.DeserializeObject <List <LotteryDay> >(LotteryNumbers);

            LotteryDay lastObj = lineList[lineList.Count - 1];

            for (int i = 0; i < lastObj.lineNumber.Length; i++)
            {
                LotteryList.Add(lastObj.lineNumber[i]);
            }


            List <UserChooseNumbers> finalList = new List <UserChooseNumbers>();


            foreach (var item2 in listJson)
            {
                if (item2.status != null)
                {
                    finalList.Add(item2);
                }
            }

            //-- compare the numbers --
            foreach (var item in List)
            {
                int  point = 0;
                bool?WinOrLose;

                for (int i = 0; i < item.userLotteryNumber.Length; i++)
                {
                    for (int n = 0; n < LotteryList.Count; n++)
                    {
                        if (item.userLotteryNumber[i] == LotteryList[n])
                        {
                            point++;
                        }
                    }
                }

                if (point == 5)
                {
                    WinOrLose = true;
                }
                else
                {
                    WinOrLose = false;
                }
                item.status = WinOrLose;
                finalList.Add(item);

                //Console.WriteLine(WinOrLose);
                //-- status change --
            }
            string jsonString = JsonConvert.SerializeObject(finalList, Formatting.Indented);

            JsonHandling.JsonWrite("../../../UserLotteryNumbers.json", jsonString);
        }