Esempio n. 1
0
        public void Checkout(ClothesShopContext db)
        {
            Console.Clear();
            Console.WriteLine("CHECKOUT");
            Console.WriteLine();
            Basket.ShowBasket();
            Console.WriteLine();
            string shippingAddress = User.ChooseShippingAddress(db);

            if (User.PayForGoods(db, Basket.TotalAmount))
            {
                var sale = new Sale();
                sale.AddSale(db, Basket.TotalAmount, shippingAddress, Basket.BasketItems, User.UserId);
                sale.ChangeSizeQuantityInDb(db, View.Type, Basket.BasketItems);
            }
            Basket.BasketItems.Clear();
            if (User.UserName == "UNKNOWN")
            {
                ActionMenu.ChooseUnregisterUserActions(db);
            }
            else
            {
                ActionMenu.ChooseUserActions(db);
            }
        }
Esempio n. 2
0
        public void ChooseEmptyBasketAction(ClothesShopContext db)
        {
            Console.WriteLine();
            Console.WriteLine("Please choose your action:");
            Console.WriteLine("1 - Back to Item View");
            Console.WriteLine("2 - Back to HomePage");
            int choice = GeneralStaticClass.ReadIntNumber();

            while (choice != 1 && choice != 2)
            {
                Console.WriteLine("There is no such choice");
                choice = GeneralStaticClass.ReadIntNumber();
            }
            switch (choice)
            {
            case 1:
                Console.Clear();
                BuyingClothes.View.ShowItem(db);
                ChooseItemAction(db);
                break;

            case 2:
                Console.Clear();
                BuyingClothes.ShowHome(db);
                break;

            default:
                Console.WriteLine("There is no such choice");
                break;
            }
        }
Esempio n. 3
0
        public bool PayForGoods(ClothesShopContext db, double payableAmount)
        {
            var userFirstName = db.Users.FirstOrDefault(u => u.UserId == UserId).Name;

            if (userFirstName != "UNKNOWN")
            {
                Console.WriteLine($"Please pay {payableAmount} EUR, {userFirstName}. Confirm? Y/N");
            }
            else
            {
                Console.WriteLine($"Please pay {payableAmount} EUR. Confirm? Y/N");
            }

            string paymentConfirmation = Console.ReadLine().ToUpper();

            while (paymentConfirmation != "Y" && paymentConfirmation != "N")
            {
                Console.WriteLine("Invalid choice. Try again.");
                paymentConfirmation = Console.ReadLine().ToUpper();
            }
            if (paymentConfirmation == "Y")
            {
                return(true);
            }
            else
            {
                Console.Clear();
                return(false);
            }
        }
Esempio n. 4
0
        public void ChooseCategoryAction(ClothesShopContext db)
        {
            Console.WriteLine();
            Console.WriteLine("Please choose your action:");
            Console.WriteLine("1 - View Item");
            Console.WriteLine("2 - Back to Categories");
            Console.WriteLine("3 - Back to HomePage");

            int choice = GeneralStaticClass.ReadIntNumber();

            while (choice != 1 && choice != 2 && choice != 3)
            {
                Console.WriteLine("There is no such choice");
                choice = GeneralStaticClass.ReadIntNumber();
            }
            switch (choice)
            {
            case 1:
                BuyingClothes.ShowItem(db);
                break;

            case 2:
                BuyingClothes.ShowCategories(db);
                break;

            case 3:
                Console.Clear();
                BuyingClothes.ShowHome(db);
                break;

            default:
                Console.WriteLine("There is no such choice");
                break;
            }
        }
Esempio n. 5
0
        public void ShowUserInfo(ClothesShopContext db)
        {
            var user = db.Users.FirstOrDefault(u => u.UserId == UserId);

            Console.WriteLine("PERSONAL DETAILS");
            Console.WriteLine();
            Console.WriteLine($"USERNAME: {user.UserName}");
            Console.WriteLine($"NAME: {user.Name}");
            Console.WriteLine($"SURNAME: {user.Surname}");
            Console.WriteLine($"ADDRESS: {user.Address}");
            Console.WriteLine($"EMAIL: {user.Email}");
            Console.WriteLine();
            Console.WriteLine("ORDER HISTORY");
            Console.WriteLine();
            var orders = db.Sales.Where(o => o.UserId == UserId);

            foreach (var order in orders)
            {
                Console.WriteLine(order.PurchaceDateTime);
                var purchasedItems = db.BasketItems.Where(i => i.SaleId == order.SaleId);
                foreach (var item in purchasedItems)
                {
                    Console.WriteLine($"{item.ClothingItem} ({item.Size}) Qty:{item.Quantity} {item.Amount} EUR");
                }
                Console.WriteLine();
            }
        }
