コード例 #1
0
ファイル: TradeService.cs プロジェクト: blendiahmetaj1/SUPSUP
        public virtual void AddMoney(Currency currency, decimal amount, Entity entity, Trade trade)
        {
            using (NoSaveChanges)
            {
                var existing = trade.TradeMoneys.SingleOrDefault(m => m.CurrencyID == currency.ID && m.EntityID == entity.EntityID);
                trade.DestinationAccepted = trade.SourceAccepted = false;

                if (existing != null)
                {
                    existing.Amount += amount;
                }
                else
                {
                    trade.TradeMoneys.Add(new TradeMoney()
                    {
                        Amount     = amount,
                        CurrencyID = currency.ID,
                        EntityID   = entity.EntityID,
                        TradeID    = trade.ID,
                        DateAdded  = DateTime.Now
                    });
                }

                walletService.AddMoney(entity.WalletID, new Money(currency, -amount));
            }
            ConditionalSaveChanges(tradeRepository);
        }
コード例 #2
0
        public ActionResult GiveMeMoney()
        {
            var entity = SessionHelper.CurrentEntity;
            var wallet = entity.Wallet;
            var gold   = currencyRepository.Gold;

            foreach (var currency in Persistent.Currencies.GetAll())
            {
                var countryMoney = new Money()
                {
                    Amount   = 100,
                    Currency = currency
                };
                walletService.AddMoney(wallet.ID, countryMoney);
            }
            var adminMoney = new Money()
            {
                Amount   = 100,
                Currency = gold
            };



            walletService.AddMoney(wallet.ID, adminMoney);

            return(RedirectToHome());
        }
コード例 #3
0
        public async Task <IResult> Confirm(AddMoneyDto addMoneyDto)      //dto üzerinden onaylama
        {
            string adres  = "https://api.genelpara.com/embed/doviz.json"; //json formatında döviz kurunun çekileceği link
            var    myType = MyTypeBuilder.CompileResultType(new List <Field>()
            {
                new Field {
                    FieldName = addMoneyDto.CurrencyType, FieldType = typeof(Money)
                }
            });                                                     //json formatından nesneye dönüştürmek için nesne tipi üretiliyor
            var data = await WebApiHelper.GetMethod(adres, myType); //apiden veriler çekiliyor

            Money money  = data.GetType().GetProperty(addMoneyDto.CurrencyType).GetValue(data) as Money;
            var   result = _addMoneyDal.Get(a => a.Id == addMoneyDto.AddMoneyId);//id üzerinden bilgiler çekiliyor

            if (result.Status)
            {
                return(new ErrorResult());
            }
            result.Status = true;                            //durum onaylandı yapılıyor
            _addMoneyDal.Update(result);
            var dovizKuru = money == null ? "1":money.Satis; //null ise döviz kuru 1 kabul ediliyor

            dovizKuru = dovizKuru.Replace('.', ',');
            decimal doviz = decimal.Parse(dovizKuru);

            doviz = doviz != (decimal)1.0 ? doviz : doviz;
            _walletService.AddMoney(new Wallet {
                Amount = addMoneyDto.Amount * doviz, UserId = result.UserId
            });
            return(new SuccessResult("onaylandı"));
        }
コード例 #4
0
        private void processCitizens()
        {
            var citizens = citizenRepository.GetAll().ToList();

            for (int i = 0; i < citizens.Count; ++i)
            {
                var citizen = citizens[i];

                if (citizen.Worked == false)
                {
                    citizen.DayWorkedRow = 0;
                }

                citizen.Worked = false;

                if (citizen.HasFood())
                {
                    var bread = citizen.GetBestBread();
                    equipmentRepository.RemoveEquipmentItem(citizen.Entity.EquipmentID.Value, bread.ProductID, bread.Quality);
                    citizen.AddHealth(bread.Quality * 2);
                }
                else
                {
                    citizen.HitPoints -= 10;
                    if (citizen.HitPoints < 0)
                    {
                        citizen.HitPoints = 0;
                    }
                }
                citizen.Trained      = false;
                citizen.UsedHospital = false;
                citizen.DrankTeas    = 0;
                using (NoSaveChanges)
                    walletService.AddMoney(citizen.Entity.WalletID, new structs.Money((int)CurrencyTypeEnum.Gold, 0.5m));
            }
            citizenRepository.SaveChanges();
        }
