Esempio n. 1
0
        public void BuyArticle(Article article, Entity entity)
        {
            using (var transaction = transactionScopeProvider.CreateTransactionScope())
            {
                if (article.Price.HasValue)
                {
                    var currency      = Persistent.Countries.GetCountryCurrency(article.Newspaper.Country);
                    var taxPercentage = (double)article.Newspaper.Country.CountryPolicy.ArticleTax;
                    var price         = (double)article.Price.Value;
                    var priceWithTax  = Math.Round(price * (1 + taxPercentage), 2);
                    var tax           = priceWithTax - price;
                    transactionService.PayForArticle(article, entity, currency.ID, price, tax);
                    warningService.AddWarning(article.NewspaperID, string.Format("{0} bought article \"{1}\" for {2} {3}", entity.Name, article.Title, article.Price, currency.Symbol));
                    article.GeneratedIncome += article.Price.Value;
                }

                if (article.Newspaper.Owner.EntityTypeID == (int)EntityTypeEnum.Citizen)
                {
                    citizenService.OnSoldArticle(article.Newspaper.Owner.Citizen);
                }

                articleRepository.AddBuyer(article.ID, entity.EntityID);
                articleRepository.SaveChanges();
                transaction.Complete();
            }
        }