示例#1
0
        /// <summary>
        /// Allows admin user to set the amount of a book
        /// </summary>
        /// <param name="adminId"></param>
        private void SetAmount(int adminId)
        {
            new Book().FindAllAvailableBooks();
            AdminView.SetAmountPage();
            MessageViews.DisplayReturnMessage();

            var bookId = InputHelper.ParseInput();

            if (bookId == 0)
            {
                return;
            }

            var newAmount = InputHelper.ParseInput();

            WebbShopAPI api    = new WebbShopAPI();
            bool        result = api.SetAmount(adminId, bookId, newAmount);

            if (result)
            {
                MessageViews.DisplaySuccessMessage();
                return;
            }

            MessageViews.DisplayErrorMessage();
        }
示例#2
0
        /// <summary>
        /// Allows an admin user to update an existing book
        /// </summary>
        /// <param name="adminId"></param>
        private void UpdateBook(int adminId)
        {
            new Book().FindAllAvailableBooks();
            MessageViews.DisplaySelectMessage();
            MessageViews.DisplayReturnMessage();

            var bookId = InputHelper.ParseInput();

            if (bookId == 0)
            {
                return;
            }

            AdminView.UpdateBookPage();
            var title  = Console.ReadLine();
            var author = Console.ReadLine();
            var price  = InputHelper.ParseInput();

            if (title != "" && author != "" && price != 0)
            {
                WebbShopAPI api    = new WebbShopAPI();
                bool        result = api.UpdateBook(adminId, bookId, title, author, price);
                if (result)
                {
                    MessageViews.DisplaySuccessMessage();
                    return;
                }
            }

            MessageViews.DisplayErrorMessage();
        }
示例#3
0
        /// <summary>
        /// Allows admin user to add a new user
        /// </summary>
        /// <param name="adminId"></param>
        private void AddUser(int adminId)
        {
            ManageAccountViews.AddAccount();
            var userName = Console.ReadLine();
            var password = Console.ReadLine();

            if (userName != "" && password != "")
            {
                WebbShopAPI api    = new WebbShopAPI();
                var         result = api.AddUser(adminId, userName, password);
                if (result)
                {
                    MessageViews.DisplaySuccessMessage();
                    return;
                }
            }
            if (userName != "" && password == "")
            {
                WebbShopAPI api    = new WebbShopAPI();
                var         result = api.AddUser(adminId, userName);
                if (result)
                {
                    MessageViews.DisplaySuccessMessage();
                    return;
                }
            }

            ManageAccountViews.RegisterFailed();
        }
示例#4
0
        /// <summary>
        /// Allows admin user to update an existing category
        /// </summary>
        /// <param name="adminId"></param>
        private void UpdateCategory(int adminId)
        {
            new Book().ViewAllCategories();
            MessageViews.DisplaySelectMessage();
            MessageViews.DisplayReturnMessage();

            var categoryId = InputHelper.ParseInput();

            if (categoryId == 0)
            {
                return;
            }

            AdminView.UpdateCategoryPage();
            var genere = Console.ReadLine();

            if (genere != "")
            {
                WebbShopAPI api    = new WebbShopAPI();
                var         result = api.UpdateCategory(adminId, categoryId, genere);
                if (result)
                {
                    MessageViews.DisplaySuccessMessage();
                    return;
                }
            }

            MessageViews.DisplayErrorMessage();
        }
示例#5
0
        /// <summary>
        /// Allows an admin user to add a book to category
        /// </summary>
        /// <param name="adminId"></param>
        private void AddBookToCategory(int adminId)
        {
            AdminView.AddBookCategory();
            new Book().SearchBooksByTitle();
            MessageViews.DisplaySelectMessage();
            var bookId = InputHelper.ParseInput();

            new Book().ViewAllCategories();
            MessageViews.DisplaySelectMessage();
            MessageViews.DisplayReturnMessage();

            var categoryId = InputHelper.ParseInput();

            if (categoryId == 0)
            {
                return;
            }

            if (bookId != 0 && categoryId != 0)
            {
                WebbShopAPI api    = new WebbShopAPI();
                var         result = api.AddBookToCategory(adminId, bookId, categoryId);
                if (result)
                {
                    MessageViews.DisplaySuccessMessage();
                    return;
                }
            }

            MessageViews.DisplayErrorMessage();
        }
示例#6
0
 public void OnFinishEditButtonClick()
 {
     inputPanel.SetActive(true);
     finishEditButton.SetActive(false);
     foreach (var messageView in MessageViews.Where(x => x.IsOwnersMessage))
     {
         messageView.HideRemoveButton();
     }
 }
