/// <summary>
        /// Checks if the article name already exists
        /// </summary>
        /// <returns>The article name</returns>
        public string CheckIfArticleExists()
        {
            using (ArticleServiceClient wcf = new ArticleServiceClient())
            {
                List <Article> allArticls = wcf.GetAllArticles().ToList();
                string         word       = Console.ReadLine();
                BackToMainMenu(word);

                for (int i = 0; i < allArticls.Count; i++)
                {
                    if (allArticls[i].Name.ToLower() == word.ToLower())
                    {
                        Console.Write("This article name already exists. Please try again: ");
                        BackToMainMenu(word);
                        word = Console.ReadLine().ToLower();
                        i    = -1;
                    }
                    else if (string.IsNullOrEmpty(word))
                    {
                        Console.Write("The input cannot be empty. Please try again: ");
                        BackToMainMenu(word);
                        word = Console.ReadLine();
                        i    = -1;
                    }
                }

                return(word);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// method that adds new article to the list of articles and saves changes to file
        /// </summary>
        private void AddArticle()
        {
            Console.WriteLine("Unesite ime artikla:");
            string name = Console.ReadLine();

            Console.WriteLine("Unesite cenu:");
            decimal price = DecimalInput();

            Console.WriteLine("Unesite kolicinu:");
            int amount = IntInput();

            Article lastArticle = articlesList[articlesList.Count - 1];
            string  id          = lastArticle.ID;

            Article article = new Article();

            article.ID     = id;
            article.Price  = price;
            article.Name   = name;
            article.Amount = amount;

            articlesList.Add(article);

            using (ArticleServiceClient wcf = new ArticleServiceClient())
            {
                wcf.UpdateArticles(articlesList.ToArray());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// method that changes price of articles
        /// </summary>
        private void UpdateArticle()
        {
            ShowAllArticles();
            do
            {
                Console.WriteLine("\nUnesite broj artikla");
                string articleID = Console.ReadLine();

                Article article = GetArticleById(articleID);
                if (article == null)
                {
                    Console.WriteLine("Ne postoji artikal sa ovim ID");
                    continue;
                }
                Console.WriteLine("Unesite novu cenu:");
                int price = -1;
                do
                {
                    price = IntInput();

                    if (price <= 0)
                    {
                        Console.WriteLine("Cene mora biti veca od 0");
                    }
                } while (price <= 0);

                article.Price = price;



                Console.WriteLine("Da li zelite da menjate jos artikala d/n");
                string answer = Console.ReadLine();

                if (answer.Equals("d") || answer.Equals("D"))
                {
                }
                else
                {
                    break;
                }
            } while (true);

            using (ArticleServiceClient wcf = new ArticleServiceClient())
            {
                wcf.UpdateArticles(articlesList.ToArray());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// method that show all articles
        /// </summary>
        void ShowAllArticles()
        {
            List <Article> articles = new List <Article>();

            using (ArticleServiceClient wcf = new ArticleServiceClient())
            {
                foreach (var article in wcf.GetArticles())
                {
                    articles.Add(article);
                }
            }



            foreach (var article in articles)
            {
                Console.WriteLine(article.ID + " " + article.Name + " $" + article.Price + " " + article.Amount);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Shows all articles in the file
        /// </summary>
        /// <returns>The total amount of articles</returns>
        public int ShowAllArticles()
        {
            int counter = 0;

            using (ArticleServiceClient wcf = new ArticleServiceClient())
            {
                foreach (var item in wcf.GetAllArticles())
                {
                    if (item.Amount != 0)
                    {
                        Console.WriteLine("{0,3}. {1,20} - {2,-1}\t {3,-20}", ++counter, item.Name, (item.Price).ToString("0.00") + " rsd", "Amount: " + item.Amount);
                    }
                    else
                    {
                        Console.WriteLine("{0,3}. {1,20} - {2,-1}\t {3,-20}", ++counter, item.Name, (item.Price).ToString("0.00") + " rsd", ">> OUT OF STOCK <<");
                    }
                }
            }
            return(counter);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Edit existing article
        /// </summary>
        public void EditArticle()
        {
            int count = ShowAllArticles();

            Validations val = new Validations();

            Console.Write("\nSelect an article number: ");
            int number = val.ValidMaxPositiveNumber(count);

            Console.Write("Choose the new price: ");
            double price = val.ValidPositiveDouble();

            // Used for later notification depending if the article was updated or not
            Article changedArticle = new Article();

            using (ArticleServiceClient wcf = new ArticleServiceClient())
            {
                List <Article> allArticles = wcf.GetAllArticles().ToList();

                Article article = new Article()
                {
                    Name   = allArticles[number - 1].Name,
                    Amount = allArticles[number - 1].Amount,
                    Price  = price
                };

                changedArticle = wcf.ModifyArticle(article);
            }

            // Notification
            if (changedArticle == null)
            {
                Console.WriteLine("Article update failed.");
            }
            else
            {
                Console.WriteLine($"Successfully updated article {changedArticle.Name}");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create new article
        /// </summary>
        public void CreateArticle()
        {
            Validations val = new Validations();

            Console.Write("Please enter the article name: ");
            string name = val.CheckIfArticleExists();

            Console.Write("Please enter the article amount: ");
            int amount = val.ValidPositiveNumber();

            Console.Write("Please enter the article price: ");
            double price = val.ValidPositiveDouble();

            // Creates a new article
            Article article = new Article()
            {
                Name   = name,
                Amount = amount,
                Price  = price
            };

            using (ArticleServiceClient wcf = new ArticleServiceClient())
            {
                article = wcf.SaveArticleToFile(article);
            }

            // Notification
            if (article == null)
            {
                Console.WriteLine("Failed to create an article.");
            }
            else
            {
                Console.WriteLine($"Successfully created an article {article.Name}");
            }
        }
Exemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 public MessageController(ArticleServiceClient articleClient)
 {
     _articleClient = articleClient;
 }
Exemplo n.º 9
0
 /// <summary>
 ///
 /// </summary>
 public DataCountViewComponent(ArticleServiceClient articleClient)
 {
     _articleClient = articleClient;
 }
Exemplo n.º 10
0
 /// <summary>
 ///
 /// </summary>
 public HomeController(ArticleServiceClient articleClient)
 {
     _articleClient = articleClient;
 }
Exemplo n.º 11
0
        /// <summary>
        /// method for shoping of articles
        /// it creates a file with shoping details
        /// </summary>
        void CreateBill()
        {
            List <Article> articlesForBill = new List <Article>();

            ShowAllArticles();
            do
            {
                Console.WriteLine("\nUnesite broj artikla");
                string articleID = Console.ReadLine();

                Article article = GetArticleById(articleID);
                if (article == null)
                {
                    Console.WriteLine("Ne postoji artikal sa ovim ID");
                    continue;
                }
                Console.WriteLine("Unesite kolicinu:");
                int amount = -1;
                do
                {
                    amount = IntInput();
                    if (amount > article.Amount)
                    {
                        Console.WriteLine("Nema dovoljno na stanju. Unesite manju kolicinu");
                    }
                    if (amount <= 0)
                    {
                        Console.WriteLine("Kolicina mora biti veca od 0");
                    }
                } while (amount > article.Amount || amount <= 0);

                article.Amount -= amount;

                Article articleForBill = new Article();
                articleForBill.Name   = article.Name;
                articleForBill.Amount = amount;
                articleForBill.Price  = article.Price;

                string str = string.Format("Ukupan iznos: {0}", articleForBill);
                articlesForBill.Add(articleForBill);

                Console.WriteLine("Da li zelite da dodate jos artikala d/n");
                string answer = Console.ReadLine();

                if (answer.Equals("d") || answer.Equals("D"))
                {
                }
                else
                {
                    break;
                }
            } while (true);


            StringBuilder sb       = new StringBuilder();
            DateTime      dateTime = DateTime.Now;

            sb.Append(dateTime.Day);
            sb.Append("/");
            sb.Append(dateTime.Month);
            sb.Append("/");
            sb.Append(dateTime.Year);
            sb.Append(" ");
            sb.Append(dateTime.Hour);
            sb.Append(":");
            sb.Append(dateTime.Minute);
            sb.Append(":");
            sb.Append(dateTime.Second);

            sb.Append(",");
            //texToFile.Add(sb.ToString());



            decimal totalAmount = 0;

            foreach (var item in articlesForBill)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.Append(item.Name);
                stringBuilder.Append(" - ");
                string str = string.Format("{0}*{1}", item.Amount, item.Price);
                stringBuilder.Append(str);

                sb.Append(stringBuilder.ToString());
                sb.Append(",");

                totalAmount += item.Amount * item.Price;
            }

            string totAmount = string.Format("Ukupan iznos: {0}", totalAmount);

            sb.Append(totAmount);


            StringBuilder stringBuilder1 = new StringBuilder();
            string        currentDate    = DateTime.Now.ToString("ddMMyyyyHHmmss");

            stringBuilder1.Append("Racun_");
            stringBuilder1.Append(++billNumber);

            stringBuilder1.Append("_");

            stringBuilder1.Append(currentDate);


            Console.WriteLine(stringBuilder1.ToString());

            using (ArticleServiceClient wcf = new ArticleServiceClient())
            {
                wcf.CreateBill(sb.ToString());
                wcf.UpdateArticles(articlesList.ToArray());
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Purchase article
        /// </summary>
        public void PurchaseArticles()
        {
            string      answer        = "";
            string      bill          = "";
            int         number        = 0;
            int         currentAmount = 0;
            double      totalPrice    = 0;
            Validations val           = new Validations();

            Console.WriteLine("==============================================\n" +
                              "Return option is disabled until purchase is completed." +
                              "\n==============================================");

            // Do until User presses No as an answer
            do
            {
                int count = ShowAllArticles();

                using (ArticleServiceClient wcf = new ArticleServiceClient())
                {
                    List <Article> allArticles = wcf.GetAllArticles().ToList();

                    // Do until a valid item is selected
                    do
                    {
                        Console.Write("\nSelect an article number: ");
                        number        = val.ValidMaxPositiveNumber(count);
                        currentAmount = allArticles[number - 1].Amount;
                        if (currentAmount == 0)
                        {
                            Console.Write("Cannot select an article that is out of stock.");
                        }
                    } while (currentAmount == 0);

                    // Select amount
                    Console.Write("Choose the amount: ");
                    int amount = val.ValidMaxPositiveNumber(allArticles[number - 1].Amount);

                    // Changed article after reducing the total amount
                    Article article = new Article()
                    {
                        Name   = allArticles[number - 1].Name,
                        Amount = allArticles[number - 1].Amount - amount,
                        Price  = allArticles[number - 1].Price
                    };

                    // Calculate total price and save the item on the bill
                    totalPrice += amount * article.Price;
                    bill       += article.Name + " - " + (amount * article.Price) + " rsd" + "\t\t(" + amount + "*" + article.Price + ")" + "|";
                    wcf.ModifyArticle(article);
                }

                Console.Write("\nWould you like to purchase more items? (yes/no): ");
                answer = val.YesNo();
                Console.Clear();
            } while (answer.ToLower() == "yes");

            // Update bill with all the info before saving it
            bill += "|-----------------------|Total price: " + totalPrice + " rsd|" + "Hour: " + DateTime.Now.ToString("HH:mm:ss") + "|";

            // Save the bill
            using (ArticleServiceClient wcf = new ArticleServiceClient())
            {
                wcf.SaveBill(bill);
            }

            // Bill preview
            Console.WriteLine("Successfult finished the purchase!\n");
            string[] billInfo = bill.Split('|');
            foreach (var item in billInfo)
            {
                Console.WriteLine(item);
            }
        }