コード例 #5
0
        private TransactionResult makeTransaction(Transaction transaction)
        {
            Entity sourceEntity      = null;
            Entity destinationEntity = null;

            if (transaction.DestinationEntityID.HasValue)
            {
                destinationEntity = entitiesRepository.GetById(transaction.DestinationEntityID.Value);
            }

            Wallet sourceWallet = null;

            if (transaction.SourceWalletID.HasValue && transaction.TakeMoneyFromSource)
            {
                sourceWallet = walletRepository.GetById(transaction.SourceWalletID.Value);
            }
            else if (transaction.SourceEntityID.HasValue && transaction.TakeMoneyFromSource)
            {
                sourceEntity = entitiesRepository.GetById(transaction.SourceEntityID.Value);
                sourceWallet = sourceEntity.Wallet;
            }


            Wallet destinationWallet = null;

            if (transaction.DestinationWalletID.HasValue)
            {
                destinationWallet = walletRepository.GetById(transaction.DestinationWalletID.Value);
            }
            else if (destinationEntity != null)
            {
                destinationWallet = destinationEntity.Wallet;
            }


            if (sourceWallet != null)
            {
                var sourceMoney = sourceWallet.WalletMoneys.FirstOrDefault(wm => wm.CurrencyID == transaction.Money.Currency.ID);

                if (sourceMoney == null || sourceMoney.Amount < transaction.Money.Amount)
                {
                    return(TransactionResult.NotEnoughMoney);
                }

                walletsService.AddMoney(sourceWallet.ID, -transaction.Money);
            }

            if (destinationWallet != null)
            {
                walletsService.AddMoney(destinationWallet.ID, transaction.Money);
            }


            TransactionLog log = new TransactionLog()
            {
                Amount              = transaction.Money.Amount,
                CurrencyID          = transaction.Money.Currency.ID,
                Date                = DateTime.Now,
                Day                 = configurationRepository.GetCurrentDay(),
                SourceEntityID      = sourceEntity?.EntityID,
                arg1                = transaction.Arg1,
                arg2                = transaction.Arg2,
                TransactionTypeID   = (int)transaction.TransactionType,
                DestinationWalletID = destinationWallet?.ID,
                SourceWalletID      = sourceWallet?.ID
            };

            if (destinationEntity != null)
            {
                log.DestinationEntityID = destinationEntity.EntityID;
            }

            transactionLogRepository.Add(log);
            transactionLogRepository.SaveChanges();

            return(TransactionResult.Success);
        }
コード例 #6
0
        public Citizen CreateCitizen(RegisterInfo info)
        {
            var entity = entitiesService.CreateEntity(info.Name, EntityTypeEnum.Citizen);

            entity.Equipment.ItemCapacity = 25;
            var country = countriesRepository.GetById(info.CountryID);

            Citizen citizen = new Citizen()
            {
                BirthDay      = configurationRepository.GetCurrentDay(),
                CreationDate  = DateTime.Now,
                CitizenshipID = info.CountryID,
                Email         = info.Email,
                RegionID      = info.RegionID,
                Verified      = true,
                PlayerTypeID  = (int)info.PlayerType,
                ID            = entity.EntityID,
                HitPoints     = 100
            };

            using (NoSaveChanges)
                SetPassword(citizen, info.Password);

            var currency = Persistent.Countries.GetCountryCurrency(country);

            walletService.AddMoney(entity.WalletID, new Money(currency, 50));
            walletService.AddMoney(entity.WalletID, new Money(GameHelper.Gold, 5));
            equipmentService.GiveItem(ProductTypeEnum.Bread, 5, 1, entity.Equipment);


            citizenRepository.Add(citizen);
            citizenRepository.SaveChanges();


            Money citizenFee = new Money(Persistent.Currencies.GetById(country.CurrencyID), country.CountryPolicy.CitizenFee);

            if (walletService.HaveMoney(country.Entity.WalletID, citizenFee))
            {
                Transaction feeTransaction = new Transaction()
                {
                    Arg1 = "Citizen Fee",
                    Arg2 = info.Name,
                    DestinationEntityID = citizen.ID,
                    Money           = citizenFee,
                    SourceEntityID  = country.ID,
                    TransactionType = TransactionTypeEnum.CitizenFee
                };
                transactionService.MakeTransaction(feeTransaction);
            }
            else
            {
                string citMessage = "Your country did not have enough money to give you birth starting money.";
                warningService.AddWarning(citizen.ID, citMessage);

                var    citLink        = EntityLinkCreator.Create(citizen.Entity);
                string countryMessage = $"You did not have enough money to give birth starting money to {citLink}.";
                warningService.AddWarning(country.ID, countryMessage);
            }
            string welcomeMessage = country.GreetingMessage;



            var thread = messageService.CreateNewThread(new List <int> {
                citizen.ID, country.ID
            }, "Welcome message");
            var smp = new SendMessageParams()
            {
                AuthorID = country.ID,
                Content  = welcomeMessage,
                Date     = DateTime.Now,
                Day      = GameHelper.CurrentDay,
                ThreadID = thread.ID
            };

            messageService.SendMessage(smp);

            return(citizen);
        }