示例#7
0
        private void AddMessage <T>(T messageData, MessageViewsPool pool) where T : ChatMessage
        {
            var messageView = pool.GetChatView();

            messageView.FillWithInfo(messageData);
            messageView.onRemoveButtonClickEvent.AddListener(() => { DeleteMessageCall.Invoke(messageData.Id); });
            messageView.ShowWithAnimation();
            MessageViews.Add(messageView);
            CheckMessagesBlock(MessageViews.IndexOf(messageView));
            messageView.transform.SetAsLastSibling();
        }
示例#8
0
        /// <summary>
        /// Allows an admin user to view all sold books
        /// </summary>
        /// <param name="adminId"></param>
        private void ViewAllSoldItems(int adminId)
        {
            WebbShopAPI api             = new WebbShopAPI();
            var         listOfSoldItems = api.SoldItems(adminId);

            if (listOfSoldItems != null)
            {
                AdminView.DisplaySoldItems(listOfSoldItems);
                return;
            }

            MessageViews.DisplayErrorMessage();
        }
示例#9
0
        /// <summary>
        /// Allows you to view details for a specific book
        /// </summary>
        /// <param name="bookId"></param>
        public void ViewDetails(int bookId)
        {
            WebbShopAPI api         = new WebbShopAPI();
            var         bookDetails = api.GetBook(bookId);

            if (bookDetails != string.Empty)
            {
                BookViews.DisplayDetails(bookDetails);
                return;
            }

            MessageViews.DisplayErrorMessage();
        }
示例#10
0
        /// <summary>
        /// Allows you to view all available books
        /// </summary>
        public void FindAllAvailableBooks()
        {
            var listOfBooks = GetAllBooks();

            if (listOfBooks.Count != 0)
            {
                var sortBookList = listOfBooks.OrderBy(b => b.ID).ToList();
                BookViews.DisplayAvailableBooks(sortBookList);
                return;
            }

            MessageViews.DisplayErrorMessage();
        }
示例#11
0
        /// <summary>
        /// Allows admin user to view the sum of all sold books
        /// </summary>
        /// <param name="adminId"></param>
        private void ViewTotalIncome(int adminId)
        {
            WebbShopAPI api         = new WebbShopAPI();
            var         totalIncome = api.MoneyEarned(adminId);

            if (totalIncome != 0)
            {
                AdminView.DisplayMoneyEarned(totalIncome);
                return;
            }

            MessageViews.DisplayErrorMessage();
        }
示例#12
0
        /// <summary>
        /// Allows an admin user to see which customer bought the most books
        /// </summary>
        /// <param name="adminId"></param>
        private void ViewBestCustomer(int adminId)
        {
            WebbShopAPI api        = new WebbShopAPI();
            var         customerId = api.BestCustomer(adminId);

            if (customerId != 0)
            {
                AdminView.DisplayBestCustomer(customerId);
                return;
            }

            MessageViews.DisplayErrorMessage();
        }
示例#13
0
        /// <summary>
        /// Allows an admin user to view all users
        /// </summary>
        /// <param name="adminId"></param>
        private void ViewAllUsers(int adminId)
        {
            WebbShopAPI api         = new WebbShopAPI();
            var         listOfUsers = api.ListUsers(adminId);

            if (listOfUsers != null)
            {
                var sortUserList = listOfUsers.OrderBy(u => u.ID).ToList();
                AdminView.DisplayUsers(sortUserList);
                return;
            }

            MessageViews.DisplayErrorMessage();
        }
示例#14
0
        /// <summary>
        /// Allows you to view all book categories
        /// </summary>
        public void ViewAllCategories()
        {
            WebbShopAPI api = new WebbShopAPI();
            var         listOfCategories = api.GetCategories().ToList();

            if (listOfCategories != null)
            {
                var sortCategoryList = listOfCategories.OrderBy(c => c.ID).ToList();
                BookViews.DisplayCategoryList(sortCategoryList);
                return;
            }

            MessageViews.DisplayErrorMessage();
        }
示例#15
0
        /// <summary>
        /// Allows you to purchase chosen book
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="bookId"></param>
        public void PurchaseBook(int userId, int bookId)
        {
            WebbShopAPI api = new WebbShopAPI();

            if (userId != 0 && bookId != 0)
            {
                var result = api.BuyBook(userId, bookId);
                if (result)
                {
                    MessageViews.DisplaySuccessMessage();
                    return;
                }
            }
            PurchaseViews.DisplayErrorMessage();
        }
示例#16
0
        /// <summary>
        /// Runs the home functionality page
        /// </summary>
        public void Run()
        {
            Seeder.Seed();
            bool keepGoing = true;

            while (keepGoing)
            {
                HomeView.MainMeny();
                var input = InputHelper.ParseInput();
                if (userId > 0)
                {
                    WebbShopAPI api = new WebbShopAPI();
                    api.Ping(userId);
                }
                switch (input)
                {
                case 1:
                    userId = new Login().Run();
                    break;

                case 2:
                    new User().RegisterAccount();
                    break;

                case 3:
                    new Book().Run();
                    break;

                case 4:
                    new Purchase().Run(userId);
                    break;

                case 5:
                    userId = new Admin().Run();
                    break;

                case 6:
                    new Logout().Run(userId);
                    keepGoing = false;
                    break;

                default:
                    MessageViews.DisplayNonAvailableMessage();
                    break;
                }
            }
        }