Esempio n. 6
0
        public string ChooseShippingAddress(ClothesShopContext db)
        {
            var shippingAddress = db.Users.FirstOrDefault(a => a.UserId == UserId).Address;

            if (shippingAddress == "UNKNOWN")
            {
                Console.WriteLine("Please provide shipping address");
                shippingAddress = Console.ReadLine();
            }
            else
            {
                Console.WriteLine($"Current address: {shippingAddress}");
                Console.WriteLine("Ship to address? Y/N");
                string choice = Console.ReadLine().ToUpper();
                while (choice != "Y" && choice != "N")
                {
                    Console.WriteLine("Invalid choice");
                    choice = Console.ReadLine();
                }
                if (choice == "N")
                {
                    Console.WriteLine("Please provide shipping address");
                    shippingAddress = Console.ReadLine();
                }
            }

            return(shippingAddress);
        }
Esempio n. 7
0
        public void ChooseUserActions(ClothesShopContext db)
        {
            Console.WriteLine("Please choose your action:");
            Console.WriteLine("1 - User Information");
            Console.WriteLine("2 - Home Page");
            int choice = GeneralStaticClass.ReadIntNumber();

            while (choice != 1 && choice != 2)
            {
                Console.WriteLine("Invalid choice");
                choice = GeneralStaticClass.ReadIntNumber();
            }
            if (choice == 1)
            {
                Console.Clear();
                BuyingClothes.User.ShowUserInfo(db);
                Console.WriteLine();
                Console.WriteLine("Back to Home Page? Y/N");

                if (Console.ReadLine().ToUpper() == "Y")
                {
                    Console.Clear();
                    BuyingClothes.ShowHome(db);
                }
            }
            else
            {
                Console.Clear();
                BuyingClothes.ShowHome(db);
            }
        }
Esempio n. 8
0
        public void AddItemToBasket(ClothesShopContext db, int itemId)
        {
            var existantBasketItem = BasketItems.FirstOrDefault(b => b.ClothingItem == db.ClothingItems.First(c => c.ClothingItemId == itemId).Name&& b.Size == Size);

            if (existantBasketItem != null)
            {
                existantBasketItem.Quantity += Quantity;
                existantBasketItem.Amount    = (int)db.ClothingItems.First(c => c.ClothingItemId == itemId).Price *existantBasketItem.Quantity;
                Console.Clear();
                Console.WriteLine($"{existantBasketItem.ClothingItem} ({Size}) Qty:{Quantity} added to basket");
            }
            else
            {
                BasketItems.Add(new BasketItem()
                {
                    ClothingItem = db.ClothingItems.First(c => c.ClothingItemId == itemId).Name,
                    Size         = Size,
                    Quantity     = Quantity,
                    Amount       = (int)db.ClothingItems.First(c => c.ClothingItemId == itemId).Price *Quantity
                }
                                );
                Console.Clear();
                Console.WriteLine($"{BasketItems[BasketItems.Count() - 1].ClothingItem} ({Size}) Qty:{Quantity} added to basket");
            }
        }
Esempio n. 9
0
 public void PurchaceClothes()
 {
     using (var db = new ClothesShopContext())
     {
         Console.WriteLine("Welcome to the online clothing shop!");
         ActionMenu.ChooseStartingUserAction(db);
     }
 }
