public void AddVotingEvent(CongressVoting voting, VotingStatusEnum votingStatus) { var countryEvent = new CountryVotingGameEvent(voting, votingStatus, GameTime.Now); eventRepository.Add(countryEvent.CreateEntity()); ConditionalSaveChanges(eventRepository); }
public BuildDefenseSystemViewModel(CongressVoting voting) : base(voting) { fillGoldCost(); fillCPCost(); fillRegions(); }
public CongressVoting StartVote(StartCongressVotingParameters parameters) { using (var trs = transactionScopeProvider.CreateTransactionScope()) { CongressVoting vote = new CongressVoting() { CreatorID = parameters.Creator.ID, CommentRestrictionID = (int)parameters.CommentRestriction, CountryID = parameters.Country.ID, StartTime = DateTime.Now, StartDay = GameHelper.CurrentDay, VotingStatusID = (int)VotingStatusEnum.Ongoing, VotingTypeID = (int)parameters.VotingType, CreatorMessage = parameters.CreatorMessage, VotingLength = parameters.VotingLength }; parameters.FillCongressVotingArguments(vote); var congressmen = congressmenRepository.First(c => c.CitizenID == vote.CreatorID); congressmen.LastVotingDay = GameHelper.CurrentDay; congressVotingRepository.Add(vote); specialVotePostProcess(vote); congressVotingRepository.SaveChanges(); informAboutNewVoting(vote); countryEventService.AddVotingEvent(vote, VotingStatusEnum.Started); trs?.Complete(); return(vote); } }
public override void FillCongressVotingArguments(CongressVoting voting) { var repository = DependencyResolver.Current.GetService <IVotingGreetingMessageRepository>(); var id = repository.Add(Message); voting.Argument1 = id.ToString(); }
private Money getMoneyForTrasnferingCashToCompany(CongressVoting voting) { decimal amount = decimal.Parse(voting.Argument1); int currencyID = int.Parse(voting.Argument3); return(new Money(currencyID, amount)); }
private void specialVotePostProcess(CongressVoting voting) { switch (voting.GetVotingType()) { case VotingTypeEnum.CreateNationalCompany: reservedEntityNameRepository.Add(voting.Argument1); ReserveMoneyForVoting(voting, GetMoneyForCreatingCountryCompany()); break; case VotingTypeEnum.TransferCashToCompany: ReserveMoneyForVoting(voting, getMoneyForTrasnferingCashToCompany(voting)); break; case VotingTypeEnum.PrintMoney: var money = getMoneyForPrintingMoney(voting); ReserveMoneyForVoting(voting, money); double amount = (double)money.Amount; voting.Argument2 = amount.ToString(); break; case VotingTypeEnum.RemoveNationalCompany: var companyID = int.Parse(voting.Argument1); var name = companyRepository.Where(c => c.ID == companyID).Select(c => c.Entity.Name).First(); voting.Argument2 = name; break; case VotingTypeEnum.BuildDefenseSystem: ReserveMoneyForVoting(voting, getMoneyForCreatingDefenseSystem(int.Parse(voting.Argument3))); break; default: return; } }
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); }
public static MvcHtmlString Create(CongressVoting voting, string @class = null) { return(LinkCreator.Create(voting.GetName(), "ViewVoting", "Congress", new { votingID = voting.ID }, @class)); }
private void informAboutNewVoting(CongressVoting voting) { var link = CongressVotingLinkCreator.Create(voting).ToHtmlString(); var msg = $"{link} has started."; var country = countryRepository.GetById(voting.CountryID); warningService.SendWarningToCongress(country, msg); }
public bool CanVote(Citizen citizen, CongressVoting voting) { var isCongressman = voting.Country.Congressmen.Any(c => c.CitizenID == citizen.ID); return (voting.CongressVotes.Any(c => c.CitizenID == citizen.ID) == false && isCongressman && voting.VotingStatusID == (int)VotingStatusEnum.Ongoing); }
public CongressVote AddVote(CongressVoting voting, Citizen citizen, VoteTypeEnum voteType) { CongressVote vote = createVote(voting, citizen.ID, voteType); congressVotingRepository.AddVote(vote); congressVotingRepository.SaveChanges(); return(vote); }
private CongressVote createVote(CongressVoting voting, int citizenID, VoteTypeEnum voteType) { return(new CongressVote() { VoteTypeID = (int)voteType, CongressVoting = voting, CitizenID = citizenID }); }
public CongressVotingsItemViewModel(CongressVoting voting) { ProposalName = string.Format("Proposal #{0} : {1}", voting.ID, ((VotingTypeEnum)voting.VotingTypeID).ToHumanReadable()); CreatorName = voting.Citizen.Entity.Name; CreatorID = voting.CreatorID; Ago = AgoHelper.DayAgo(GameHelper.CurrentDay, voting.StartDay); ID = voting.ID; StatusHumanReadable = ((VotingStatusEnum)voting.VotingStatusID).ToHumanReadable(); }
public void RemoveFromGameMoneyInVoting(CongressVoting voting) { var reservedMoney = congressVotingReservedMoneyRepository.GetReservedMoneyForVoting(voting.ID); foreach (var reserved in reservedMoney) { congressVotingReservedMoneyRepository.Remove(reserved); } ConditionalSaveChanges(congressVotingReservedMoneyRepository); }
public CongressVotingComment AddComment(CongressVoting voting, Citizen citizen, string message) { CongressVotingComment comment = new CongressVotingComment() { Citizen = citizen, CongressVoting = voting, Day = GameHelper.CurrentDay, Time = DateTime.Now, Message = message }; congressVotingRepository.AddComment(comment); congressVotingRepository.SaveChanges(); return(comment); }
public List <CongressVote> CreateAbstainedVotes(CongressVoting voting, IEnumerable <Congressman> abstainedCongressmen) { var votes = new List <CongressVote>(); foreach (var congressman in abstainedCongressmen) { CongressVote vote = new CongressVote() { CitizenID = congressman.CitizenID, CongressVotingID = voting.ID, VoteTypeID = (int)VoteTypeEnum.Abstained }; votes.Add(vote); } return(votes); }
public void AddAbstainedVotesForNotVoters(CongressVoting voting) { List <int> congressManVotedIDs = voting.CongressVotes .Select(v => v.Citizen.ID) .ToList(); var abstainedCongressmans = voting.Country .Congressmen .Where(c => congressManVotedIDs.Contains(c.CitizenID) == false) .ToList(); foreach (var abstained in abstainedCongressmans) { var vote = createVote(voting, abstained.CitizenID, VoteTypeEnum.Abstained); congressVotingRepository.AddVote(vote); } congressVotingRepository.SaveChanges(); }
public void RejectVoting(CongressVoting voting, CongressVotingRejectionReasonEnum reason) { voting.VotingStatusID = (int)VotingStatusEnum.Rejected; voting.RejectionReasonID = (int)reason; switch (voting.GetVotingType()) { case VotingTypeEnum.CreateNationalCompany: UnreserveMoneyForVoting(voting); reservedEntityNameRepository.Remove(voting.Argument1); break; case VotingTypeEnum.TransferCashToCompany: UnreserveMoneyForVoting(voting); break; default: break; } countryEventService.AddVotingEvent(voting, VotingStatusEnum.Rejected); }
private void addForeignTax(CongressVoting voting, ProductTypeEnum productType, double rate, int foreignCountryID) { var tax = productTaxRepository.FirstOrDefault(t => t.ProductID == (int)productType && t.CountryID == voting.CountryID); if (tax == null) { tax = new ProductTax() { CountryID = voting.CountryID, ProductID = (int)productType, ProductTaxTypeID = (int)getProductTaxType((VotingTypeEnum)voting.VotingTypeID), TaxRate = (decimal)(rate / 100.0), ForeignCountryID = foreignCountryID }; productTaxRepository.Add(tax); } else { tax.TaxRate = (decimal)rate; } }
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); }
public ChangePartyCreateFeeViewModel(CongressVoting voting) : base(voting) { }
public ChangeCongressCadenceLengthViewModel(CongressVoting voting) : base(voting) { }
public override void FillCongressVotingArguments(CongressVoting voting) { voting.Argument1 = CreationCost.ToString(); }
public override void FillCongressVotingArguments(CongressVoting voting) { voting.Argument1 = NewLength.ToString(); }
public CountryVotingGameEvent(CongressVoting voting, VotingStatusEnum votingStatus, GameTime time) : base(voting.Country, CountryEventTypeEnum.Voting, time) { VotingID = voting.ID; CongressVotingStatus = votingStatus; }
private static ViewVotingBaseViewModel instantiate(VotingTypeEnum votingType, CongressVoting voting, bool isPlayerCongressman, bool canVote) { #if DEBUG if (viewModelTypes.Count != Enum.GetValues(typeof(VotingTypeEnum)).Length) { throw new Exception("Something is propably wrong here :D"); } #endif var type = viewModelTypes[votingType]; var ctor = type.GetConstructor(new[] { typeof(CongressVoting), typeof(bool), typeof(bool) }); return((ViewVotingBaseViewModel)ctor.Invoke(new object[] { voting, isPlayerCongressman, canVote })); }
public override void FillCongressVotingArguments(CongressVoting voting) { voting.Argument1 = JobFee.ToString(); }
public ChangeProductExportTaxViewModel(CongressVoting voting) : base(voting) { loadProducts(); loadCountries(); }
public override void FillCongressVotingArguments(CongressVoting voting) { voting.Argument1 = CompanyName; voting.Argument2 = RegionID.ToString(); voting.Argument3 = ProductID.ToString(); }
public ChangeContractJobMarketFeeViewModel(CongressVoting voting) : base(voting) { }