예제 #1
0
 public static string CheckIfTypeExists(string foodType)
 {
     using (var context = new StoreContext())
     {
         var types = context.ProductTypes.ToList();
         foreach (var item in types)
         {
             while (foodType.ToLower() == item.PropertyName.ToLower())
             {
                 Console.WriteLine(Startup.languageInterface[72]);
                 Console.WriteLine(Startup.languageInterface[0]);
                 ConsoleKey answer = InputChecker.CheckIfEnter();
                 if (answer == ConsoleKey.Enter)
                 {
                     foodType = Console.ReadLine();
                 }
                 else
                 {
                     return(string.Empty);
                 }
             }
         }
     }
     return(foodType);
 }
예제 #2
0
        //bool correct;
        //Метод за създаване на нов обект
        //static List<string> languageInterface = Startup.languageInterface;
        public Product CreateNewProduct(List <Product> list, List <string> langageInterface)
        {
            Console.Write(langageInterface[12]);
            string brand = CheckIfItemExists(Console.ReadLine(), list);

            if (brand == string.Empty)
            {
                return(product);
            }
            Console.Write(langageInterface[13]);
            decimal price = InputChecker.CheckIfDecimal();

            Console.Write(langageInterface[14]);
            int inStock = InputChecker.CheckIfInt();

            Console.WriteLine(langageInterface[15]);
            int type = InputChecker.CheckTypeInput(0);

            Console.Write(langageInterface[16]);
            int maxStock = InputChecker.CheckIfInt();

            Console.Write(langageInterface[17]);
            decimal overcharge = InputChecker.CheckIfDecimal();

            product = new Product(brand, price, inStock, type, maxStock, overcharge);
            return(product);
        }