Esempio n. 10
0
        public void ChooseItemAction(ClothesShopContext db)
        {
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Please choose your action:");
            Console.WriteLine("1 - Add Item to Basket");
            Console.WriteLine("2 - Go to Basket");
            Console.WriteLine("3 - Back to Category Items");
            Console.WriteLine("4 - Back to HomePage");

            int choice = GeneralStaticClass.ReadIntNumber();

            while (choice != 1 && choice != 2 && choice != 3 && choice != 4)
            {
                Console.WriteLine("There is no such choice");
                choice = GeneralStaticClass.ReadIntNumber();
            }
            switch (choice)
            {
            case 1:
                BuyingClothes.Basket.ChooseSizeQuantity(db, BuyingClothes.View.ItemId);
                if (BuyingClothes.Basket.Quantity == 0)
                {
                    BuyingClothes.View.ShowItem(db);
                    ChooseItemAction(db);
                }
                else
                {
                    BuyingClothes.Basket.AddItemToBasket(db, BuyingClothes.View.ItemId);
                    ChooseItemActionAfterAddingToBasket(db);
                }
                break;

            case 2:
                BuyingClothes.ShowBasket(db);
                break;

            case 3:
                BuyingClothes.View.ShowClothingCategoryItems(db);
                ChooseCategoryAction(db);
                break;

            case 4:
                Console.Clear();
                BuyingClothes.ShowHome(db);
                break;

            default:
                Console.WriteLine("There is no such choice");
                break;
            }
        }
Esempio n. 11
0
        public void ChooseFullBasketAction(ClothesShopContext db)
        {
            Console.WriteLine();
            Console.WriteLine("Please choose your action:");
            Console.WriteLine("1 - Proceed to Checkout");
            Console.WriteLine("2 - Update Basket Item");
            Console.WriteLine("3 - Delete Basket Item(s)");
            Console.WriteLine("4 - Back to Item View");
            Console.WriteLine("5 - Back to HomePage");

            int choice = GeneralStaticClass.ReadIntNumber();

            while (choice != 1 && choice != 2 && choice != 3 && choice != 4 && choice != 5)
            {
                Console.WriteLine("There is no such choice");
                choice = GeneralStaticClass.ReadIntNumber();
            }

            switch (choice)
            {
            case 1:
                BuyingClothes.Checkout(db);
                break;

            case 2:
                BuyingClothes.Basket.UpdateItem(db);
                Console.WriteLine("Basket updated");
                BuyingClothes.ShowBasket(db);
                break;

            case 3:
                BuyingClothes.Basket.DeleteItem();
                BuyingClothes.ShowBasket(db);
                break;

            case 4:
                Console.Clear();
                BuyingClothes.View.ShowItem(db);
                ChooseItemAction(db);
                break;

            case 5:
                Console.Clear();
                BuyingClothes.ShowHome(db);
                break;

            default:
                Console.WriteLine("There is no such choice");
                break;
            }
        }
Esempio n. 12
0
        public void FindDbClothingItemTypes(ClothesShopContext db)
        {
            foreach (var item in db.ClothingItems)
            {
                if (!Types.Values.Contains(item.Type))
                {
                    Types.Add(Types.Count() + 1, item.Type);
                }
            }

            foreach (var type in Types)
            {
                Console.WriteLine($"{type.Key} - {type.Value}");
            }
        }
Esempio n. 13
0
        public void ShowItem(ClothesShopContext db)
        {
            Console.Clear();
            var item = db.ClothingItems.FirstOrDefault(i => i.ClothingItemId == ItemId);

            if (item != null)
            {
                Console.WriteLine($"ID: {item.ClothingItemId} {item.Name} {item.Price} EUR");
                Console.WriteLine("Available sizes: ");
                foreach (var size in db.ClothingSizes.Where(s => s.ClothingItemId == ItemId))
                {
                    Console.Write($"{size.Size}, ");
                }
            }
        }
Esempio n. 14
0
        public void ChooseUnregisterUserActions(ClothesShopContext db)
        {
            Console.WriteLine("Back to Home Page? Y/N");
            string choice = Console.ReadLine().ToUpper();

            while (choice != "Y" && choice != "N")
            {
                Console.WriteLine("Invalid choice");
                choice = Console.ReadLine().ToUpper();
            }
            if (choice == "Y")
            {
                BuyingClothes.ShowHome(db);
            }
        }
