Beispiel #1
0
        /// <summary>
        /// Choose menu "Change user data"
        /// </summary>
        public static void ChangeUserDataByAdmin()
        {
            string inputName, inputUserId;
            int    userId;

            Print.PrintHeader("Change user data", ConsoleColor.DarkYellow);
            inputUserId = Print.ReadInput("Enter user ID:");

            userId = ParseInput.IsCorrectId(inputUserId);
            if (userId == -1)
            {
                return;
            }

            inputName = Print.ReadInput("Enter new user name (at least 3 characters):");
            if (!ParseInput.IsCorrectName(inputName))
            {
                return;
            }

            if (!StartActions.AdminLogic.ChangeUserName(inputName, userId))
            {
                Console.WriteLine("Username hasn't changed!");
            }
            else
            {
                Console.WriteLine("Username has changed!");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Choose menu ("Change username"
        /// </summary>
        public static void ChangeName()
        {
            string inputName;

            Print.PrintHeader("Change username", ConsoleColor.DarkYellow);
            inputName = Print.ReadInput("Enter new username (at least 3 characters):");

            if (!ParseInput.IsCorrectName(inputName))
            {
                return;
            }

            if (!StartActions.UserLogic.ChangeName(inputName))
            {
                Console.WriteLine("Username hasn't changed!");
            }
            else
            {
                Console.WriteLine("Username has changed!");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Choose menu "Add New Product"
        /// </summary>
        public static void AddNewProduct()
        {
            string  inputName, inputPrice;
            decimal price;

            Print.PrintHeader("Add New Product", ConsoleColor.DarkYellow);

            Console.WriteLine("Choose product category: ");

            foreach (var item in StartActions.AdminLogic.GetCategories())
            {
                Console.WriteLine(item);
            }

            string inputCategory = Print.ReadInput("\nEnter category number: ");

            inputName = Print.ReadInput("Enter name (at least 3 characters):");
            if (!ParseInput.IsCorrectName(inputName))
            {
                return;
            }

            inputPrice = Print.ReadInput("Enter price:");
            price      = ParseInput.IsCorrectPrice(inputPrice);
            if (price == -1)
            {
                return;
            }

            if (!StartActions.AdminLogic.AddNewProduct(inputCategory, inputName, price))
            {
                Console.WriteLine("Incorrect input data\nProduct hasn't added!");
            }
            else
            {
                Console.WriteLine("Product has added!");
            }
        }
Beispiel #4
0
        /// <summary>
        /// Choose menu "Change product data"
        /// </summary>
        public static void ChangeProductDataByAdmin()
        {
            string  inputName, inputPrice, inputProductId;
            int     productId;
            decimal price;

            Print.PrintHeader("Change product data", ConsoleColor.DarkYellow);

            inputProductId = Print.ReadInput("Enter product ID:");
            productId      = ParseInput.IsCorrectId(inputProductId);
            if (productId == -1)
            {
                return;
            }

            if (!StartActions.AdminLogic.ProductExist(productId))
            {
                Console.WriteLine("Such product doesn't exist!");
                return;
            }

            string input = Print.ReadInput("Enter what you need to change\n[1] Product name\n[2] Product price");

            if (input == "1")
            {
                inputName = Print.ReadInput("Enter new name:");
                if (!ParseInput.IsCorrectName(inputName))
                {
                    return;
                }

                if (StartActions.AdminLogic.ChangeProductName(productId, inputName))
                {
                    Console.WriteLine("Name changed!");
                }
                else
                {
                    Console.WriteLine("Incorrect input!");
                }
            }
            else if (input == "2")
            {
                inputPrice = Print.ReadInput("Enter new price:");
                price      = ParseInput.IsCorrectPrice(inputPrice);

                if (price == -1)
                {
                    return;
                }

                if (StartActions.AdminLogic.ChangeProductPrice(productId, price))
                {
                    Console.WriteLine("Price changed!");
                }
                else
                {
                    Console.WriteLine("Incorrect input!");
                }
            }
            else
            {
                Console.WriteLine("Incorrect input!");
            }
        }
        /// <summary>
        /// Choose menu 'Register'
        /// </summary>
        public static void Register()
        {
            GuestLogic = new GuestLogic();
            string name, email, password, input;

            while (true)
            {
                Console.Clear();
                Print.PrintHeader("REGISTER", ConsoleColor.DarkYellow);

                name = Print.ReadInput("\nEnter your name (at least 3 characters): ");
                if (!ParseInput.IsCorrectName(name))
                {
                    Console.WriteLine("\nIncorrect name!");
                    input = Print.ReadInput("\n[1] Try again\nor enter any other key to return");
                    if (input != "1")
                    {
                        return;
                    }
                    else
                    {
                        continue;
                    }
                }

                email = Print.ReadInput("\nEnter user email (*****@***): ");
                if (!ParseInput.IsCorrectEmail(email))
                {
                    Console.WriteLine("\nIncorrect email!");
                    input = Print.ReadInput("\n[1] Try again\nor enter any other key to return");
                    if (input != "1")
                    {
                        return;
                    }
                    else
                    {
                        continue;
                    }
                }

                password = Print.ReadInput("\nEnter password (at least 3 characters): ");
                if (!ParseInput.IsCorrectPassword(password))
                {
                    Console.WriteLine("\nIncorrect password!");
                    input = Print.ReadInput("\n[1] Try again\nor enter any other key to return");
                    if (input != "1")
                    {
                        return;
                    }
                    else
                    {
                        continue;
                    }
                }
                if (!GuestLogic.Register(name, email, password))
                {
                    Console.WriteLine("\nUser with this email already exists!");
                    input = Print.ReadInput("\n[1] Try again\nor enter any other key to return");
                    if (input != "1")
                    {
                        return;
                    }
                }
                else
                {
                    break;
                }
            }

            GuestLogic.LogIn(email, password);

            Console.Clear();
            if (UserLogic.GetAccountType().Equals("USER"))
            {
                UserActions.UserMode();
            }
            else
            {
                UserActions.AdminMode();
            }

            while (true)
            {
                Print.PrintHeader($"{UserLogic.GetAccountType()}: {UserLogic.GetAccountName()}", ConsoleColor.Green);

                UserActions.GetActions();

                input = Console.ReadLine();
                Console.Clear();
                Print.PrintHeader($"{UserLogic.GetAccountType()}: {UserLogic.GetAccountName()}", ConsoleColor.Green);
                if (input.ToLower() == "q")
                {
                    UserLogic.LogOut();
                    break;
                }

                UserActions.ChooseAction(input);
            }
        }