Пример #1
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}");
            }
        }
Пример #2
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}");
            }
        }