Esempio n. 15
0
 public void ShowBasket(ClothesShopContext db)
 {
     Console.Clear();
     Console.WriteLine("BASKET VIEW");
     if (Basket.BasketItems.Count() == 0)
     {
         Console.WriteLine("Your basket is empty");
         ActionMenu.ChooseEmptyBasketAction(db);
     }
     else
     {
         Basket.ShowBasket();
         ActionMenu.ChooseFullBasketAction(db);
     }
 }
Esempio n. 16
0
        public void ShowHome(ClothesShopContext db)
        {
            var userFirstName = db.Users.FirstOrDefault(u => u.UserId == User.UserId).Name;

            if (userFirstName != "UNKNOWN")
            {
                Console.WriteLine($"Welcome to the online clothing shop {userFirstName}!");
            }
            else
            {
                Console.WriteLine($"Welcome to the online clothing shop!");
            }
            View.ShowTypes(db);
            View.AskUserTypeChoice();
            ShowCategories(db);
        }
Esempio n. 17
0
        public void ShowCategories(ClothesShopContext db)
        {
            View.ShowClothingItemCategories(db);
            Console.WriteLine($"{View.Categories.Count() + 1} - Back to HomePage");
            int categoryChoice = View.AskUserCategoryChoice();

            if (categoryChoice == View.Categories.Count() + 1)
            {
                Console.Clear();
                ShowHome(db);
            }
            else
            {
                View.ShowClothingCategoryItems(db);
                ActionMenu.ChooseCategoryAction(db);
            }
        }
Esempio n. 18
0
        public void LogIn(ClothesShopContext db)
        {
            Console.WriteLine("Please enter your username");
            string username = Console.ReadLine();

            var user = db.Users.FirstOrDefault(u => u.UserName == username);

            while (user == null || user.Name == "UNKNOWN")
            {
                Console.WriteLine("Wrong username. Try again!");
                username = Console.ReadLine();
                user     = db.Users.FirstOrDefault(u => u.UserName == username);
            }
            UserName = username;
            UserId   = user.UserId;
            Console.Clear();
        }
Esempio n. 19
0
        public void ChooseSizeQuantity(ClothesShopContext db, int itemId)
        {
            Console.WriteLine($"Please choose the size: ");
            string sizeChoice = Console.ReadLine().ToUpper();

            while (!db.ClothingSizes.Any(s => s.Size == sizeChoice && s.ClothingItemId == itemId))
            {
                Console.WriteLine("There is no such size. Please provide size");
                sizeChoice = Console.ReadLine().ToUpper();
            }
            Size = sizeChoice;
            var availableQuantity = db.ClothingSizes.First(q => q.Size == sizeChoice && q.ClothingItemId == itemId).Quantity;

            Console.WriteLine($"How many items you want to add to basket? Available: {availableQuantity}");
            Console.WriteLine("Type 0 to cancel");
            CheckQuantityAvailability(db.ClothingItems.First(c => c.ClothingItemId == itemId).Name, availableQuantity);
        }
Esempio n. 20
0
        public void ChooseItemActionAfterAddingToBasket(ClothesShopContext db)
        {
            Console.WriteLine();
            Console.WriteLine("Please choose your action:");
            Console.WriteLine("1 - Go to Basket");
            Console.WriteLine("2 - Back to Item View");
            Console.WriteLine("3 - Back to Category View");
            Console.WriteLine("4 - Back to Home Page");

            int choice = GeneralStaticClass.ReadIntNumber();

            while (choice != 1 && choice != 2 && choice != 3 && choice != 4)
            {
                Console.WriteLine("There is no such choice");
                choice = GeneralStaticClass.ReadIntNumber();
            }

            switch (choice)
            {
            case 1:
                Console.Clear();
                BuyingClothes.ShowBasket(db);
                break;

            case 2:
                Console.Clear();
                BuyingClothes.View.ShowItem(db);
                ChooseItemAction(db);
                break;

            case 3:
                Console.Clear();
                BuyingClothes.ShowCategories(db);
                break;

            case 4:
                Console.Clear();
                BuyingClothes.ShowHome(db);
                break;

            default:
                Console.WriteLine("There is no such choice");
                break;
            }
        }
