public virtual void CancelTrade(Trade trade, Entity who) { using (NoSaveChanges) { returnProductAndMoneyFromTrade(trade); trade.Set(TradeStatusEnum.Cancel); if (trade.GetTradeSide(who) == TradeSideEnum.Destination) { trade.DestinationAccepted = false; } else { trade.SourceAccepted = false; } var entityLink = EntityLinkCreator.Create(who); var tradeLink = TradeLinkCreator.Create(trade); var msg = $"{entityLink} cancelled {tradeLink}."; var secondSide = GetSecondSide(trade, who); warningService.AddWarning(secondSide.EntityID, msg); } tradeRepository.SaveChanges(); }
public void Travel(int citizenID, Region startRegion, Region endRegion, MovingTicket ticket) { using (NoSaveChanges) { var citizen = citizenRepository.GetById(citizenID); citizen.RegionID = endRegion.ID; equipmentRepository.RemoveEquipmentItem(citizen.Entity.EquipmentID.Value, ticket); var trades = tradeRepository.GetTradesAssociatedWithEntity(citizenID) .Where(trade => trade.TradeStatusID == (int)TradeStatusEnum.Ongoing) .ToList(); var citizenLink = EntityLinkCreator.Create(citizen.Entity); var reason = $"{citizenLink} moving into other region"; foreach (var trade in trades) { tradeService.AbortTrade(trade, reason); } citizen.HitPoints -= ticket.HpLoss; } ConditionalSaveChanges(citizenRepository); }
public virtual Trade StartTrade(Entity source, Entity destination) { Trade trade = new Trade() { DateTime = DateTime.Now, Day = GameHelper.CurrentDay, DestinationAccepted = false, DestinationEntityID = destination.EntityID, DestinationUsedFuelAmount = null, SourceAccepted = false, SourceUsedFuelAmount = null, SourceEntityID = source.EntityID, TradeStatusID = (int)TradeStatusEnum.Ongoing, UpdatedDate = DateTime.Now, }; tradeRepository.Add(trade); ConditionalSaveChanges(tradeRepository); var sourceLink = EntityLinkCreator.Create(source); var tradeLink = TradeLinkCreator.Create(trade); var msg = $"{sourceLink} started {tradeLink} with you."; warningService.AddWarning(destination.EntityID, msg); return(trade); }
public void SendProductGift(Entity source, Entity destination, ProductTypeEnum productType, int quality, int amount) { using (var trs = transactionScopeProvider.CreateTransactionScope()) { using (NoSaveChanges) { int?fuelUsed = null; if (WillGiftUseFuel(source, destination)) { int fuelNeeded = GetNeededFuelToSendGift(source, destination, productType, quality, amount); fuelUsed = fuelNeeded; equipmentService.RemoveProductsFromEquipment(ProductTypeEnum.Fuel, fuelNeeded, 1, source.Equipment); } equipmentService.RemoveProductsFromEquipment(productType, amount, quality, source.Equipment); equipmentService.GiveItem(productType, amount, quality, destination.Equipment); createGiftTransaction(source, destination, productType, quality, amount, fuelUsed); var sourceLink = EntityLinkCreator.Create(source); string msg = $"You received {amount} {productType.ToHumanReadable()} from {sourceLink}."; warningService.AddWarning(destination.EntityID, msg); } giftTransactionRepository.SaveChanges(); trs.Complete(); } }
public void SendMoneyGift(Entity source, Entity destination, Currency currency, decimal amount) { var money = new Money(currency, amount); using (var trs = transactionScopeProvider.CreateTransactionScope()) { transactionsService.MakeGift(source, destination, money); var sourceLink = EntityLinkCreator.Create(source); string msg = $"You received {money.Amount} {currency.Symbol} from {sourceLink}."; warningService.AddWarning(destination.EntityID, msg); if (destination.Is(EntityTypeEnum.Company)) { var company = destination.Company; companyFinanceSummaryService.AddFinances(company, new GiftBalanceFinance(amount, currency.ID)); } if (source.Is(EntityTypeEnum.Company)) { var company = source.Company; companyFinanceSummaryService.AddFinances(company, new GiftBalanceFinance(-amount, currency.ID)); } trs.Complete(); } }
private void InformAboutRemoveInvite(PartyInvite invite) { var partyLink = EntityLinkCreator.Create(invite.Party.Entity).ToHtmlString(); string message = $"You are no longer invited to {partyLink}."; using (NoSaveChanges) warningService.AddWarning(invite.CitizenID, message); }
private void SendInviteWarning(Citizen citizen, Party party) { var partyLink = EntityLinkCreator.Create(party.Entity).ToHtmlString(); var partyInvites = LinkCreator.Create("party invites", "Invites", "Party"); var message = $"You were invited to {partyLink}. See {partyInvites} to accept or decline invite."; using (NoSaveChanges) warningService.AddWarning(citizen.ID, message); }
public void SendInformationAboutSideSurrender(War war, Country surrenderingCountry) { var countryLink = EntityLinkCreator.Create(surrenderingCountry.Entity); var warLink = WarLinkCreator.Create(war); string message = $"{countryLink} offered surrender in {warLink}."; SendMessageToEveryoneInWar(war, message, surrenderingCountry.ID); }
public void SendInformationAboutSurrenderAccept(War war, Country acceptingCountry) { var countryLink = EntityLinkCreator.Create(acceptingCountry.Entity); var warLink = WarLinkCreator.Create(war); string message = $"{countryLink} accepted surrender in {warLink}."; SendMessageToEveryoneInWar(war, message, acceptingCountry.ID); }
public void RemoveManager(CompanyManager manager) { var companyLink = EntityLinkCreator.Create(manager.Company.Entity); string msg = $"You are no longer manager of {companyLink}."; using (NoSaveChanges) warningService.AddWarning(manager.EntityID, msg); companyManagerRepository.Remove(manager); companyManagerRepository.SaveChanges(); }
public void ChangeOwnership(Newspaper newspaper, Entity newOwner) { newspaper.OwnerID = newOwner.EntityID; var newspaperLink = EntityLinkCreator.Create(newspaper.Entity); string message = $"You are new owner of {newspaperLink}."; using (NoSaveChanges) warningService.AddWarning(newOwner.EntityID, message); ConditionalSaveChanges(newspaperRepository); }
public void CancelJoinRequest(PartyJoinRequest request) { var citizenLink = EntityLinkCreator.Create(request.Citizen.Entity); var message = $"{citizenLink} canceled join request"; using (NoSaveChanges) warningService.AddWarning(request.PartyID, message); partyJoinRequestRepository.Remove(request); partyJoinRequestRepository.SaveChanges(); }
public void DeclineJoinRequest(PartyJoinRequest request) { var partyLink = EntityLinkCreator.Create(request.Party.Entity); var message = $"Your request to {partyLink} was declined."; using (NoSaveChanges) warningService.AddWarning(request.CitizenID, message); partyJoinRequestRepository.Remove(request); partyJoinRequestRepository.SaveChanges(); }
public void AcceptCongressCandidate(CongressCandidate candidate) { candidate.CongressCandidateStatusID = (int)CongressCandidateStatusEnum.Approved; var link = EntityLinkCreator.Create(candidate.Party.Country.Entity).ToHtmlString(); warningService.AddWarning(candidate.CandidateID, message: $"You were accept by your Party President as congress candidate in {link}"); congressCandidateVotingRepository.SaveChanges(); }
public virtual void SendMessageAboutAttack(War war, WarSideEnum attackingSide, Region region) { var attacker = attackingSide == WarSideEnum.Attacker ? war.Attacker.Entity : war.Defender.Entity; var attackerLink = EntityLinkCreator.Create(attacker).ToHtmlString(); var regionLink = RegionLinkCreator.Create(region).ToHtmlString(); var warLink = WarLinkCreator.Create(war).ToHtmlString(); string message = $"{attackerLink} attacked {regionLink} in {warLink}!"; warService.SendMessageToEveryoneInWar(war, message, attacker.EntityID); }
public void SendWarningToCongress(Country country, string message) { var congressman = congressmenRepository.Where(c => c.CountryID == country.ID).Select(c => c.CitizenID).ToList(); var countryLink = EntityLinkCreator.Create(country.Entity); message = $"[Redirected from {countryLink}'s congress] {message}"; foreach (var congressmanID in congressman) { AddWarning(congressmanID, message); } }
public void CancelMPP(MilitaryProtectionPactOffer offer) { var otherLink = EntityLinkCreator.Create(offer.FirstCountry.Entity); var msg = $"{otherLink} has canceled military pact proposal"; warningService.AddWarning(offer.SecondCountryID, msg); transactionsService.GetGoldForDeclineMPP(offer.FirstCountry, offer.SecondCountry, offer.ReservedGold); militaryProtectionPactOfferRepository.Remove(offer); militaryProtectionPactOfferRepository.SaveChanges(); }
public virtual MethodResult CanFinishTrade(Trade trade) { if (trade.DestinationAccepted == false || trade.SourceAccepted == false) { return(new MethodResult("Not everyone accepted trade")); } if (trade.Is(TradeStatusEnum.Ongoing) == false) { return(new MethodResult("You can only end active trade!")); } var sourceFuelCost = GetNeededFuel(trade.Source, trade); if (sourceFuelCost > 0 && equipmentService.HaveItem(trade.Source.Equipment, ProductTypeEnum.Fuel, 1, sourceFuelCost.Value).IsError) { var sourceLink = EntityLinkCreator.Create(trade.Source); var msg = $"{sourceLink} did not have enough fuel to complete trade"; return(new MethodResult(msg)); } var destinationFuelCost = GetNeededFuel(trade.Destination, trade); if (destinationFuelCost > 0 && equipmentService.HaveItem(trade.Destination.Equipment, ProductTypeEnum.Fuel, 1, destinationFuelCost.Value).IsError) { var destinationLink = EntityLinkCreator.Create(trade.Destination); var msg = $"{destinationLink} did not have enough fuel to complete trade"; return(new MethodResult(msg)); } var freeSourceSpace = equipmentService.GetUnusedInventorySpace(trade.Source.Equipment); var neededSourceSpace = trade.TradeProducts.Where(p => p.EntityID == trade.DestinationEntityID).Sum(p => p.Amount) - sourceFuelCost; if (freeSourceSpace < neededSourceSpace) { var sourceLink = EntityLinkCreator.Create(trade.Source); var msg = $"{sourceLink} did not have enough inventory space to complete trade"; return(new MethodResult(msg)); } var freeDestinationSpace = equipmentService.GetUnusedInventorySpace(trade.Destination.Equipment); var neededDestinationSpace = trade.TradeProducts.Where(p => p.EntityID == trade.SourceEntityID).Sum(p => p.Amount) - destinationFuelCost; if (freeDestinationSpace < neededDestinationSpace) { var sourceLink = EntityLinkCreator.Create(trade.Destination); var msg = $"{sourceLink} did not have enough inventory space to complete trade"; return(new MethodResult(msg)); } return(MethodResult.Success); }
public void RefuseMPP(MilitaryProtectionPactOffer offer) { transactionsService.GetGoldForDeclineMPP(offer.FirstCountry, offer.SecondCountry, offer.ReservedGold); var otherLink = EntityLinkCreator.Create(offer.SecondCountry.Entity); var msg = $"{otherLink} declined your MPP offer."; warningService.AddWarning(offer.FirstCountryID, msg); militaryProtectionPactOfferRepository.Remove(offer); militaryProtectionPactOfferRepository.SaveChanges(); }
public void RemoveCompany(Company company) { using (var trs = transactionScopeProvider.CreateTransactionScope()) { var employees = company.CompanyEmployees.ToList(); var companyLink = EntityLinkCreator.Create(company.Entity); foreach (var employee in employees) { string message = $"Company {companyLink} was removed. You were fired due to this reason."; warningService.AddWarning(employee.CitizenID, message); entityRepository.RemoveSpecific(employee); } foreach (var manager in company.CompanyManagers.ToList()) { string message = $"Company {companyLink} was removed. You are not longer a manager in this company."; warningService.AddWarning(manager.EntityID, message); entityRepository.RemoveSpecific(manager); } foreach (var offer in company.MarketOffers.ToList()) { entityRepository.RemoveSpecific(offer); } foreach (var offer in company.JobOffers.ToList()) { if (offer.ContractJobOffer != null) { entityRepository.RemoveSpecific(offer.ContractJobOffer); } if (offer.NormalJobOffer != null) { entityRepository.RemoveSpecific(offer.NormalJobOffer); } entityRepository.RemoveSpecific(offer); } if (company.Hospital != null) { entityRepository.RemoveSpecific(company.Hospital); } var entity = company.Entity; using (NoSaveChanges) entityRepository.RemoveSpecific(company); RemoveEntity(entity); entityRepository.SaveChanges(); trs.Complete(); } }
public void RemoveRequest(FriendRequest request) { using (NoSaveChanges) { string link = EntityLinkCreator.Create(request.ProposerCitizen.Entity).ToHtmlString(); popupService.AddInfo("You canceled friendship request."); warningService.AddWarning(request.SecondCitizenID, $"{link} canceled friendship request."); } friendRepository.RemoveFriendshipRequest(request); ConditionalSaveChanges(friendRepository); }
public void RemoveFriend(Citizen first, Citizen second) { var friendship = friendRepository.GetFriend(first.ID, second.ID); using (NoSaveChanges) { string link = EntityLinkCreator.Create(first.Entity).ToHtmlString(); warningService.AddWarning(second.ID, $"{link} removed you as friend."); } friendRepository.Remove(friendship); friendRepository.SaveChanges(); }
public void SendFriendRequest(Citizen proposer, Citizen other) { friendRepository.AddFriendRequest(proposer, other); using (NoSaveChanges) { string link = EntityLinkCreator.Create(proposer.Entity).ToHtmlString(); warningService.AddWarning(other.ID, $"You received friendship request from {link}."); popupService.AddInfo($"You've sent friend request to {other.Entity.Name}."); } ConditionalSaveChanges(friendRepository); }
public void AcceptJoinRequest(PartyJoinRequest request) { var partyLink = EntityLinkCreator.Create(request.Party.Entity); var message = $"Your join request to party {partyLink} was accepted"; using (NoSaveChanges) { JoinParty(request.Citizen, request.Party); warningService.AddWarning(request.CitizenID, message); } partyJoinRequestRepository.SaveChanges(); }
public virtual void EndMPP(MilitaryProtectionPact mpp) { var firstCountry = Persistent.Countries.GetById(mpp.FirstCountryID); var secondCountry = Persistent.Countries.GetById(mpp.SecondCountryID); var firstLink = EntityLinkCreator.Create(firstCountry.Entity); var secondLink = EntityLinkCreator.Create(secondCountry.Entity); var msg = $"MPP between {firstLink} and {secondLink} has ended."; warningService.AddWarning(firstCountry.ID, msg); warningService.AddWarning(secondCountry.ID, msg); militaryProtectionPactRepository.Remove(mpp); ConditionalSaveChanges(militaryProtectionPactRepository); }
public void AddManager(Company company, Citizen citizen, CompanyRights rights) { CompanyManager manager = new CompanyManager() { EntityID = citizen.ID, CompanyID = company.ID, }; var companyLink = EntityLinkCreator.Create(company.Entity); var msg = $"From this day on you are new manager of {companyLink}"; using (NoSaveChanges) warningService.AddWarning(citizen.ID, msg); rights.FillEntity(ref manager); companyManagerRepository.Add(manager); ConditionalSaveChanges(companyManagerRepository); }
public void InformAboutNotEnoughRawToWork(Company company, CompanyEmployee employee, List <ProductRequirement> requirements) { var employeeLink = EntityLinkCreator.Create(employee.Citizen.Entity); var companyLink = EntityLinkCreator.Create(company.Entity); string msg = string.Format("{0} wanted to work at {1} but there was not enough resources. {0} Needed : ", employeeLink, companyLink); List <string> resources = new List <string>(); foreach (var req in requirements) { resources.Add(string.Format("{0} Q{1} {2}", req.Quantity, req.Quality, req.RequiredProductType.ToHumanReadable())); } msg += string.Join(",", resources); warningService.AddWarning(company.ID, msg); }
public void AcceptMPP(MilitaryProtectionPactOffer offer) { var otherLink = EntityLinkCreator.Create(offer.SecondCountry.Entity); var msg = $"{otherLink} accepted your MPP offer."; warningService.AddWarning(offer.FirstCountryID, msg); var pact = new MilitaryProtectionPact() { Active = true, StartDay = GameHelper.CurrentDay, EndDay = GameHelper.CurrentDay + offer.Length, FirstCountryID = offer.FirstCountryID, SecondCountryID = offer.SecondCountryID }; militaryProtectionPactRepository.Add(pact); militaryProtectionPactOfferRepository.Remove(offer); militaryProtectionPactOfferRepository.SaveChanges(); }
public void SendJoinRequest(Citizen citizen, Party party, string message) { var request = new PartyJoinRequest() { Day = GameHelper.CurrentDay, CitizenID = citizen.ID, DateTime = DateTime.Now, PartyID = party.ID, Message = message }; var citizenLink = EntityLinkCreator.Create(citizen.Entity); var requestsLink = LinkCreator.Create("join requests", "JoinRequests", "Party", new { partyID = party.ID }); var warningMessage = $"{citizenLink} send join requests. You can see actual {requestsLink} to accept or decline them."; using (NoSaveChanges) warningService.AddWarning(party.ID, warningMessage); partyJoinRequestRepository.Add(request); ConditionalSaveChanges(partyJoinRequestRepository); }
public void WriteComment(DevIssue issue, Citizen citizen, string content, VisibilityOptionEnum visibility) { var comment = new DevIssueComment() { CitizenID = citizen.ID, Day = GameHelper.CurrentDay, Time = DateTime.Now, VisibilityOptionID = (int)visibility, DevIssueID = issue.ID, Content = content }; var entityLink = EntityLinkCreator.Create(citizen.Entity); var issueLink = DevIssueLinkCreator.Create(issue); var msg = $"{entityLink} commented your issue - {issueLink}"; warningService.AddWarning(issue.CreatedByID, msg); devIssueCommentRepository.Add(comment); devIssueCommentRepository.SaveChanges(); }