示例#17
0
        /// <summary>
        /// Allows you to search for a specific category
        /// </summary>
        public void SearchFunctionCategories()
        {
            BookViews.SearchPage();
            var keyword = Console.ReadLine();

            if (keyword != "")
            {
                WebbShopAPI api = new WebbShopAPI();
                var         listOfCategories = api.GetCategories(keyword).ToList();
                if (listOfCategories != null)
                {
                    BookViews.DisplayCategoryList(listOfCategories);
                    return;
                }
            }

            MessageViews.DisplayErrorMessage();
        }
示例#18
0
        /// <summary>
        /// Allows you to search for books based to title
        /// </summary>
        public void SearchBooksByTitle()
        {
            BookViews.SearchPage();
            var keyword = Console.ReadLine();

            if (keyword != "")
            {
                WebbShopAPI api         = new WebbShopAPI();
                var         listOfBooks = api.GetBooks(keyword).ToList();
                if (listOfBooks != null)
                {
                    BookViews.DisplayBookList(listOfBooks);
                    return;
                }
            }

            MessageViews.DisplayErrorMessage();
        }
示例#19
0
        protected override void RemoveMessage(int messageId)
        {
            var index = MessageViews.FindIndex(x => x.Id == messageId);

            if (index < 0)
            {
                return;
            }
            var message = MessageViews[index];

            message.HideWithAnimation(() =>
            {
                message.gameObject.GetComponent <MessageViewsPool.PolledObject>()?
                .ReturnToPool();
                MessageViews.Remove(message);
                CheckMessagesBlock(index);
            });
        }
示例#20
0
        /// <summary>
        /// Allows admin user to add a new category
        /// </summary>
        /// <param name="adminId"></param>
        private void AddCategory(int adminId)
        {
            AdminView.AddCategoryPage();
            var genere = Console.ReadLine();

            if (genere != "")
            {
                WebbShopAPI api    = new WebbShopAPI();
                var         result = api.AddCategory(adminId, genere);
                if (result)
                {
                    MessageViews.DisplaySuccessMessage();
                    return;
                }
            }

            MessageViews.DisplayErrorMessage();
        }
示例#21
0
        /// <summary>
        /// Allows an admin user to find another user
        /// </summary>
        /// <param name="adminId"></param>
        private void FindUser(int adminId)
        {
            AdminView.SearchPage();
            var keyword = Console.ReadLine();

            if (keyword != "")
            {
                WebbShopAPI api         = new WebbShopAPI();
                var         listOfUsers = api.FindUser(adminId, keyword);
                if (listOfUsers != null)
                {
                    var sortUserList = listOfUsers.OrderBy(u => u.ID).ToList();
                    AdminView.DisplayUsers(sortUserList);
                    return;
                }
            }

            MessageViews.DisplayErrorMessage();
        }
示例#22
0
        /// <summary>
        /// Runs the purchase functionality page
        /// </summary>
        /// <param name="userId"></param>
        public void Run(int userId)
        {
            PurchaseViews.StartPage();

            bool keepGoing = true;

            while (keepGoing)
            {
                new Book().FindAllAvailableBooks();
                MessageViews.DisplaySelectMessage();
                MessageViews.DisplayReturnMessage();
                var bookId = InputHelper.ParseInput();
                if (bookId == 0)
                {
                    break;
                }

                PurchaseViews.DisplayPurchaseMeny();
                MessageViews.DisplayReturnMessage();
                var input = InputHelper.ParseInput();
                if (input == 0)
                {
                    break;
                }

                switch (input)
                {
                case 1:
                    ViewDetails(bookId);
                    break;

                case 2:
                    PurchaseBook(userId, bookId);
                    keepGoing = false;
                    break;

                default:
                    MessageViews.DisplayNonAvailableMessage();
                    break;
                }
            }
        }
示例#23
0
        /// <summary>
        /// Runs the book functionality page
        /// </summary>
        public void Run()
        {
            bool keepGoing = true;

            while (keepGoing)
            {
                BookViews.BookMeny();
                var input = InputHelper.ParseInput();

                switch (input)
                {
                case 1:
                    ViewAllCategories();
                    break;

                case 2:
                    SearchFunctionCategories();
                    break;

                case 3:
                    SearchBooksByAuthor();
                    break;

                case 4:
                    SearchBooksByTitle();
                    break;

                case 5:
                    FindAllAvailableBooks();
                    break;

                case 6:
                    keepGoing = false;
                    break;

                default:
                    MessageViews.DisplayNonAvailableMessage();
                    break;
                }
            }
        }