Esempio n. 21
0
        public int GetNewItemQuantity(int itemToUpdate, ClothesShopContext db)
        {
            Console.WriteLine($"Updating item: {BasketItems[itemToUpdate].ClothingItem} ({BasketItems[itemToUpdate].Size})");
            var clothingItemToUpdate = BasketItems[itemToUpdate].ClothingItem;
            var sizeToUpdate         = BasketItems[itemToUpdate].Size;
            var dbClothingItemId     = db.ClothingItems.FirstOrDefault(c => c.Name == clothingItemToUpdate).ClothingItemId;
            var availableQuantity    = db.ClothingSizes.FirstOrDefault(a => a.ClothingItemId == dbClothingItemId && a.Size == sizeToUpdate).Quantity;

            Console.WriteLine($"Please provide new quantity. Total items available: {availableQuantity}");
            int newQuantity = GeneralStaticClass.ReadIntNumber();

            while (newQuantity < 0 || newQuantity > availableQuantity)
            {
                Console.WriteLine($"Invalid quantity. Total items available: {availableQuantity}");
                newQuantity = GeneralStaticClass.ReadIntNumber();
            }
            return(newQuantity);
        }
Esempio n. 22
0
        public void Register(ClothesShopContext db)
        {
            Console.WriteLine("Please choose your username");

            string userName = Console.ReadLine();

            while (db.Users.Any(u => u.UserName == userName))
            {
                Console.Clear();
                Console.WriteLine("Such username already exists");
                Console.WriteLine("Please choose your username");
                userName = Console.ReadLine();
            }
            UserName = userName;
            Console.WriteLine("Please provide your Name");
            Name = Console.ReadLine();
            Console.WriteLine("Please provide your Surname");
            Surname = Console.ReadLine();
            Console.WriteLine("Please provide your Address");
            Address = Console.ReadLine();
            Console.WriteLine("Please provide your Email");

            string email = Console.ReadLine();

            while (!email.Contains("@") || !email.Contains("."))
            {
                Console.WriteLine("Invalid email. Please provide email");
                email = Console.ReadLine();
            }
            while (db.Users.Any(u => u.Email == email))
            {
                Console.WriteLine("User with such email address already exists");
                Console.WriteLine("Please provide your Email");
                email = Console.ReadLine();
            }

            Email = email;
            db.Users.Add(new User {
                Address = Address, Email = Email, Name = Name, Surname = Surname, UserName = UserName
            });
            db.SaveChanges();
            UserId = db.Users.FirstOrDefault(a => a.UserName == UserName).UserId;
            Console.Clear();
        }
Esempio n. 23
0
        public void UpdateItem(ClothesShopContext db)
        {
            Console.Clear();
            Console.WriteLine("BASKET VIEW");
            ShowBasket();
            Console.WriteLine();
            int itemToUpdate = GetItemToUpdateNo();
            int newQuantity  = GetNewItemQuantity(itemToUpdate, db);

            if (newQuantity == 0)
            {
                BasketItems.RemoveAt(itemToUpdate);
            }
            else
            {
                BasketItems[itemToUpdate].Amount   = BasketItems[itemToUpdate].Amount / BasketItems[itemToUpdate].Quantity * newQuantity;
                BasketItems[itemToUpdate].Quantity = newQuantity;
            }
        }
Esempio n. 24
0
        public void ChooseStartingUserAction(ClothesShopContext db)
        {
            Console.WriteLine();
            Console.WriteLine("Please choose your action:");
            Console.WriteLine("1 - Log in");
            Console.WriteLine("2 - Register");
            Console.WriteLine("3 - Shop without registration");

            int choice = GeneralStaticClass.ReadIntNumber();

            while (choice != 1 && choice != 2 && choice != 3)
            {
                Console.WriteLine("There is no such choice");
                choice = GeneralStaticClass.ReadIntNumber();
            }

            switch (choice)
            {
            case 1:
                Console.Clear();
                BuyingClothes.User.LogIn(db);
                ChooseUserActions(db);
                break;

            case 2:
                Console.Clear();
                BuyingClothes.User.Register(db);
                Console.WriteLine("User registered, please log in");
                BuyingClothes.User.LogIn(db);
                ChooseUserActions(db);
                break;

            case 3:
                Console.Clear();
                BuyingClothes.User.SetUnregisteredShopping(db);
                BuyingClothes.ShowHome(db);
                break;

            default:
                Console.WriteLine("There is no such choice");
                break;
            }
        }
