Exemplo n.º 1
0
        /// <summary>
        /// Output page with information about current user orders and work with user actions
        /// </summary>
        private void OrderHistory()
        {
            this.Clear();
            var orders = this.Controller.OrderController.GetOrdersOfUser(this.User.Email);

            foreach (var order in orders)
            {
                this.OutputOrder(order);
            }
            Console.WriteLine(@"change status {id}- change status of order with id");
            Console.WriteLine("main - go to main page");
            Console.WriteLine("0 - Exit");

            while (true)
            {
                this.userAction = this.GetUserText();
                if (Regex.IsMatch(userAction, @"^change status \d{1,10}$"))
                {
                    this.ChangeOrderStatus(int.Parse(userAction.Remove(0, 14)));
                    this.page = MainPage;
                    return;
                }
                else if (userAction.Equals("main"))
                {
                    this.page = MainPage;
                    return;
                }
                else if (userAction.Equals("0") && this.User != null)
                {
                    this.page = SignOff;
                    return;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Output page with information about current user and work with user actions
        /// </summary>
        private void PersonalInformationOfCurrentUser()
        {
            if (this.User != null)
            {
                this.OutputUser(this.Controller.UserController.GetUser(this.User.Email));
            }
            Console.WriteLine(@"change - change information of user with Id");
            Console.WriteLine("main - go to main page");
            Console.WriteLine("0 - Exit");

            while (true)
            {
                this.userAction = this.GetUserText();
                if (Regex.IsMatch(userAction, @"^change$"))
                {
                    this.ChangePersonalInformation(this.User.Email);
                    return;
                }
                else if (userAction.Equals("main"))
                {
                    this.page = MainPage;
                    return;
                }
                else if (userAction.Equals("0") && this.User != null)
                {
                    this.page = SignOff;
                    return;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get fields from user and try to sign up new user in system
        /// </summary>
        private void SignUp()
        {
            RegisterUserViewModel userViewModel = new RegisterUserViewModel();

            while (!ConsoleUI.IsValidEmail(userViewModel.Email))
            {
                Console.WriteLine("Email :");
                userViewModel.Email = this.GetUserText();
            }
            while (!Regex.IsMatch(userViewModel.UserName, @"(\d|\w){6,12}"))
            {
                Console.WriteLine("UserName :"******"(\d|\w){6,12}"))
            {
                Console.WriteLine("Password :"******"Confirm password :");
                userViewModel.ConfirmPassword = this.GetUserText();
            }
            var temp = this.Controller.UserController.SignUpUser(userViewModel);

            if (temp)
            {
                this.page = SignIn;
            }
            else
            {
                this.page = MainPage;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Output main pagee and work with user actions
        /// </summary>
        public void MainPage()
        {
            this.Clear();
            if (this.User is RegisteredUser)
            {
                this.WriteRegisteredUserMainFunctions();
            }
            if (this.User is Administrator)
            {
                this.WriteAdministratorMainFunctions();
            }
            if (this.User == null)
            {
                this.WriteGuestMainFunctions();
            }

            this.userAction = this.GetUserText();
            if (userAction.Equals("show"))
            {
                this.page = GetListOfAllProducts;
            }
            else if (userAction.Equals("find"))
            {
                this.page = FindProductByName;
            }
            else if (userAction.Equals("sign up") && this.User == null)
            {
                this.page = SignUp;
            }
            else if (userAction.Equals("sign in") && this.User == null)
            {
                this.page = SignIn;
            }
            else if (userAction.Equals("watch history") && this.User is RegisteredUser)
            {
                this.page = OrderHistory;
            }
            else if (userAction.Equals("persinf") && this.User is RegisteredUser)
            {
                this.page = PersonalInformationOfCurrentUser;
            }
            else if (userAction.Equals("new product") && this.User is Administrator)
            {
                this.page = CreateNewProduct;
            }
            else if (userAction.Equals("show users") && this.User is Administrator)
            {
                this.page = ListOfUsers;
            }
            else if (userAction.Equals("0") && this.User != null)
            {
                this.page = SignOff;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Output page with creating form of new product and send product in BLL
        /// </summary>
        private void CreateNewProduct()
        {
            Product product = new Product();

            while (true)
            {
                this.OutputProduct(product);
                Console.WriteLine("name - to change username");
                Console.WriteLine("description -to change description");
                Console.WriteLine("price - to change price");
                Console.WriteLine("add - to add prodyct");
                Console.WriteLine("main - go to main page");
                Console.WriteLine("0 - Exit");

                this.userAction = this.GetUserText();
                if (userAction.Equals("name"))
                {
                    this.userAction = this.GetUserText();
                    product.Name    = userAction;
                }
                else if (userAction.Equals("description"))
                {
                    this.userAction     = this.GetUserText();
                    product.Description = userAction;
                }
                else if (userAction.Equals("price"))
                {
                    this.userAction = this.GetUserText();
                    if (Regex.IsMatch(userAction, @"^(\d){1,12}$"))
                    {
                        product.Price = int.Parse(userAction);
                    }
                }
                else if (userAction.Equals("add"))
                {
                    this.Controller.ProductController.AddProduct(product);
                    this.page = MainPage;
                    return;
                }
                else if (userAction.Equals("main"))
                {
                    this.page = MainPage;
                    return;
                }
                else if (userAction.Equals("0") && this.User != null)
                {
                    this.page = SignOff;
                    return;
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Change status of order with user rigths
        /// </summary>
        /// <param name="order">order to change status</param>
        private void ChangeOrderStatusByUser(OrderViewModel order)
        {
            bool isUpdated = false;

            while (true)
            {
                this.OutputOrder(order);
                if (order.State < OrderState.Received)
                {
                    Console.WriteLine("Received -to change status to Completed");
                    Console.WriteLine("CanceledByUser - to change status to CanceledByUser");
                }
                if (isUpdated)
                {
                    Console.WriteLine("Update - to update status");
                }
                Console.WriteLine("main - go to main page");
                Console.WriteLine("0 - Exit");

                this.userAction = this.GetUserText();

                if (userAction.Equals("Received") && order.State < OrderState.Received)
                {
                    order.State = OrderState.Received;
                    isUpdated   = true;
                }
                else if (userAction.Equals("CanceledByUser") && order.State < OrderState.Received)
                {
                    order.State = OrderState.CanceledByUser;
                    isUpdated   = true;
                }
                else if (userAction.Equals("Update") && isUpdated)
                {
                    this.Controller.OrderController.UpdateStatebyId(order.Id, order.State);
                    this.page = MainPage;
                    return;
                }

                if (userAction.Equals("main"))
                {
                    this.page = MainPage;
                    return;
                }
                else if (userAction.Equals("0") && this.User != null)
                {
                    this.page = SignOff;
                    return;
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get fields from user and try to sign in system
        /// </summary>
        private void SignIn()
        {
            RegisterUserViewModel userViewModel = new RegisterUserViewModel();

            Console.WriteLine("         Sign in   ");
            Console.WriteLine("Email :");
            userViewModel.Email = this.GetUserText();

            Console.WriteLine("Password :");
            userViewModel.Password = this.GetUserText();

            var temp = this.Controller.UserController.SignInUser(userViewModel);

            this.User = temp;
            this.page = MainPage;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Output page with all users and work with user actions
        /// </summary>
        private void ListOfUsers()
        {
            this.Clear();
            List <UsersViewModel> users = this.Controller.UserController.GetListOfUsers();

            foreach (var user in users)
            {
                Console.WriteLine("User:"******"User`s orders: \n");
                var orders = this.Controller.OrderController.GetOrdersOfUser(user.Email);
                foreach (var order in orders)
                {
                    this.OutputOrder(order);
                }
            }
            Console.WriteLine(@"change status {id}- change status of order with id");
            Console.WriteLine(@"{email} - change information of user with email");
            Console.WriteLine("main - go to main page");
            Console.WriteLine("0 - Exit");

            while (true)
            {
                this.userAction = this.GetUserText();
                if (Regex.IsMatch(userAction, @"^change status \d{1,10}$"))
                {
                    this.ChangeOrderStatus(int.Parse(userAction.Remove(0, 14)));
                    this.page = MainPage;
                    return;
                }
                else if (ConsoleUI.IsValidEmail(userAction))
                {
                    this.ChangePersonalInformation(userAction);
                }
                else if (userAction.Equals("main"))
                {
                    this.page = MainPage;
                    return;
                }
                else if (userAction.Equals("0") && this.User != null)
                {
                    this.page = SignOff;
                    return;
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Output page with information about products and work with user actions
        /// </summary>
        private void ListOfProducts(List <Product> products)
        {
            this.Clear();
            foreach (var product in products)
            {
                this.OutputProduct(product);
            }
            Console.WriteLine(@"order + {Id} - make an order");
            Console.WriteLine("main - go to main page");
            if (this.User != null)
            {
                Console.WriteLine("0 - Exit");
            }

            while (true)
            {
                this.userAction = this.GetUserText();
                if (Regex.IsMatch(userAction, @"^order \d*$"))
                {
                    if (this.User == null)
                    {
                        this.page = SignIn;
                        return;
                    }
                    else
                    {
                        this.CreateNewOrder(userAction.Remove(0, 6));
                        return;
                    }
                }
                else if (userAction.Equals("main"))
                {
                    this.page = MainPage;
                    return;
                }
                else if (userAction.Equals("0") && this.User != null)
                {
                    this.page = SignOff;
                    return;
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Create new order
        /// </summary>
        /// <param name="id">id of product that will be ordered</param>
        private void CreateNewOrder(string id)
        {
            var product = this.Controller.ProductController.GetProductByKey(id);

            this.OutputProduct(product);
            Console.WriteLine(@"confirm - confirm new order");
            Console.WriteLine("main - go to main page");
            Console.WriteLine("0 - Exit");
            OrderViewModel order = new OrderViewModel()
            {
                IdProduct = product.Id, Name = product.Name, EmailUser = this.User.Email, Price = product.Price
            };

            while (true)
            {
                this.OutputOrder(order);
                this.userAction = this.GetUserText();
                if (userAction.Equals("description"))
                {
                    Console.WriteLine("Description : ");
                    order.Description = this.GetUserText();
                }
                else if (userAction.Equals("confirm"))
                {
                    this.Controller.OrderController.AddOrder(order);
                    this.page = OrderHistory;
                    return;
                }
                else if (userAction.Equals("main"))
                {
                    this.page = MainPage;
                    return;
                }
                else if (userAction.Equals("0") && this.User != null)
                {
                    this.page = SignOff;
                    return;
                }
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Constructor that sets user,controller and page
 /// </summary>
 public ConsoleUI(IRegisteredUser user, IController controller)
 {
     this.User       = user;
     this.Controller = controller;
     this.page       = MainPage;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Output page with information about current user and change information in current users profile
        /// </summary>
        private void ChangePersonalInformation(string userEmail)
        {
            var user = this.Controller.UserController.GetUser(userEmail);

            if (user == null)
            {
                return;
            }
            var newUser = new UsersViewModel()
            {
                UserName = user.UserName, Email = user.Email, Password = user.Password
            };

            while (true)
            {
                this.OutputUser(newUser);
                Console.WriteLine("name - to change username");
                Console.WriteLine("email -to change email");
                Console.WriteLine("password - to change password");
                Console.WriteLine("update - to save changes");
                Console.WriteLine("main - go to main page");
                Console.WriteLine("0 - Exit");

                this.userAction = this.GetUserText();
                if (userAction.Equals("name"))
                {
                    this.userAction = this.GetUserText();
                    if (Regex.IsMatch(userAction, @"(\d|\w){6,12}"))
                    {
                        newUser.UserName = userAction;
                    }
                }
                else if (userAction.Equals("email"))
                {
                    this.userAction = this.GetUserText();
                    if (ConsoleUI.IsValidEmail(userAction))
                    {
                        newUser.Email = userAction;
                    }
                }
                else if (userAction.Equals("password"))
                {
                    this.userAction = this.GetUserText();
                    if (Regex.IsMatch(userAction, @"(\d|\w){6,12}"))
                    {
                        newUser.Password = userAction;
                    }
                }
                else if (userAction.Equals("update"))
                {
                    var update = this.Controller.UserController.UpdateUser(user, newUser);
                    if (update == null)
                    {
                        Console.WriteLine("Update failed. try another email");
                    }
                    else
                    {
                        if (user.Email.Equals(this.User.Email))
                        {
                            this.User = update;
                        }
                        this.page = MainPage;
                        return;
                    }
                }
                else if (userAction.Equals("main"))
                {
                    this.page = MainPage;
                    return;
                }
                else if (userAction.Equals("0") && this.User != null)
                {
                    this.page = SignOff;
                    return;
                }
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Set current user as guest and sends to main page
 /// </summary>
 private void SignOff()
 {
     this.User = null;
     this.page = MainPage;
 }