예제 #3
0
        //Проверка за съществуването да даден хранителен тип от foodType списъка в Product.cs


        //Проверка дали обекта съществува
        private string CheckIfItemExists(string brand)
        {
            using (var context = new StoreContext())
            {
                var productList = context.Products.ToList();
                foreach (var item in productList)
                {
                    while (brand == item.Brand)
                    {
                        Console.WriteLine(Startup.languageInterface[37]);
                        Console.WriteLine(Startup.languageInterface[0]);
                        ConsoleKey answer = InputChecker.CheckIfEnter();
                        if (answer == ConsoleKey.Enter)
                        {
                            brand = Console.ReadLine();
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                }
            }
            return(brand);
        }
예제 #4
0
        //Метод за създаване на нов обект
        public void CreateNewProduct(List <string> langageInterface)
        {
            Console.Write(langageInterface[12]);
            string brand = CheckIfItemExists(Console.ReadLine());

            if (brand == string.Empty)
            {
                return;
            }
            Console.Write(langageInterface[13]);
            decimal price = InputChecker.CheckIfDecimal();

            Console.WriteLine(langageInterface[15]);
            int type = InputChecker.CheckTypeInput(0);

            Console.Write(langageInterface[14]);
            int inStock = InputChecker.CheckIfInt();

            Console.Write(langageInterface[16]);
            int maxStock = InputChecker.CheckIfInt();

            Console.Write(langageInterface[17]);
            decimal overcharge = InputChecker.CheckIfDecimal();

            product = new Product(brand, price, inStock, type, maxStock, overcharge);

            using (var context = new StoreContext())
            {
                context.Products.Add(product);
                context.SaveChanges();
            }
        }
예제 #5
0
        //Метод за изтриване на обект от списъка с продукти
        public List <Product> DeleteItem(List <Product> list)
        {
            Console.WriteLine(Startup.languageInterface[22]);
            ConsoleKey check = InputChecker.CheckIfEnter();

            if (check == ConsoleKey.Enter)
            {
                int index = SellAndRestock.FindItemIndex(list);
                Console.WriteLine(Startup.languageInterface[23], list[index].Brand);
                check = InputChecker.CheckIfEnter();
                if (check == ConsoleKey.Enter)
                {
                    Console.WriteLine(Startup.languageInterface[24], list[index].Brand);
                    list.RemoveAt(index);
                }
                else
                {
                    Console.WriteLine(Startup.languageInterface[25], list[index].Brand);
                    return(list);
                }
            }
            else
            {
                Console.WriteLine(Startup.languageInterface[25]);
            }
            return(list);
        }
예제 #6
0
        //Метод за изтриване на обект от списъка с продукти
        public void DeleteItem()
        {
            Console.WriteLine(Startup.languageInterface[22]);
            ConsoleKey check = InputChecker.CheckIfEnter();

            if (check == ConsoleKey.Enter)
            {
                using (var context = new StoreContext())
                {
                    int index = SellAndRestock.FindItem();
                    Console.WriteLine(Startup.languageInterface[23], context.Products.Single(id => id.ProductID == index).Brand);
                    check = InputChecker.CheckIfEnter();
                    if (check == ConsoleKey.Enter)
                    {
                        var itemToDelete = context.Products.Single(id => id.ProductID == index);
                        Console.WriteLine(itemToDelete.Brand);
                        context.Products.Remove(itemToDelete);
                        context.SaveChanges();
                    }
                    else
                    {
                        Console.WriteLine(Startup.languageInterface[25]);
                        //return list;
                    }
                }
            }
            else
            {
                Console.WriteLine(Startup.languageInterface[25]);
            }
            //return list;
        }
예제 #7
0
        public void Sell()
        {
            List <int> shoppingCart = ShoppingCart();

            using (var context = new StoreContext())
            {
                var insertMoney = context.StoreMoney.First();
                foreach (var item in shoppingCart)
                {
                    var singleItem = context.Products.Single(id => id.ProductID == item);
                    Console.WriteLine(Startup.languageInterface[38], singleItem.Brand, singleItem.InStock);
                    int ammount = InputChecker.CheckIfInt(0, singleItem.InStock);
                    singleItem.InStock          -= ammount;
                    insertMoney.StoreCashSupply += (singleItem.Price * ammount)
                                                   + ((singleItem.Price * singleItem.Overcharge) * ammount);
                    var Newlog = ("Date: ", DateTime.Now,
                                  "Product Type: ", singleItem.Type,
                                  "Brand: ", singleItem.Brand,
                                  "Ammount: ", ammount,
                                  "Price: ", (singleItem.Price * ammount) + ((singleItem.Price * singleItem.Overcharge) * ammount)).ToString();
                    var log = new StoreLog()
                    {
                        SalesLog = Newlog
                    };
                    context.StoreLog.Add(log);
                }
                context.SaveChanges();
                Console.WriteLine(Startup.languageInterface[43]);
            }
        }
예제 #8
0
        internal static string FindItem(List <Product> list)
        {
            string        itemBrand;
            List <int>    types  = new List <int>();
            List <string> brands = new List <string>();
            int           i      = 0;

            foreach (var item in list)
            {
                if (!types.Contains(item.Type))
                {
                    types.Add(item.Type);
                }
            }
            Console.WriteLine(Startup.languageInterface[45]);
            foreach (var type in types)
            {
                Console.WriteLine("{0} - {1}", type, Product.GetListItem(type));
            }
            Console.Write(Startup.languageInterface[46]);
            int input = InputChecker.CheckIfInt();

            foreach (var item in list)
            {
                if (item.Type == input)
                {
                    if (item.InStock != 0)
                    {
                        brands.Add(item.Brand);
                    }
                }
            }
            if (brands.Count > 0)
            {
                foreach (var brand in brands)
                {
                    Console.WriteLine("{0}:{1}", i, brand);
                    i++;
                }
                Console.Write(Startup.languageInterface[47]);
                input = InputChecker.CheckIfInt(brands.Count - 1);
                while (input >= brands.Count || input < 0)
                {
                    Console.WriteLine(Startup.languageInterface[48]);
                    int.TryParse(Console.ReadLine(), out input);
                }
                itemBrand = brands[input];
            }
            else
            {
                itemBrand = "Out of stock!";
            }
            return(itemBrand);
        }
예제 #9
0
        public static void RemoveItemType()
        {
            Console.Clear();
            Console.WriteLine(Startup.languageInterface[19]);
            string     insertPassword = Console.ReadLine();
            ConsoleKey answer         = ConsoleKey.Enter;

            while (answer != ConsoleKey.Escape)
            {
                if (insertPassword == "1")
                {
                    using (var context = new StoreContext())
                    {
                        var productTypes = context.ProductTypes.ToList();
                        foreach (var item in productTypes)
                        {
                            Console.WriteLine("{0}) {1}", item.PropertyId, item.PropertyName);
                        }
                        //Check if the type exists
                        List <int> typeIds = new List <int>();
                        foreach (var item in productTypes)
                        {
                            typeIds.Add(item.PropertyId);
                        }
                        Console.WriteLine(Startup.languageInterface[69]);
                        int itemToRemove = InputChecker.CheckIfInt();
                        while (!typeIds.Contains(itemToRemove))
                        {
                            Console.WriteLine(Startup.languageInterface[36]);
                            itemToRemove = InputChecker.CheckIfInt(1, context.ProductTypes.Last().PropertyId);
                        }
                        //Deleting the selected type
                        Console.WriteLine(Startup.languageInterface[23], context.ProductTypes.Single(id => id.PropertyId == itemToRemove).PropertyName);
                        answer = InputChecker.CheckIfEnter();
                        if (answer == ConsoleKey.Enter)
                        {
                            var typeToRemove = context.ProductTypes.Single(id => id.PropertyId == itemToRemove);
                            context.ProductTypes.Remove(typeToRemove);
                            context.SaveChanges();
                            answer = ConsoleKey.Escape;
                        }
                    }
                }
                else
                {
                    Console.WriteLine(Startup.languageInterface[18]);
                    Console.WriteLine(Startup.languageInterface[0]);
                    answer = InputChecker.CheckIfEnter();
                    Console.Write(Startup.languageInterface[19]);
                    insertPassword = Console.ReadLine();
                }
            }
        }
예제 #10
0
        //Проверка за съществуването да даден хранителен тип от foodType списъка в Product.cs
        public static int CheckTypeInput(int currentValue)
        {
            for (int i = 0; i < Product.foodType.Count; i++)
            {
                Console.WriteLine("{0}-{1}", i, Product.GetListItem(i));
            }
            Console.WriteLine(Startup.languageInterface[20]);
            Console.WriteLine(Startup.languageInterface[0]);
            ConsoleKey answer = InputChecker.CheckIfEnter();

            if (answer == ConsoleKey.Enter)
            {
                Product.AddItemType();
                Console.Clear();
                foreach (var item in Product.foodType)
                {
                    Console.WriteLine(item);
                }
            }
            Console.Write(Startup.languageInterface[15]);
            bool correct = int.TryParse(Console.ReadLine(), out int type);

            if (string.IsNullOrEmpty(type.ToString()) && !correct)
            {
                Console.WriteLine(Startup.languageInterface[34]);
                return(currentValue);
            }
            else
            {
                while (correct == false || type > Product.foodType.Count || type < 0)
                {
                    if (correct == false)
                    {
                        Console.WriteLine(Startup.languageInterface[35]);
                        correct = int.TryParse(Console.ReadLine(), out type);
                    }
                    else if (type > Product.foodType.Count || type < 0)
                    {
                        Console.WriteLine(Startup.languageInterface[36]);
                        correct = int.TryParse(Console.ReadLine(), out type);
                    }
                }
                return(type);
            }
        }
예제 #11
0
        public static void EditProductType()
        {
            Console.WriteLine(Startup.languageInterface[19]);
            string     insertPassword = Console.ReadLine();
            ConsoleKey answer         = ConsoleKey.Enter;

            while (answer != ConsoleKey.Escape)
            {
                if (insertPassword == "1")
                {
                    Console.Clear();
                    for (int i = 0; i < foodType.Count; i++)
                    {
                        Console.WriteLine("{0}) {1}", i, foodType[i]);
                    }
                    Console.WriteLine(Startup.languageInterface[71]);
                    int itemToEdit = InputChecker.CheckIfInt(foodType.Count);
                    Console.WriteLine(Startup.languageInterface[21]);
                    string newName = CRUDProduct.CheckIfItemExists(Console.ReadLine(), foodType);
                    if (newName != string.Empty)
                    {
                        Console.WriteLine(Startup.languageInterface[73], foodType[itemToEdit], newName);
                        Console.WriteLine(Startup.languageInterface[0]);
                        if (InputChecker.CheckIfEnter() == ConsoleKey.Enter)
                        {
                            foodType[itemToEdit] = newName;
                        }
                        else
                        {
                            Console.WriteLine(Startup.languageInterface[34]);
                        }
                        answer = ConsoleKey.Escape;
                    }
                }
                else
                {
                    Console.WriteLine(Startup.languageInterface[18]);
                    Console.WriteLine(Startup.languageInterface[0]);
                    answer = InputChecker.CheckIfEnter();
                    Console.Write(Startup.languageInterface[19]);
                    insertPassword = Console.ReadLine();
                }
            }
        }
예제 #12
0
        public List <Product> Sell(List <Product> list)
        {
            List <string> shoppingCart = ShoppingCart(list);

            foreach (var brandName in shoppingCart)
            {
                if (brandName != "Out of stock!")
                {
                    Console.Write(Startup.languageInterface[38], brandName);
                    //int.TryParse(Console.ReadLine(), out int ammount);
                    int ammount = InputChecker.CheckIfInt();
                    foreach (var item in list)
                    {
                        if (item.Brand == brandName)
                        {
                            while (item.InStock < ammount)
                            {
                                Console.WriteLine(Startup.languageInterface[39], brandName, item.InStock);
                                Console.Write(Startup.languageInterface[40]);
                                //int.TryParse(Console.ReadLine(), out ammount);
                                ammount = InputChecker.CheckIfInt(item.InStock);
                            }
                            item.InStock    -= ammount;
                            shoppingCardCost = shoppingCardCost + (item.Price * ammount) + ((item.Price * item.Overcharge) * ammount);
                            Startup.shopCash = Startup.shopCash + (item.Price * ammount) + ((item.Price * item.Overcharge) * ammount);
                            Console.WriteLine(Startup.languageInterface[41], Product.GetListItem(item.Type), brandName, item.InStock);
                            using (StreamWriter sw = new StreamWriter("files/log.txt", true))
                            {
                                sw.WriteLine(Startup.languageInterface[42], DateTime.Now, Product.GetListItem(item.Type), brandName, ammount, (item.Price * ammount) + ((item.Price * item.Overcharge) * ammount));
                            }
                            Console.WriteLine(Startup.languageInterface[62], shoppingCardCost);
                        }
                    }
                    Console.WriteLine(Startup.languageInterface[43]);
                }
                else
                {
                    Console.WriteLine(Startup.languageInterface[44]);
                }
            }
            return(list);
        }
예제 #13
0
        public void DisplayProducts()
        {
            Console.WriteLine(Startup.languageInterface[64]);
            Console.WriteLine(Startup.languageInterface[65]);
            int input = InputChecker.CheckIfInt(0, 2);

            using (var context = new StoreContext())
            {
                switch (input)
                {
                case 1:
                    int index = FindItem();
                    Console.Clear();
                    var selectedProduct = context.Products.Single(id => id.ProductID == index);
                    Console.WriteLine(Startup.languageInterface[66], context.ProductTypes.Find(selectedProduct.Type).PropertyName, selectedProduct.Brand);
                    Console.WriteLine(Startup.languageInterface[67], selectedProduct.InStock, selectedProduct.MaxStock);
                    Console.WriteLine(Startup.languageInterface[68], selectedProduct.Price, selectedProduct.Overcharge);

                    break;

                case 2:
                    var products = context.Products.ToList();
                    Console.Clear();
                    foreach (var item in products)
                    {
                        Console.WriteLine(Startup.languageInterface[66], context.ProductTypes.Find(item.Type).PropertyName, item.Brand);
                        Console.WriteLine(Startup.languageInterface[67], item.InStock, item.MaxStock);
                        Console.WriteLine(Startup.languageInterface[68], item.Price, item.Overcharge);
                        Console.WriteLine();
                    }
                    break;

                default:
                    Console.WriteLine(Startup.languageInterface[50]);
                    break;
                }
            }
            Console.WriteLine(Startup.languageInterface[0]);
            InputChecker.CheckIfEnter();
            Console.Clear();
        }
예제 #14
0
        public static void AddItemType()
        {
            Console.Clear();
            Console.WriteLine(Startup.languageInterface[19]);
            string     insertPassword = Console.ReadLine();
            ConsoleKey answer         = ConsoleKey.Enter;

            while (answer != ConsoleKey.Escape)
            {
                if (insertPassword == "1")
                {
                    Console.WriteLine(Startup.languageInterface[21]);
                    var addition = CRUDProduct.CheckIfTypeExists(Console.ReadLine());
                    if (addition != string.Empty)
                    {
                        using (var context = new StoreContext())
                        {
                            var newType = new ProductTypes()
                            {
                                PropertyName = addition
                            };
                            context.ProductTypes.Add(newType);
                            context.SaveChanges();
                        }
                        answer = ConsoleKey.Escape;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    Console.WriteLine(Startup.languageInterface[18]);
                    Console.WriteLine(Startup.languageInterface[0]);
                    answer = InputChecker.CheckIfEnter();
                    Console.Write(Startup.languageInterface[19]);
                    insertPassword = Console.ReadLine();
                }
            }
        }
예제 #15
0
 public static string CheckIfItemExists(string foodType, List <string> list)
 {
     foreach (var item in list)
     {
         while (foodType.ToLower() == item.ToLower())
         {
             Console.WriteLine(Startup.languageInterface[72]);
             Console.WriteLine(Startup.languageInterface[0]);
             ConsoleKey answer = InputChecker.CheckIfEnter();
             if (answer == ConsoleKey.Enter)
             {
                 foodType = Console.ReadLine();
             }
             else
             {
                 return(string.Empty);
             }
         }
     }
     return(foodType);
 }
예제 #16
0
 //Проверка дали обекта съществува
 private string CheckIfItemExists(string brand, List <Product> list)
 {
     foreach (var item in list)
     {
         while (brand == item.Brand)
         {
             Console.WriteLine(Startup.languageInterface[37]);
             Console.WriteLine(Startup.languageInterface[0]);
             ConsoleKey answer = InputChecker.CheckIfEnter();
             if (answer == ConsoleKey.Enter)
             {
                 brand = Console.ReadLine();
             }
             else
             {
                 return(string.Empty);
             }
         }
     }
     return(brand);
 }
예제 #17
0
        //Метод за редактиране на даден обект от списъка с продукти в магазина
        public Product EditProduct(List <Product> list)
        {
            string itemToEdit = SellAndRestock.FindItem(list);

            while (itemToEdit == "Out of stock!")
            {
                Console.WriteLine(Startup.languageInterface[36]);
                itemToEdit = SellAndRestock.FindItem(list);
            }
            Console.WriteLine(Startup.languageInterface[26], itemToEdit);
            ConsoleKey check = InputChecker.CheckIfEnter();

            if (check == ConsoleKey.Enter)
            {
                foreach (var item in list)
                {
                    if (item.Brand == itemToEdit)
                    {
                        Console.WriteLine(Startup.languageInterface[12]);
                        item.Brand = EditItemProperty(item.Brand);
                        Console.WriteLine(Startup.languageInterface[29]);
                        item.Price = EditItemProperty(item.Price);
                        Console.WriteLine(Startup.languageInterface[30]);
                        item.InStock = EditItemProperty(item.InStock);
                        Console.WriteLine(Startup.languageInterface[31]);
                        item.Type = InputChecker.CheckTypeInput(item.Type);
                        Console.WriteLine(Startup.languageInterface[32]);
                        item.MaxStock = EditItemProperty(item.MaxStock);
                        Console.WriteLine(Startup.languageInterface[33]);
                        item.Overcharge = EditItemProperty(item.Overcharge);
                    }
                }
            }
            else
            {
                Console.WriteLine(Startup.languageInterface[34]);
            }
            return(product);
        }
예제 #18
0
        internal static int FindItem()
        {
            int itemId;

            using (var context = new StoreContext())
            {
                var        typesInStock = context.Products.Select(t => t.Type).ToList().Distinct();
                var        types        = context.ProductTypes.ToList();
                List <int> available    = new List <int>();
                Console.WriteLine(Startup.languageInterface[15]);
                foreach (var item in typesInStock)
                {
                    Console.WriteLine("{0}) {1}", item, context.ProductTypes.Single(p => p.PropertyId == item).PropertyName);
                    available.Add(item);
                }
                int input = InputChecker.CheckIfInt();
                while (available.Contains(input) == false)
                {
                    Console.WriteLine(Startup.languageInterface[2]);
                    input = InputChecker.CheckIfInt();
                }
                var itemsFromSelectedType = context.Products.Where(id => id.Type == input);
                available.Clear();
                Console.Clear();
                Console.WriteLine(Startup.languageInterface[47]);
                foreach (var item in itemsFromSelectedType)
                {
                    Console.WriteLine("{0}) {1}", item.ProductID, item.Brand);
                    available.Add(item.ProductID);
                }
                itemId = InputChecker.CheckIfInt();
                while (available.Contains(itemId) == false)
                {
                    Console.WriteLine(Startup.languageInterface[2]);
                    itemId = InputChecker.CheckIfInt();
                }
            }
            return(itemId);
        }
예제 #19
0
        public void DisplayProducts(List <Product> list)
        {
            Console.WriteLine(Startup.languageInterface[64]);
            Console.WriteLine(Startup.languageInterface[65]);
            int input = InputChecker.CheckIfInt();

            while (input > 2 || input < 0)
            {
                input = InputChecker.CheckIfInt();
            }
            switch (input)
            {
            case 1:
                int index = FindItemIndex(list);
                Console.WriteLine(Startup.languageInterface[66], Product.foodType[list[index].Type], list[index].Brand);
                Console.WriteLine(Startup.languageInterface[67], list[index].InStock, list[index].MaxStock);
                Console.WriteLine(Startup.languageInterface[68], list[index].Price, list[index].Overcharge);
                Console.WriteLine();
                break;

            case 2:
                foreach (var item in list)
                {
                    Console.WriteLine(Startup.languageInterface[66], Product.foodType[item.Type], item.Brand);
                    Console.WriteLine(Startup.languageInterface[67], item.InStock, item.MaxStock);
                    Console.WriteLine(Startup.languageInterface[68], item.Price, item.Overcharge);
                    Console.WriteLine();
                }
                break;

            default:
                Console.WriteLine(Startup.languageInterface[50]);
                break;
            }
            InputChecker.CheckIfEnter();
            Console.WriteLine();
            Console.WriteLine(Startup.languageInterface[0]);
            Console.Clear();
        }
예제 #20
0
        //Метод за редактиране на даден обект от списъка с продукти в магазина
        public void EditProduct()
        {
            int itemToEdit = SellAndRestock.FindItem();

            while (itemToEdit == -1)
            {
                Console.WriteLine(Startup.languageInterface[36]);
                itemToEdit = SellAndRestock.FindItem();
            }
            using (var context = new StoreContext())
            {
                Console.WriteLine(Startup.languageInterface[26], context.Products.Single(id => id.ProductID == itemToEdit).Brand);
                Console.WriteLine(Startup.languageInterface[0]);
                ConsoleKey check = InputChecker.CheckIfEnter();
                if (check == ConsoleKey.Enter)
                {
                    var selectedProduct = context.Products.Single(id => id.ProductID == itemToEdit);
                    Console.WriteLine(Startup.languageInterface[12]);
                    product.Brand = EditItemProperty(selectedProduct.Brand);
                    Console.WriteLine(Startup.languageInterface[31]);
                    selectedProduct.Type = InputChecker.CheckTypeInput(selectedProduct.Type);
                    Console.WriteLine(Startup.languageInterface[29]);
                    selectedProduct.Price = EditItemProperty(selectedProduct.Price);
                    Console.WriteLine(Startup.languageInterface[30]);
                    selectedProduct.InStock = EditItemProperty(selectedProduct.InStock);
                    Console.WriteLine(Startup.languageInterface[32]);
                    selectedProduct.MaxStock = EditItemProperty(selectedProduct.MaxStock);
                    Console.WriteLine(Startup.languageInterface[33]);
                    selectedProduct.Overcharge = EditItemProperty(selectedProduct.Overcharge);
                    context.SaveChanges();
                }
                else
                {
                    Console.WriteLine(Startup.languageInterface[34]);
                }
            }
        }
예제 #21
0
        private List <string> ShoppingCart(List <Product> list)
        {
            string        itemBrand    = string.Empty;
            ConsoleKey    answer       = ConsoleKey.Enter;
            List <string> shoppingCart = new List <string>();

            answer = ConsoleKey.Enter;
            while (answer != ConsoleKey.Escape)
            {
                itemBrand = FindItem(list);
                if (itemBrand != null && itemBrand != "Out of stock!")
                {
                    shoppingCart.Add(itemBrand);
                    Console.WriteLine(Startup.languageInterface[49]);
                    Console.WriteLine(Startup.languageInterface[0]);
                    answer = InputChecker.CheckIfEnter();
                }
                else
                {
                    Console.WriteLine(Startup.languageInterface[50]);
                }
            }
            return(shoppingCart);
        }
예제 #22
0
        private List <int> ShoppingCart()
        {
            int        itemId;
            ConsoleKey answer       = ConsoleKey.Enter;
            List <int> shoppingCart = new List <int>();

            answer = ConsoleKey.Enter;
            while (answer != ConsoleKey.Escape)
            {
                itemId = FindItem();
                if (itemId != -1)
                {
                    shoppingCart.Add(itemId);
                    Console.WriteLine(Startup.languageInterface[49]);
                    Console.WriteLine(Startup.languageInterface[0]);
                    answer = InputChecker.CheckIfEnter();
                }
                else
                {
                    Console.WriteLine(Startup.languageInterface[50]);
                }
            }
            return(shoppingCart);
        }
예제 #23
0
        public void Restock()
        {
            Console.WriteLine(Startup.languageInterface[51]);
            Console.WriteLine(Startup.languageInterface[52]);
            Console.WriteLine(Startup.languageInterface[78]);
            int input = InputChecker.CheckIfInt(0, 3);

            using (var context = new StoreContext())
            {
                var moneySupply = context.StoreMoney.First();
                var productList = context.Products.ToList();
                switch (input)
                {
                case 1:
                    foreach (var product in productList)
                    {
                        Console.Clear();
                        Console.WriteLine(Startup.languageInterface[53]);
                        Console.WriteLine(Startup.languageInterface[54], product.Type, product.Brand, product.InStock, product.MaxStock);
                        Console.WriteLine(Startup.languageInterface[55]);
                        ConsoleKey answer = Console.ReadKey(true).Key;
                        if (answer == ConsoleKey.Enter)
                        {
                            Console.WriteLine(Startup.languageInterface[56]);
                            int order = InputChecker.CheckIfInt();
                            while (order + product.InStock > product.MaxStock || order < 0 || order * product.Price > moneySupply.StoreCashSupply)
                            {
                                if (order + product.InStock > product.MaxStock)
                                {
                                    Console.WriteLine(Startup.languageInterface[57], product.MaxStock);
                                }
                                else if (order < 0)
                                {
                                    Console.WriteLine(Startup.languageInterface[58]);
                                }
                                else if (order * product.Price > moneySupply.StoreCashSupply)
                                {
                                    Console.WriteLine(Startup.languageInterface[59]);
                                }
                                Console.Write(Startup.languageInterface[60]);
                                order = InputChecker.CheckIfInt();
                            }
                            moneySupply.StoreCashSupply -= order * product.Price;
                            product.InStock              = order + product.InStock;
                        }
                    }
                    context.SaveChanges();
                    break;

                case 2:
                    foreach (var product in productList)
                    {
                        int ammount = product.MaxStock - product.InStock;
                        if (moneySupply.StoreCashSupply > ammount * product.Price)
                        {
                            moneySupply.StoreCashSupply -= ammount * product.Price;
                            product.InStock              = product.MaxStock;
                        }
                        else
                        {
                            Console.WriteLine(Startup.languageInterface[59]);
                        }
                    }
                    context.SaveChanges();
                    break;

                default:
                    break;
                }
            }
            Console.Clear();
            Console.WriteLine(Startup.languageInterface[61]);
        }
예제 #24
0
        public static void EditProductType()
        {
            Console.WriteLine(Startup.languageInterface[19]);
            string     insertPassword = Console.ReadLine();
            ConsoleKey answer         = ConsoleKey.Enter;

            while (answer != ConsoleKey.Escape)
            {
                if (insertPassword == "1")
                {
                    using (var context = new StoreContext())
                    {
                        var productTypes = context.ProductTypes.ToList();
                        Console.Clear();
                        foreach (var item in productTypes)
                        {
                            Console.WriteLine("{0}) {1}", item.PropertyId, item.PropertyName);
                        }
                        Console.WriteLine(Startup.languageInterface[71]);
                        //Check if the type exists
                        List <int> typeIds = new List <int>();
                        foreach (var item in productTypes)
                        {
                            typeIds.Add(item.PropertyId);
                        }
                        int itemToEdit = InputChecker.CheckIfInt(1, context.ProductTypes.Last().PropertyId);
                        while (!typeIds.Contains(itemToEdit))
                        {
                            Console.WriteLine(Startup.languageInterface[36]);
                            itemToEdit = InputChecker.CheckIfInt(1, context.ProductTypes.Last().PropertyId);
                        }
                        //change the name of the type
                        //Console.WriteLine("item to edit {0}", context.ProductTypes.Single(id=>id.PropertyId == itemToEdit).PropertyName);
                        Console.WriteLine(Startup.languageInterface[21]);
                        string newName = CRUDProduct.CheckIfTypeExists(Console.ReadLine());
                        if (newName != string.Empty)
                        {
                            //Console.WriteLine(itemToEdit);
                            // Console.WriteLine(context.ProductTypes.Single(id => id.PropertyId == itemToEdit).PropertyName);
                            //Console.WriteLine(Startup.languageInterface[73], context.ProductTypes.Single(id => id.PropertyId == itemToEdit).PropertyName);
                            Console.WriteLine(Startup.languageInterface[0]);
                            if (InputChecker.CheckIfEnter() == ConsoleKey.Enter)
                            {
                                var typeToEdit = context.ProductTypes.Single(id => id.PropertyId == itemToEdit);
                                //Console.WriteLine(typeToEdit.PropertyName);
                                //Console.ReadLine();
                                typeToEdit.PropertyName = newName;
                                context.SaveChanges();
                            }
                            else
                            {
                                Console.WriteLine(Startup.languageInterface[34]);
                            }
                            answer = ConsoleKey.Escape;
                        }
                    }
                }
                else
                {
                    Console.WriteLine(Startup.languageInterface[18]);
                    Console.WriteLine(Startup.languageInterface[0]);
                    answer = InputChecker.CheckIfEnter();
                    Console.Write(Startup.languageInterface[19]);
                    insertPassword = Console.ReadLine();
                }
            }
        }
예제 #25
0
        public static int CheckTypeInput(int currentValue)
        {
            using (var context = new StoreContext())
            {
                List <int> ids = new List <int>();
                foreach (var item in context.ProductTypes.ToList())
                {
                    Console.WriteLine("{0}){1}", item.PropertyId, item.PropertyName);
                    ids.Add(item.PropertyId);
                }

                Console.WriteLine(Startup.languageInterface[20]);
                Console.WriteLine(Startup.languageInterface[0]);
                ConsoleKey answer = InputChecker.CheckIfEnter();
                if (answer == ConsoleKey.Enter)
                {
                    Product.AddItemType();
                    Console.Clear();
                    foreach (var item in Product.foodType)
                    {
                        Console.WriteLine(item);
                    }
                }
                Console.Write(Startup.languageInterface[15]);
                int input = CheckIfInt();
                while (ids.Contains(input) == false)
                {
                    Console.WriteLine("again");
                    input = InputChecker.CheckIfInt();
                }
                return(input);
            }

            //for (int i = 0; i < Product.foodType.Count; i++)
            //{
            //    Console.WriteLine("{0}-{1}", i, Product.GetListItem(i));
            //}
            //Console.WriteLine(Startup.languageInterface[20]);
            //Console.WriteLine(Startup.languageInterface[0]);
            //ConsoleKey answer = InputChecker.CheckIfEnter();
            //if (answer == ConsoleKey.Enter)
            //{
            //    Product.AddItemType();
            //    Console.Clear();
            //    foreach (var item in Product.foodType)
            //    {
            //        Console.WriteLine(item);
            //    }
            //}
            //Console.Write(Startup.languageInterface[15]);
            //bool correct = int.TryParse(Console.ReadLine(), out int type);
            //if (string.IsNullOrEmpty(type.ToString()) && !correct)
            //{
            //    Console.WriteLine(Startup.languageInterface[34]);
            //    return currentValue;
            //}
            //else
            //{
            //    while (correct == false || type > Product.foodType.Count || type < 0)
            //    {
            //        if (correct == false)
            //        {
            //            Console.WriteLine(Startup.languageInterface[35]);
            //            correct = int.TryParse(Console.ReadLine(), out type);
            //        }
            //        else if (type > Product.foodType.Count || type < 0)
            //        {
            //            Console.WriteLine(Startup.languageInterface[36]);
            //            correct = int.TryParse(Console.ReadLine(), out type);
            //        }
            //    }
            //    return type;
            //}
        }
예제 #26
0
        public List <Product> Restock(List <Product> list)
        {
            Console.WriteLine(Startup.languageInterface[51]);
            Console.WriteLine(Startup.languageInterface[52]);
            Console.WriteLine(Startup.languageInterface[78]);
            //int.TryParse(Console.ReadLine(), out int input);
            int input = InputChecker.CheckIfInt(3);

            switch (input)
            {
            case 1:
                foreach (var product in list)
                {
                    Console.Clear();
                    Console.WriteLine(Startup.languageInterface[53]);
                    Console.WriteLine(Startup.languageInterface[54], Product.GetListItem(product.Type), product.Brand, product.InStock, product.MaxStock);
                    Console.WriteLine(Startup.languageInterface[55]);
                    ConsoleKey answer = Console.ReadKey(true).Key;
                    if (answer == ConsoleKey.Enter)
                    {
                        Console.WriteLine(Startup.languageInterface[56]);
                        int order = InputChecker.CheckIfInt();
                        while (order + product.InStock > product.MaxStock || order < 0 || order * product.Price > Startup.shopCash)
                        {
                            if (order + product.InStock > product.MaxStock)
                            {
                                Console.WriteLine(Startup.languageInterface[57], product.MaxStock);
                            }
                            else if (order < 0)
                            {
                                Console.WriteLine(Startup.languageInterface[58]);
                            }
                            else if (order * product.Price > Startup.shopCash)
                            {
                                Console.WriteLine(Startup.languageInterface[59]);
                            }
                            Console.Write(Startup.languageInterface[60]);
                            order = InputChecker.CheckIfInt();
                        }
                        Startup.shopCash = Startup.shopCash - order * product.Price;
                        product.InStock  = order + product.InStock;
                    }
                }
                break;

            case 2:
                foreach (var product in list)
                {
                    int ammount = product.MaxStock - product.InStock;
                    if (Startup.shopCash > ammount * product.Price)
                    {
                        Startup.shopCash = Startup.shopCash - ammount * product.Price;
                        product.InStock  = product.MaxStock;
                    }
                    else
                    {
                        Console.WriteLine(Startup.languageInterface[59]);
                    }
                }
                break;

            default:

                break;
            }
            Console.Clear();
            Console.WriteLine(Startup.languageInterface[61]);
            return(list);
        }
예제 #27
0
        static void Main(string[] args)
        {
            ExportAndInport creator     = new ExportAndInport();
            CRUDProduct     newProduct  = new CRUDProduct();
            List <Product>  list        = creator.ImportStoreDataFromFiles();
            SellAndRestock  transaction = new SellAndRestock();

            Console.Clear();
            ConsoleKey cont = ConsoleKey.Enter;

            while (cont == ConsoleKey.Enter)
            {
                Console.Clear();
                Console.WriteLine(languageInterface[3]);
                Console.WriteLine(languageInterface[4]);
                Console.WriteLine(languageInterface[5]);
                Console.WriteLine(languageInterface[70]);
                Console.WriteLine(languageInterface[63]);
                Console.WriteLine(languageInterface[9]);
                Console.WriteLine(languageInterface[10], 5);
                Console.Write(languageInterface[1]);

                int input = InputChecker.CheckIfInt(5);
                switch (input)
                {
                case 1:
                    Console.Clear();
                    ConsoleKey answer = ConsoleKey.Enter;
                    while (answer != ConsoleKey.Escape)
                    {
                        Console.Clear();
                        transaction.Sell(list);
                        Console.WriteLine(languageInterface[0]);
                        answer = InputChecker.CheckIfEnter();
                        Console.Clear();
                    }
                    break;

                case 2:
                    //Избиране на опция от менюто за управление на инвентара
                    Console.Clear();
                    Console.WriteLine(languageInterface[6]);
                    Console.WriteLine(languageInterface[8]);
                    Console.WriteLine(languageInterface[7]);
                    Console.WriteLine(languageInterface[74]);
                    Console.WriteLine(languageInterface[75]);
                    Console.WriteLine(languageInterface[76]);
                    Console.WriteLine(languageInterface[10], 7);
                    input = InputChecker.CheckIfInt(7);
                    switch (input)
                    {
                    case 1:
                        Console.Clear();
                        list.Add(newProduct.CreateNewProduct(list, languageInterface));
                        break;

                    case 2:
                        Console.Clear();
                        newProduct.DeleteItem(list);

                        break;

                    case 3:
                        Console.Clear();
                        newProduct.EditProduct(list);
                        break;

                    case 4:
                        Console.Clear();
                        Product.AddItemType();
                        break;

                    case 5:
                        Console.Clear();
                        Product.RemoveItemType();
                        break;

                    case 6:
                        Console.Clear();
                        Product.EditProductType();
                        break;

                    default:
                        break;
                    }
                    break;

                case 3:
                    Console.Clear();
                    transaction.DisplayProducts(list);
                    break;

                case 4:
                    Console.Clear();
                    transaction.Restock(list);

                    break;

                case 5:
                    Console.Clear();
                    ExportAndInport.ExportStoreDataToFiles(list);
                    return;

                default:
                    break;
                }
            }
        }