private static void Main(string[] args) { IShopService shopService = new ShopService(); try { //order and sell var article = shopService.OrderArticle(1, 20); shopService.SellArticle(10, article); //print article on console article = shopService.GetArticleById(1); if (article == null) { Console.WriteLine("Article not found: "); } Console.WriteLine("Found article with ID: " + article.ID); //print article on console article = shopService.GetArticleById(12); if (article == null) { Console.WriteLine("Article not found: "); } Console.WriteLine("Found article with ID: " + article.ID); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }
private static void Main(string[] args) { var shopService = new ShopService(); Article article = null; IUnitOfWork unitOfWork; try { //order and sell article = shopService.OrderArticle(articleId1, maxExpectedPrice); shopService.SellArticle(article, buyerId); } catch (ArticalNotFoundException ae) { Console.WriteLine(ae.Message); } catch (NotSavedArticleException nsae) { Console.WriteLine(nsae.Message); } catch (Exception ex) { Console.WriteLine(ex); } try { unitOfWork = new UnitOfWork(); article = unitOfWork.ArticleRepository.GetArticleById(articleId1); //print article on console Console.WriteLine("Found article with ID: " + article.ID); } catch (ArticalNotFoundException anfex) { Console.WriteLine($"Article with id:{articleId1} not found"); } catch (Exception ex) { Console.WriteLine($"Article with id:{articleId1} not found"); } try { unitOfWork = new UnitOfWork(); article = unitOfWork.ArticleRepository.GetArticleById(articleId12); //print article on console Console.WriteLine("Found article with ID: " + article.ID); } catch (Exception ex) { Console.WriteLine($"Article with id:{articleId12} not found"); } Console.ReadKey(); }
/// <summary> /// Orders and sell an article, if it exists /// </summary> /// <param name="articleId"> Article id</param> /// <param name="maxExpectedPrice">Max expected price</param> /// <param name="buyerId">Buyer id</param> private static void OrderAndSellArticle(int articleId, int maxExpectedPrice, int buyerId) { try { ISupplier supplier = _shopService.OrderArticle(articleId, maxExpectedPrice); if (supplier != null) { _shopService.SellArticle(supplier, articleId, buyerId); } } catch (Exception ex) { Console.WriteLine(ex); } }