Esempio n. 25
0
        public void ShowClothingItemCategories(ClothesShopContext db)
        {
            Console.Clear();
            Console.WriteLine($"{Type} categories:");

            foreach (var item in db.ClothingItems.Where(i => i.Type == Type))
            {
                if (!Categories.Values.Contains(item.Category))
                {
                    Categories.Add(Categories.Count() + 1, item.Category);
                }
            }
            if (!Categories.Values.Contains("View All"))
            {
                Categories.Add(Categories.Count() + 1, "View All");
            }

            foreach (var category in Categories)
            {
                Console.WriteLine($"{category.Key} - {category.Value}");
            }
        }
Esempio n. 26
0
 public void AddSale(ClothesShopContext db, double totalAmount, string shippingAddress, List <BasketItem> BasketItems, int userId)
 {
     db.Sales.Add(new Sale {
         Amount = totalAmount, ShippingAdress = shippingAddress, PurchaceDateTime = DateTime.Now, UserId = userId
     });
     db.SaveChanges();
     foreach (var item in BasketItems)
     {
         db.BasketItems.Add(
             new BasketItem
         {
             Amount       = item.Amount,
             ClothingItem = item.ClothingItem,
             Quantity     = item.Quantity,
             Size         = item.Size,
             SaleId       = db.Sales.Count()
         }
             );
     }
     db.SaveChanges();
     Console.Clear();
     Console.WriteLine("Thank you for your purchace!");
 }
Esempio n. 27
0
 public void ShowClothingCategoryItems(ClothesShopContext db)
 {
     Console.Clear();
     if (Category == "View All")
     {
         ItemIds = new List <int>();
         Console.WriteLine($"{Type} {Category}:");
         foreach (var item in db.ClothingItems.Where(i => i.Type == Type))
         {
             Console.WriteLine($"ID: {item.ClothingItemId} {item.Name} {item.Price} EUR");
             ItemIds.Add(item.ClothingItemId);
         }
     }
     else
     {
         ItemIds = new List <int>();
         Console.WriteLine($"{Type} {Category}:");
         foreach (var item in db.ClothingItems.Where(i => i.Type == Type && i.Category == Category))
         {
             Console.WriteLine($"ID: {item.ClothingItemId} {item.Name} {item.Price} EUR");
             ItemIds.Add(item.ClothingItemId);
         }
     }
 }
Esempio n. 28
0
        public void ChangeSizeQuantityInDb(ClothesShopContext db, string type, List <BasketItem> basketItems)
        {
            int itemId;

            foreach (var item in basketItems)
            {
                itemId = db.ClothingItems.FirstOrDefault(c => c.Name == item.ClothingItem && c.Type == type).ClothingItemId;
                var dbItem = db.ClothingSizes.FirstOrDefault(d => d.Size == item.Size && d.ClothingItemId == itemId);
                if (dbItem != null)
                {
                    dbItem.Quantity -= item.Quantity;
                    if (dbItem.Quantity == 0) // if all quantity for size sold
                    {
                        db.ClothingSizes.Remove(dbItem);
                        db.SaveChanges();
                        if (!db.ClothingSizes.Any(a => a.ClothingItemId == itemId)) // if no sizes for clothingItem left
                        {
                            db.ClothingItems.Remove(db.ClothingItems.FirstOrDefault(a => a.ClothingItemId == itemId));
                        }
                    }
                }
            }
            db.SaveChanges();
        }
Esempio n. 29
0
 public void ShowItem(ClothesShopContext db)
 {
     View.AskUserItemChoice();
     View.ShowItem(db);
     ActionMenu.ChooseItemAction(db);
 }
Esempio n. 30
0
 public void SetUnregisteredShopping(ClothesShopContext db)
 {
     UserId   = db.Users.FirstOrDefault(a => a.UserName == "UNKNOWN").UserId;
     UserName = "******";
 }