private void payMonetaryOfferTax(MonetaryOffer offer, ref MonetaryTransaction transaction)
        {
            var tax = CalculateTax((double)offer.ValueOfSold, getTaxRate(offer));

            addTaxToTransaction(offer, transaction, tax);
            var currency = GetUsedCurrency(offer);

            var countryEntity = Persistent.Countries.FirstOrDefault(c => c.CurrencyID == currency.ID)?.Entity;
            var payingEntity  = offer.Entity;
            var money         = new Money()
            {
                Amount   = (decimal)tax,
                Currency = currency
            };

            var sociatisTransaction = new structs.Transaction()
            {
                Arg1  = "Monetary tax",
                Arg2  = string.Format("{0}({1}) paid monetary tax in {2}({3})", payingEntity.Name, payingEntity.EntityID, countryEntity?.Name, countryEntity?.EntityID),
                Money = money,
                DestinationEntityID = countryEntity?.EntityID,
                TransactionType     = TransactionTypeEnum.MonetaryTax
            };

            offer.TaxReservedMoney -= (decimal)tax;
            transactionService.MakeTransaction(sociatisTransaction, useSqlTransaction: false);
        }
        public void ReserveMoneyForVoting(CongressVoting voting, params Money[] money)
        {
            foreach (var m in money)
            {
                var reservedMoney = new CongressVotingReservedMoney()
                {
                    Amount     = m.Amount,
                    CurrencyID = m.Currency.ID
                };

                voting.CongressVotingReservedMoneys.Add(reservedMoney);

                var country = Persistent.Countries.GetById(voting.CountryID);

                var transaction = new structs.Transaction()
                {
                    Arg1 = "ReserveCongressMoney",
                    Arg2 = string.Format("country {0} - {1} {2}", country.Entity.Name, m.Amount, m.Currency.Symbol),
                    DestinationEntityID = null,
                    Money           = m,
                    SourceEntityID  = voting.CountryID,
                    TransactionType = TransactionTypeEnum.ReserveCongressVotingReservedMoney
                };

                transactionsService.MakeTransaction(transaction);
            }

            ConditionalSaveChanges(congressVotingReservedMoneyRepository);
        }
Esempio n. 3
0
        private MethodResult payCashForWork(Company company, Citizen citizen, CompanyEmployee employee)
        {
            var currency = company.Region.Country.Currency;

            var transaction = new structs.Transaction()
            {
                Arg1 = "Job Salary",
                Arg2 = string.Format("{0} Paid {1}", company.Entity.Name, citizen.Entity.Name),
                DestinationEntityID = citizen.ID,
                SourceEntityID      = company.ID,
                Money = new Money()
                {
                    Amount   = employee.TodaySalary.Value,
                    Currency = currency
                },
                TransactionType = TransactionTypeEnum.Salary
            };

            var result = transactionService.MakeTransaction(transaction);

            if (result == enums.TransactionResult.NotEnoughMoney)
            {
                return(new MethodResult("Company does not have enough money"));
            }

            companyFinanceSummaryService.AddFinances(company, new SalaryCostFinance(employee.TodaySalary.Value, currency.ID));

            return(MethodResult.Success);
        }
Esempio n. 4
0
        public virtual TransactionResult MakeBattleStartTransaction(War war, Country attacker, double goldAmount)
        {
            var attEntity = attacker.Entity;
            var money     = new Money()
            {
                Amount   = (decimal)goldAmount,
                Currency = Persistent.Currencies.GetById((int)CurrencyTypeEnum.Gold)
            };

            var transaction = new structs.Transaction()
            {
                Arg1            = "Start Battle - attacker cost",
                Arg2            = string.Format("{0}({1}) paid for creating batle in war #{2}", attEntity.Name, attEntity.EntityID, war.ID),
                Money           = money,
                SourceEntityID  = attacker.ID,
                TransactionType = TransactionTypeEnum.StartBattle
            };

            return(transactionService.MakeTransaction(transaction, useSqlTransaction: false));
        }
        public void ReserveMoneyFromEntity(Entity entity, MonetaryOffer offer)
        {
            var overallReservedMoney = (double)(offer.TaxReservedMoney + offer.OfferReservedMoney);
            var currency             = GetUsedCurrency(offer);
            var money = new Money()
            {
                Amount   = (decimal)overallReservedMoney,
                Currency = currency
            };

            var transaction = new structs.Transaction()
            {
                Arg1            = "Monetary tax",
                Arg2            = string.Format("{0}({1}) Reserved money for MM transaction #{2} - tax {3} + reserved {4}", entity.Name, entity.EntityID, offer.ID, offer.TaxReservedMoney, offer.OfferReservedMoney),
                Money           = money,
                SourceEntityID  = entity.EntityID,
                TransactionType = TransactionTypeEnum.MonetaryTax
            };

            transactionService.MakeTransaction(transaction, useSqlTransaction: false);
        }
        private void payBackReservedMoney(MonetaryOffer offer)
        {
            var giveBackMoneyAmount = (double)(offer.TaxReservedMoney + offer.OfferReservedMoney);
            var currency            = GetUsedCurrency(offer);
            var offerEntity         = offer.Entity;
            var money = new Money()
            {
                Amount   = (decimal)giveBackMoneyAmount,
                Currency = currency
            };

            var sociatisTransaction = new structs.Transaction()
            {
                Arg1  = "Monetary tax",
                Arg2  = string.Format("{0}({1}) got his money back from monetary offer", offerEntity.Name, offerEntity.EntityID),
                Money = money,
                DestinationEntityID = offerEntity.EntityID,
                TransactionType     = TransactionTypeEnum.MonetaryTax
            };

            transactionService.MakeTransaction(sociatisTransaction, useSqlTransaction: false);
        }
