public bool AddOperation(TypeOperation type, int amount, Сountry country, int month, int years) { if (amount < CanSpend && amount < country.CanSpend)// Проверка на половину депо { Random rnd = new Random(); int id = rnd.Next(0, 10000000); if (!this.Operations.Any(x => x.Id == id)) { switch (type) { case TypeOperation.Receipt: ReceiptCoins(amount, "Coin:" + country.Name); country.ExpenditureCoins(amount); SaveData(type, amount, country, id, month, years); SaveData(type, amount, this, id, month, years); break; case TypeOperation.Expenditure: ExpenditureCoins(amount); country.ReceiptCoins(amount, "Coin:" + country.Name); SaveData(type, amount, country, id, month, years); SaveData(type, amount, this, id, month, years); break; default: break; } return(true); } else { return(false); } } else { return(false); } ///При таком подходе будет переполнение ( Хотел сделать красиво через рекурсию :C ) //if (!this.Operations.Any(x=>x.Id == id)) //{ // switch (type) // { // case TypeOperation.Receipt: // ReceiptCoins(amount, "Coin:" + country.Name); // country.AddOperation(TypeOperation.Expenditure, amount, this); // SaveData(type, amount, country, id); // break; // case TypeOperation.Expenditure: // ExpenditureCoins(amount); // country.AddOperation(TypeOperation.Receipt, amount, this); // SaveData(type, amount, country, id); // break; // default: // break; // } //} }
private void SaveData(TypeOperation type, int amount, Сountry country, int id, int month, int years) { if (type == TypeOperation.Expenditure) { Operations.Add(new Operation() { Id = id, Amount = amount, Type = type, CountryTo = country, DateCreate = DateTime.Now, Month = month, Year = years }); } else { Operations.Add(new Operation() { Id = id, Amount = amount, Type = type, CountryFrom = country, DateCreate = DateTime.Now, Month = month, Year = years }); } }