protected override bool TryUpdateExistingItem(DbfArticle dbfArticle) { var existingArticle = RepositoriesFactory.Get <Article>().Get(article => article.Code == dbfArticle.Code); if (existingArticle == null) { return(false); } existingArticle.Name = dbfArticle.Name ?? string.Empty; existingArticle.Barcode = dbfArticle.Barcode ?? string.Empty; existingArticle.IsActive = true; var articlePrice = existingArticle.ArticlePrices.FirstOrDefault(price => price.ArticlePriceType == PriceType && price.EntryDate == dbfArticle.EntryDate); if (articlePrice != null) { articlePrice.Value = dbfArticle.Price; return(true); } var newArticlePrice = new ArticlePrice { Article = existingArticle, ArticlePriceType = PriceType, EntryDate = dbfArticle.EntryDate, Value = dbfArticle.Price }; existingArticle.ArticlePrices.Add(newArticlePrice); return(true); }
public static ArticlePrice GetOrderArticle() { int articleChoice; ArticlePrice article = ArticlePrice.None; Console.WriteLine("1. Pencil" + Environment.NewLine + "2. Block" + Environment.NewLine + "3. Paper" + Environment.NewLine + "4. Rubber"); var articlerEntry = Console.ReadLine(); if (int.TryParse(articlerEntry, out articleChoice)) { switch (articleChoice) { case 1: article = ArticlePrice.Pencil; break; case 2: article = ArticlePrice.Block; break; case 3: article = ArticlePrice.Paper; break; case 4: article = ArticlePrice.Rubber; break; } } return(article); }
public static CommonEntries.Price Convert(ArticlePrice price) { var result = new CommonEntries.Price { Amount = price.Value, Currency = price.Currency, Formatted = price.Formatted }; return(result); }
private ArticlePrice GetArticlePrice(string manufacturerArticle) { using (var connection = new SqlConnection(Constants.ConnectionString)) { connection.Open(); string sqlSelect = string.Format("select cost + cost/100*vatrate, cast(round((cost/supplierCost - 1)*1000, -1)/10 as int), vatrate, SupplierCost, ProductId FROM [GF_Vofis].[dbo].[T_ProductCost] where ManufacturerArticle = '{0}' and OnOffer=1", manufacturerArticle); SqlCommand command = new SqlCommand(sqlSelect, connection); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { var articlePrice = new ArticlePrice(); articlePrice.VatPrice = Math.Round(Convert.ToDecimal(reader.GetValue(0).ToString()), 2); articlePrice.Natsenka = Convert.ToInt32(reader.GetValue(1).ToString()); articlePrice.VatRate = Convert.ToDecimal(reader.GetValue(2).ToString()); articlePrice.SupplierCost = Convert.ToDecimal(reader.GetValue(3).ToString()); articlePrice.ProductId = Convert.ToInt32(reader.GetValue(4).ToString()); return(articlePrice); } return(null); } }
public static void OrderArticles(Order order) { ArticlePrice article = GetOrderArticle(); if (article != ArticlePrice.None) { int amount = GetOrderAmount(); if (amount != 0 && amount <= 100) { Article articleItem = new Article(article, amount, CalculateDiscount(order.Customer)); order.AddArticle(articleItem); Console.WriteLine("Order created!"); } } else { Console.WriteLine("Something went wrong. Please try again!"); } }
protected override Article GetTargetItemBySource(DbfArticle dbfArticle) { var newArticle = new Article { Name = dbfArticle.Name ?? string.Empty, Quantity = 0f, Measure = "ед", Barcode = dbfArticle.Barcode ?? string.Empty, Code = dbfArticle.Code ?? string.Empty, IsActive = true }; var newArticlePrice = new ArticlePrice { Article = newArticle, ArticlePriceType = PriceType, EntryDate = dbfArticle.EntryDate, Value = dbfArticle.Price }; newArticle.ArticlePrices.Add(newArticlePrice); return(newArticle); }
public void Map_ApiModelToDto_Success() { // Arrange var banana = new Article { Id = 2, Name = "Banana" }; var articlePrice = new ArticlePrice { Article = banana, Id = 1, UnitPrice = 12 }; // Act var model = _mapper.Map <ArticlePriceDto>(articlePrice); // Assert Assert.That(model.Id == articlePrice.Id); Assert.That(model.UnitPrice == articlePrice.UnitPrice); Assert.That(model.Article.Id == articlePrice.Article.Id); Assert.That(model.Article.Name == articlePrice.Article.Name); }
public ArticlePriceWithType(ArticlePrice price, ArticlePriceType type) { Price = price; Type = type; }
public Article(ArticlePrice articlePrice, int amount, double discount) { ArticlePrice = articlePrice; Amount = amount; Discount = discount; }