示例#24
0
        /// <summary>
        /// Allows an admin user to add a new book
        /// </summary>
        /// <param name="adminId"></param>
        private void AddBook(int adminId)
        {
            AdminView.AddBookPage();
            var title  = Console.ReadLine();
            var author = Console.ReadLine();
            var price  = InputHelper.ParseInput();
            var amount = InputHelper.ParseInput();

            if (title != "" && author != "" && price != 0 && amount != 0)
            {
                WebbShopAPI api    = new WebbShopAPI();
                bool        result = api.AddBook(adminId, title, author, price, amount);
                if (result)
                {
                    MessageViews.DisplaySuccessMessage();
                    return;
                }
            }

            MessageViews.DisplayErrorMessage();
        }
示例#25
0
        /// <summary>
        /// Allows admin user to demote another admin user
        /// </summary>
        /// <param name="adminId"></param>
        private void DemoteUser(int adminId)
        {
            ViewAllUsers(adminId);
            MessageViews.DisplaySelectMessage();
            MessageViews.DisplayReturnMessage();
            var userId = InputHelper.ParseInput();

            if (userId == 0)
            {
                return;
            }

            WebbShopAPI api    = new WebbShopAPI();
            bool        result = api.Demote(adminId, userId);

            if (result)
            {
                MessageViews.DisplaySuccessMessage();
                return;
            }
            MessageViews.DisplayErrorMessage();
        }
示例#26
0
        /// <summary>
        /// Allows admin user to delete book category
        /// </summary>
        /// <param name="adminId"></param>
        private void DeleteCategory(int adminId)
        {
            new Book().ViewAllCategories();
            MessageViews.DisplaySelectMessage();
            MessageViews.DisplayReturnMessage();

            var categoryId = InputHelper.ParseInput();

            if (categoryId == 0)
            {
                return;
            }

            WebbShopAPI api    = new WebbShopAPI();
            var         result = api.DeleteCategory(adminId, categoryId);

            if (result)
            {
                MessageViews.DisplaySuccessMessage();
                return;
            }

            MessageViews.DisplayErrorMessage();
        }
示例#27
0
        /// <summary>
        /// Allows admin user to delete book
        /// </summary>
        /// <param name="adminId"></param>
        private void DeleteBook(int adminId)
        {
            new Book().FindAllAvailableBooks();
            MessageViews.DisplaySelectMessage();
            MessageViews.DisplayReturnMessage();

            var bookId = InputHelper.ParseInput();

            if (bookId == 0)
            {
                return;
            }

            WebbShopAPI api    = new WebbShopAPI();
            bool        result = api.DeleteBook(adminId, bookId);

            if (result)
            {
                MessageViews.DisplaySuccessMessage();
                return;
            }

            MessageViews.DisplayErrorMessage();
        }
示例#28
0
        /// <summary>
        /// Runs the Admin funtionality-page
        /// </summary>
        /// <returns>integer, user id if admin, 0 if not</returns>
        public int Run()
        {
            AdminView.StartPage();
            userId = new Login().Run();
            if (userId == 0)
            {
                return(0);
            }

            var result = CheckAdmin(userId);

            if (!result)
            {
                AdminView.VerifyAdminFailed();
                return(0);
            }

            bool keepGoing = true;

            while (keepGoing)
            {
                AdminView.AdminPage();
                var input = InputHelper.ParseInput();

                switch (input)
                {
                case 1:
                    AddBook(userId);
                    break;

                case 2:
                    SetAmount(userId);
                    break;

                case 3:
                    ViewAllUsers(userId);
                    break;

                case 4:
                    FindUser(userId);
                    break;

                case 5:
                    UpdateBook(userId);
                    break;

                case 6:
                    DeleteBook(userId);
                    break;

                case 7:
                    AddCategory(userId);
                    break;

                case 8:
                    AddBookToCategory(userId);
                    break;

                case 9:
                    UpdateCategory(userId);
                    break;

                case 10:
                    DeleteCategory(userId);
                    break;

                case 11:
                    AddUser(userId);
                    break;

                case 12:
                    ViewAllSoldItems(userId);
                    break;

                case 13:
                    ViewTotalIncome(userId);
                    break;

                case 14:
                    ViewBestCustomer(userId);
                    break;

                case 15:
                    PromoteUser(userId);
                    break;

                case 16:
                    DemoteUser(userId);
                    break;

                case 17:
                    ActivateUser(userId);
                    break;

                case 18:
                    InactivateUser(userId);
                    break;

                case 19:
                    keepGoing = false;
                    break;

                default:
                    MessageViews.DisplayNonAvailableMessage();
                    break;
                }
            }
            return(userId);
        }