Esempio n. 7
0
        public void CountryPayForCompanyCreate(Country country, Company company)
        {
            var adminFee = new Money()
            {
                Currency = GameHelper.Gold,
                Amount   = ConfigurationHelper.Configuration.CompanyCountryFee
            };



            var adminTransaction = new structs.Transaction()
            {
                Arg1 = "Admin Fee",
                Arg2 = string.Format("{0}({1}) created company {2}({3})", country.Entity.Name, country.Entity.EntityID, company.Entity.Name, company.ID),
                DestinationEntityID = null,
                Money           = adminFee,
                SourceEntityID  = country.ID,
                TransactionType = TransactionTypeEnum.CompanyCreate
            };

            transactionService.MakeTransaction(adminTransaction);
        }
        private void makeMarketTransaction(MonetaryOffer buyOffer, Entity buyerEntity, MonetaryOffer sellOffer, int boughtAmount)
        {
            var money = new Money()
            {
                Amount   = boughtAmount * sellOffer.Rate,
                Currency = Persistent.Currencies.GetById(buyOffer.SellCurrencyID)
            };

            var sellEntity = entityRepository.GetById(sellOffer.SellerID);

            var sociatisTransaction = new structs.Transaction()
            {
                Arg1  = "Monetary transaction",
                Arg2  = string.Format("buyer - {0}({1}) MM sell transaction - seller {2}({3})", buyerEntity.Name, buyerEntity.EntityID, sellEntity.Name, sellEntity.EntityID),
                Money = money,
                DestinationEntityID = sellEntity.EntityID,
                TransactionType     = TransactionTypeEnum.MonetaryMarket
            };

            transactionService.MakeTransaction(sociatisTransaction, useSqlTransaction: false);

            money = new Money()
            {
                Amount   = boughtAmount,
                Currency = Persistent.Currencies.GetById(buyOffer.BuyCurrencyID)
            };

            sociatisTransaction = new structs.Transaction()
            {
                Arg1  = "Monetary transaction",
                Arg2  = string.Format("buyer - {0}({1}) MM buy transaction - seller {2}({3})", buyerEntity.Name, buyerEntity.EntityID, sellEntity.Name, sellEntity.EntityID),
                Money = money,
                DestinationEntityID = buyerEntity.EntityID,
                TransactionType     = TransactionTypeEnum.MonetaryMarket
            };
            transactionService.MakeTransaction(sociatisTransaction, useSqlTransaction: false);
        }
        public void UnreserveMoneyForVoting(CongressVoting voting)
        {
            var reservedMoney = voting.CongressVotingReservedMoneys.ToList();

            foreach (var reserved in reservedMoney)
            {
                var money = new Money(reserved.CurrencyID, reserved.Amount);

                var transaction = new structs.Transaction()
                {
                    Arg1 = "ReserveCongressMoney",
                    Arg2 = string.Format("country {0} - {1} {2} unreserved in #{3}", voting.Country.Entity.Name, money.Amount, money.Currency.Symbol, voting.ID),
                    DestinationEntityID = voting.CountryID,
                    Money           = money,
                    SourceEntityID  = null,
                    TransactionType = TransactionTypeEnum.ReserveCongressVotingReservedMoney
                };

                transactionsService.MakeTransaction(transaction);
                congressVotingReservedMoneyRepository.Remove(reserved);
            }

            ConditionalSaveChanges(congressVotingReservedMoneyRepository);
        }