コード例 #7
0
        public void GivenUser_WhenAddMoney_ThenMoneyIncreased()
        {
            // Arrange
            var user = _userService.CreateUser("Zoran", "123456");

            // Act

            _walletService.AddMoney("Zoran", 100);

            // Assert
            var actual = _walletService.GetMoney("Zoran");

            Assert.AreEqual(100, actual);
        }
コード例 #8
0
        public ActionResult StupidCompanies()
        {
            ProductTypeEnum[] productTypes = new ProductTypeEnum[]
            {
                ProductTypeEnum.Bread,
                ProductTypeEnum.Weapon,
                ProductTypeEnum.Grain,
                ProductTypeEnum.Iron,
                ProductTypeEnum.Tea,
                ProductTypeEnum.Oil,
                ProductTypeEnum.Fuel,
                ProductTypeEnum.MovingTicket,
                ProductTypeEnum.TeaLeaf,
                ProductTypeEnum.Wood,
                ProductTypeEnum.UpgradePoints,
                ProductTypeEnum.MedicalSupplies,
                ProductTypeEnum.Paper,
                ProductTypeEnum.ConstructionMaterials
            };

            CurrencyTypeEnum[] currencies = new CurrencyTypeEnum[]
            {
                CurrencyTypeEnum.PLN,
                CurrencyTypeEnum.Gold,
                CurrencyTypeEnum.Dollar
            };

            using (var trs = transactionScopeProvider.CreateTransactionScope())
            {
                foreach (var productType in productTypes)
                {
                    var name    = RandomGenerator.GenerateString(50);
                    var company = companyService.CreateCompany(name, productType, SessionHelper.LoggedCitizen.RegionID, SessionHelper.LoggedCitizen.ID);
                    companyRepository.ReloadEntity(company);
                    companyRepository.ReloadNavigationProperty(company, x => x.Region);
                    foreach (var cur in currencies)
                    {
                        walletService.AddMoney(company.Entity.WalletID, new Money((int)cur, 1000));
                    }

                    equipmentService.GiveItem(productType, 1000, 1, company.Entity.Equipment);

                    marketService.AddOffer(new AddMarketOfferParameters()
                    {
                        Amount      = 1000,
                        CompanyID   = company.ID,
                        CountryID   = company.Region.CountryID,
                        Price       = 1,
                        ProductType = productType,
                        Quality     = 1
                    });
                }
                var cname = RandomGenerator.GenerateString(50);
                var c     = companyService.CreateCompany(cname, ProductTypeEnum.SellingPower, SessionHelper.LoggedCitizen.RegionID, SessionHelper.LoggedCitizen.ID);
                equipmentService.GiveItem(ProductTypeEnum.SellingPower, 1000, 1, c.Entity.Equipment);
                companyRepository.ReloadEntity(c);
                companyRepository.ReloadNavigationProperty(c, x => x.Region);
                foreach (var cur in currencies)
                {
                    walletService.AddMoney(c.Entity.WalletID, new Money((int)cur, 1000));
                }

                foreach (var productType in ProductGroups.Consumables)
                {
                    equipmentService.GiveItem(productType, 1000, 1, c.Entity.Equipment);

                    marketService.AddOffer(new AddMarketOfferParameters()
                    {
                        Amount      = 1000,
                        CompanyID   = c.ID,
                        CountryID   = c.Region.CountryID,
                        Price       = 1,
                        ProductType = productType,
                        Quality     = 1
                    });
                }
                trs.Complete();
            }

            AddSuccess("Stupid companies completed");
            return(RedirectBack());
        }