/// <summary> /// Tries to sell the article /// </summary> /// <param name="article">Article to sell</param> /// <param name="buyerId">Id of the Buyer</param> private void SellArticle(Article article, int buyerId) { if (article == null) { logger.Debug("Article not found. Aborting selling of article"); return; } logger.Debug("Trying to sell article with id=" + article.ID); article.IsSold = true; article.SoldDate = DateTime.Now; article.BuyerUserId = buyerId; try { DatabaseDriver.Save(article); logger.Info("Article with id=" + article.ID + " is sold."); } catch (ArgumentNullException ex) { logger.Error("Could not save article with id=" + article.ID); throw new Exception("Could not save article with id"); } catch (Exception) { } }
public void OrderAndSellArticle(int id, int maxExpectedPrice, int buyerId) { #region ordering article List <Supplier> suppliersList = new List <Supplier>() { new Supplier1(), new Supplier2(), new Supplier3() }; Article article = null; for (int i = 0; i < suppliersList.Count; i++) { article = GetArticleDetails(suppliersList[i], maxExpectedPrice, id, i == suppliersList.Count - 1); if (article != null) { break; } } #endregion #region selling article if (article == null) { throw new Exception("Could not order article"); } logger.Debug("Trying to sell article with id=" + id); article.IsSold = true; article.SoldDate = DateTime.Now; article.BuyerUserId = buyerId; try { databaseDriver.Save(article); logger.Info("Article with id=" + id + " is sold."); } catch (ArgumentNullException) { logger.Error("Could not save article with id=" + id); throw new Exception("Could not save article with id"); } catch (Exception ex) { Console.WriteLine(ex); } #endregion }
public void OrderAndSellArticle(int id, int maxExpectedPrice, int buyerId) { #region ordering article Article article = null; Article tempArticle = null; foreach (var item in _suppliers) { var articleExists = item.ArticleInInventory(id); if (articleExists) { tempArticle = item.GetArticle(id); if (maxExpectedPrice > tempArticle.ArticlePrice) { article = tempArticle; } } } #endregion #region selling article if (article == null) { throw new Exception("Could not order article"); } logger.Debug("Trying to sell article with id=" + id); article.IsSold = true; article.SoldDate = DateTime.Now; article.BuyerUserId = buyerId; try { DatabaseDriver.Save(article); logger.Info("Article with id=" + id + " is sold."); } catch (ArgumentNullException ex) { logger.Error("Could not save article with id=" + id); throw new Exception("Could not save article with id"); } catch (Exception e) { throw; } #endregion }
public void SellArticle(int id, Article article, int buyerId) { logger.Debug("Trying to sell article with id=" + id); try { article.IsSold = true; article.SoldDate = DateTime.Now; article.BuyerUserId = buyerId; DatabaseDriver.Save(article); logger.Info("Article with id=" + article.Id + " is sold."); } catch (ArgumentNullException ex) { logger.Error("Could not save article with id=" + id); throw new Exception("Could not save article with id"); } }
private void SellArticle(int id, int buyerId, Article article) { try { if (article == null) { throw new Exception("Could not order article"); } } catch (Exception ex) { Console.WriteLine(ex); return; } _logger.Debug("Trying to sell article with ID = " + id); //_suppliers.Where(s => s.GetArticle(id).NameOfArticle == article.NameOfArticle).; // s.GetArticle(id).IsSold = true); article.IsSold = true; article.SoldDate = DateTime.Now; article.BuyerUserId = buyerId; _suppliers.ForEach(s => s.UpdateArticle(article)); try { _databaseDriver.Save(article); _logger.Info("Article with ID = " + id + " is sold."); } catch (Exception) { string errorMessage = "Could not save article with ID = " + id; _logger.Error(errorMessage); Console.WriteLine(errorMessage); //throw new Exception(errorMessage); } }