示例#1
0
        public void IncreaseSkill(int citizenID, WorkTypeEnum workType, double amount)
        {
            var citizen = citizenRepository.GetById(citizenID);

            switch (workType)
            {
            case WorkTypeEnum.Construction:
            {
                citizen.Construction += (decimal)amount;
                break;
            }

            case WorkTypeEnum.Manufacturing:
            {
                citizen.Manufacturing += (decimal)amount;
                break;
            }

            case WorkTypeEnum.Raw:
            {
                citizen.Raw += (decimal)amount;
                break;
            }

            case WorkTypeEnum.Selling:
            {
                citizen.Selling += (decimal)amount;
                break;
            }
            }
            citizenRepository.SaveChanges();
        }
示例#2
0
        public Task <bool> Handle(UpdateCitizenCommand message, CancellationToken cancellationToken)
        {
            var citizenActual = _citizenRepository.GetById(message.Id);

            if (!CitizenExistent(message.Id, message.MessageType))
            {
                return(Task.FromResult(false));
            }

            var citizen = new Citizen(message.Id, message.Name, message.NickName, message.Document, message.Email, message.Gender, citizenActual.DateRegister);

            if (!CitizenIsValid(citizen))
            {
                return(Task.FromResult(false));
            }

            _citizenRepository.Update(citizen);

            if (Commit())
            {
                _mediator.PublishEvent(new CitizenUpdatedEvent(citizen.Id, citizen.Name, citizen.NickName, citizen.Document, citizen.Email, citizen.Gender, citizen.DateRegister));
            }

            return(Task.FromResult(true));
        }
示例#3
0
        public ActionResult SendFriendRequest(int citizenID)
        {
            var citizen = citizenRepository.GetById(citizenID);

            if (citizen == null)
            {
                return(RedirectToHomeWithError("Citizen with this ID does not exist!"));
            }

            var currentCitizen = SessionHelper.CurrentEntity.Citizen;

            if (currentCitizen == null)
            {
                return(RedirectToHomeWithError("You must be an citizen to make friends."));
            }

            MethodResult result;

            if ((result = friendService.CanSendFriendRequest(currentCitizen, citizen)).IsError)
            {
                return(RedirectBackWithError(result));
            }

            friendService.SendFriendRequest(currentCitizen, citizen);

            return(RedirectToAction("View", "Citizen", new { citizenID = citizenID }));
        }
示例#4
0
        public BattleHero GetBattleHero(Battle battle, bool isAttacker)
        {
            bool participantAttacker = isAttacker;

            var hero = battle.BattleParticipants
                       .Where(p => p.IsAttacker == participantAttacker)
                       .GroupBy(p => p.CitizenID)
                       .Select(group => new
            {
                CitizenID = group.Key,
                Damage    = group.Sum(p => p.DamageDealt)
            })
                       .OrderByDescending(p => p.Damage)
                       .FirstOrDefault();

            if (hero == null)
            {
                return(null);
            }

            var citizen = citizenRepository.GetById(hero.CitizenID);

            return(new BattleHero()
            {
                Citizen = citizen,
                DamageDealt = (double)hero.Damage
            });
        }
示例#5
0
        public ActionResult GiveMeVoting()
        {
            var citizen = citizenRepository.GetById(SessionHelper.LoggedCitizen.ID);

            foreach (var cong in citizen.Congressmen.ToList())
            {
                cong.LastVotingDay = GameHelper.CurrentDay - 1;
            }

            citizenRepository.SaveChanges();
            return(RedirectToHome());
        }
        public ActionResult View(int citizenID)
        {
            var citizen = citizenRepository.GetById(citizenID);

            if (citizen == null)
            {
                return(RedirectToHomeWithError("Citizen does not exist!"));
            }

            var friends = friendRepository.GetFriends(citizenID).ToList();

            ViewCitizenViewModel vm = new ViewCitizenViewModel(citizen, friends, citizenService, friendService);

            return(View(vm));
        }
示例#7
0
        public BattleHero GetWarHero(War war, bool isAttacker)
        {
            var hero = war.Battles
                       .SelectMany(b => b.BattleParticipants)
                       .Where(p => p.IsAttacker == isAttacker)
                       .GroupBy(p => p.CitizenID)
                       .Select(group => new
            {
                CitizenID = group.Key,
                Damage    = group.Sum(p => p.DamageDealt)
            })
                       .OrderByDescending(p => p.Damage)
                       .FirstOrDefault();

            if (hero == null)
            {
                return(null);
            }

            var citizen = citizenRepository.GetById(hero.CitizenID);

            return(new BattleHero()
            {
                Citizen = citizen,
                DamageDealt = (double)hero.Damage
            });
        }
示例#8
0
        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);
        }
示例#9
0
 public async Task <Citizen> GetCitizenByIdAsync(int?id)
 {
     if (id.HasValue)
     {
         return(await Task.FromResult(_citizenRepository.GetById(id)));
     }
     else
     {
         return(null);
     }
 }
示例#10
0
        public ActionResult GiveMeHealth()
        {
            ICitizenRepository citizenRepository = DependencyResolver.Current.GetService <ICitizenRepository>();

            var citizen = citizenRepository.GetById(SessionHelper.LoggedCitizen.ID);

            citizen.HitPoints = 100;
            citizen.Worked    = false;

            citizenRepository.SaveChanges();

            return(RedirectToHome());
        }
示例#11
0
        public ActionResult AddManager(int hotelID, int citizenID)
        {
            var hotel   = hotelRepository.GetById(hotelID);
            var citizen = citizenRepository.GetById(citizenID);

            var result = hotelService.CanAddManager(hotel, SessionHelper.CurrentEntity, citizen);

            if (result.IsError)
            {
                return(RedirectBackWithError(result));
            }

            hotelService.AddManager(hotel, SessionHelper.CurrentEntity, citizen);
            AddSuccess("New manager has been added!");
            return(RedirectBack());
        }
        public ActionResult AddJournalist(AddJournalistViewModel vm)
        {
            var newspaper = newspaperRepository.GetById(vm.NewspaperID);

            if (newspaper == null)
            {
                return(NewspaperDoesNotExistRedirect());
            }

            var entity = SessionHelper.CurrentEntity;
            var rights = newspaperService.GetNewspaperRights(newspaper, entity, SessionHelper.LoggedCitizen);

            if (rights.HasFlag(NewspaperRightsEnum.CanManageJournalists) == false)
            {
                return(RedirectToHomeWithError("You cannot manage journalists!"));
            }

            var citizen = citizenRepository.GetById(vm.CitizenID);

            if (citizen == null)
            {
                return(RedirectToHomeWithError("Citizen does not exist!"));
            }

            var result = newspaperService.CanAddJournalist(newspaper, citizen);

            if (ModelState.IsValid && result.IsError == false)
            {
                newspaperService.AddNewJournalist(newspaper, citizen);
                AddSuccess("{0} was added as journalist!", citizen.Entity.Name);
            }
            else if (result.IsError)
            {
                AddError(result);
            }
            else
            {
                AddError("Something went wrong");
            }

            return(RedirectBack());
        }
示例#13
0
        public JsonResult InviteAjax(int partyID, int citizenID)
        {
            var currentCitizen = SessionHelper.CurrentEntity;

            if (currentCitizen.GetEntityType() != EntityTypeEnum.Citizen)
            {
                return(JsonError("You are not a citizen!"));
            }

            var          party   = partyRepository.GetById(partyID);
            var          citizen = citizenRepository.GetById(citizenID);
            MethodResult result;

            if ((result = partyService.CanInviteCitizen(SessionHelper.LoggedCitizen, party, citizen)).IsError)
            {
                return(JsonError(result));
            }

            partyService.InviteCitizen(citizen, party);
            return(JsonSuccess($"You invited {citizen.Entity.Name} to {party.Entity.Name}"));
        }
示例#14
0
        /// <summary>
        /// No checks are being made here. Function assumes that you pass proper data.
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public Session CreateSession(CreateSessionParameters parameters)
        {
            var session = new Session()
            {
                CitizenID      = parameters.CitizenID,
                Cookie         = CreateCookie(parameters.IP, DateTime.Now, parameters.CitizenID),
                ExpirationDate = DateTime.Now + TimeSpan.FromHours(1),
                IP             = parameters.IP,
                RememberMe     = parameters.RememberMe
            };

            if (parameters.RememberMe)
            {
                session.ExpirationDate = session.ExpirationDate.AddDays(7);
            }

            var citizen = citizensRepository.GetById(session.CitizenID);

            citizen.LastActivityDay = GameHelper.CurrentDay;

            sessionRepository.Add(session);
            sessionRepository.SaveChanges();
            return(session);
        }
示例#15
0
        public void ResignFromParty(int citizenID)
        {
            var citizen = citizenRepository.GetById(citizenID);

            ResignFromParty(citizen);
        }
 public CitizenViewModel GetById(Guid id)
 {
     return(_mapper.Map <CitizenViewModel>(_citizenRepository.GetById(id)));
 }
        public void FinishVoting(CongressVoting voting)
        {
            voting.VotingStatusID = (int)VotingStatusEnum.Accepted;
            switch ((VotingTypeEnum)voting.VotingTypeID)
            {
            case VotingTypeEnum.ChangeCongressVotingLength:
            {
                voting.Country.CountryPolicy.CongressVotingLength = int.Parse(voting.Argument1);
                break;
            }

            case VotingTypeEnum.ChangePartyPresidentCadenceLength:
            {
                voting.Country.CountryPolicy.PartyPresidentCadenceLength = int.Parse(voting.Argument1);
                break;
            }

            case VotingTypeEnum.ChangeCongressCadenceLength:
            {
                voting.Country.CountryPolicy.CongressCadenceLength = int.Parse(voting.Argument1);
                break;
            }

            case VotingTypeEnum.ChangeNormalJobMarketFee:
            {
                voting.Country.CountryPolicy.NormalJobMarketFee = (decimal)(double.Parse(voting.Argument1));
                break;
            }

            case VotingTypeEnum.ChangeContractJobMarketFee:
            {
                voting.Country.CountryPolicy.ContractJobMarketFee = (decimal)(double.Parse(voting.Argument1));
                break;
            }

            case VotingTypeEnum.ChangeProductVAT:
            {
                ProductTypeEnum productType = ((ProductTypeEnum)int.Parse(voting.Argument1));
                var             rate        = double.Parse(voting.Argument2);

                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)ProductTaxTypeEnum.VAT,
                        TaxRate          = (decimal)(rate / 100.0),
                        ForeignCountryID = voting.CountryID
                    };
                    productTaxRepository.Add(tax);
                }
                else
                {
                    tax.TaxRate = (decimal)rate;
                }

                productTaxRepository.SaveChanges();

                break;
            }

            case VotingTypeEnum.ChangeProductExportTax:
            case VotingTypeEnum.ChangeProductImportTax:
            {
                ProductTypeEnum productType      = ((ProductTypeEnum)int.Parse(voting.Argument1));
                var             rate             = double.Parse(voting.Argument2);
                int             countryID        = voting.CountryID;
                int             foreignCountryID = int.Parse(voting.Argument3);

                if (foreignCountryID != -1)
                {
                    addForeignTax(voting, productType, rate, foreignCountryID);
                }
                else
                {
                    foreach (var country in Persistent.Countries.GetAll())
                    {
                        if (country.ID == countryID)
                        {
                            continue;
                        }
                        addForeignTax(voting, productType, rate, country.ID);
                    }
                }

                productTaxRepository.SaveChanges();

                break;
            }

            case VotingTypeEnum.ChangeArticleTax:
            {
                var taxRate = double.Parse(voting.Argument1);
                voting.Country.CountryPolicy.ArticleTax = (decimal)(taxRate / 100.0);
                break;
            }

            case VotingTypeEnum.ChangeNewspaperCreateCost:
            {
                var cost = double.Parse(voting.Argument1);
                voting.Country.CountryPolicy.NewspaperCreateCost = (decimal)cost;
                break;
            }

            case VotingTypeEnum.ChangeMarketOfferCost:
            {
                var cost = double.Parse(voting.Argument1);
                voting.Country.CountryPolicy.MarketOfferCost = (decimal)cost;
                break;
            }

            case VotingTypeEnum.ChangeOrganisationCreateCost:
            {
                var cost = double.Parse(voting.Argument1);
                voting.Country.CountryPolicy.OrganisationCreateCost = (decimal)cost;
                break;
            }

            case VotingTypeEnum.ChangePresidentCadenceLength:
            {
                var length = int.Parse(voting.Argument1);
                voting.Country.CountryPolicy.PresidentCadenceLength = length;
                break;
            }

            case VotingTypeEnum.ChangePartyCreateFee:
            {
                var cost = double.Parse(voting.Argument1);
                voting.Country.CountryPolicy.PartyFoundingFee = (decimal)cost;
                break;
            }

            case VotingTypeEnum.ChangeNormalCongressVotingWinPercentage:
            {
                var winPercentage = double.Parse(voting.Argument1);
                voting.Country.CountryPolicy.NormalCongressVotingWinPercentage = (decimal)(winPercentage / 100.0);
                break;
            }

            case VotingTypeEnum.ChangeCitizenCompanyCost:
            case VotingTypeEnum.ChangeOrganisationCompanyCost:
            {
                var cost = double.Parse(voting.Argument1);

                if ((VotingTypeEnum)voting.VotingTypeID == VotingTypeEnum.ChangeCitizenCompanyCost)
                {
                    voting.Country.CountryPolicy.CitizenCompanyCost = (decimal)cost;
                }
                else
                {
                    voting.Country.CountryPolicy.OrganisationCompanyCost = (decimal)cost;
                }
                break;
            }

            case VotingTypeEnum.ChangeMonetaryTaxRate:
            {
                var rate = double.Parse(voting.Argument1);
                voting.Country.CountryPolicy.MonetaryTaxRate = (decimal)rate / 100;
                break;
            }

            case VotingTypeEnum.ChangeMinimumMonetaryTaxValue:
            {
                var value = double.Parse(voting.Argument1);
                voting.Country.CountryPolicy.MinimumMonetaryTax = (decimal)value;
                break;
            }

            case VotingTypeEnum.ChangeTreasureLawHolder:
            {
                var value = int.Parse(voting.Argument1);
                voting.Country.CountryPolicy.TreasuryVisibilityLawAllowHolderID = value;
                break;
            }

            case VotingTypeEnum.ChangeCompanyCreationLawHolder:
            {
                var value = int.Parse(voting.Argument1);
                voting.Country.CountryPolicy.CountryCompanyBuildLawAllowHolder = value;
                break;
            }

            case VotingTypeEnum.CreateNationalCompany:
            {
                var country  = voting.Country;
                var regionID = Convert.ToInt32(voting.Argument2);

                var region = regionRepository.GetById(regionID);

                if (region.CountryID != voting.CountryID)
                {
                    RejectVoting(voting, CongressVotingRejectionReasonEnum.RegionIsNotYoursConstructCompany);
                    break;
                }

                var             companyName = voting.Argument1;
                ProductTypeEnum productType = (ProductTypeEnum)Convert.ToInt32(voting.Argument3);

                if (productType == ProductTypeEnum.MedicalSupplies)
                {
                    companyName = hospitalService.GenerateNameForHospital(region);
                }

                reservedEntityNameRepository.Remove(companyName);
                var company = companyService.CreateCompanyForCountry(companyName, productType, regionID, country, payForCreation: false);

                if (productType == ProductTypeEnum.MedicalSupplies)
                {
                    region.Hospital = company.Hospital;
                }

                RemoveFromGameMoneyInVoting(voting);
                break;
            }

            case VotingTypeEnum.RemoveNationalCompany:
            {
                int companyID = int.Parse(voting.Argument1);
                var company   = companyRepository.GetById(companyID);
                if (company.Region.CountryID != voting.CountryID)
                {
                    RejectVoting(voting, CongressVotingRejectionReasonEnum.CompanyIsNotYoursRemoveCompany);
                    break;
                }
                removalService.RemoveCompany(company);
                break;
            }

            case VotingTypeEnum.AssignManagerToCompany:
            {
                var companyID = int.Parse(voting.Argument1);
                var citizenID = int.Parse(voting.Argument2);

                var company = companyRepository.GetById(companyID);
                var citizen = citizenRepository.GetById(citizenID);

                if (company.CompanyManagers.Any(manager => manager.EntityID == citizenID))
                {
                    RejectVoting(voting, CongressVotingRejectionReasonEnum.AlreadyManagerAssignManager);
                }

                companyService.AddManager(company, citizen, new CompanyRights(true, 100));
                break;
            }

            case VotingTypeEnum.TransferCashToCompany:
            {
                decimal amount     = decimal.Parse(voting.Argument1);
                int     companyID  = int.Parse(voting.Argument2);
                int     currencyID = int.Parse(voting.Argument3);

                var company = companyRepository.GetById(companyID);
                var money   = new Money(currencyID, amount);
                var country = voting.Country;

                var possibleReason = GetRejectionReasonForTransferCashToCompany(money, company, country);

                if (possibleReason.HasValue)
                {
                    RejectVoting(voting, possibleReason.Value);
                    break;
                }

                transactionsService.TransferMoneyFromCountryToCompany(money, company, country);
                RemoveFromGameMoneyInVoting(voting);

                break;
            }

            case VotingTypeEnum.ChangeGreetingMessage:
            {
                int greetingID = int.Parse(voting.Argument1);
                var message    = votingGreetingMessageRepository.GetById(greetingID).Message;


                voting.Country.GreetingMessage = message;
                break;
            }

            case VotingTypeEnum.ChangeCitizenStartingMoney:
            {
                decimal amount = decimal.Parse(voting.Argument1);

                var policy = voting.Country.CountryPolicy;
                policy.CitizenFee = amount;
                break;
            }

            case VotingTypeEnum.ChangeMinimumContractLength:
            {
                int length = int.Parse(voting.Argument1);

                var policy = voting.Country.CountryPolicy;
                policy.MinimumContractLength = length;
                break;
            }

            case VotingTypeEnum.ChangeMaximumContractLength:
            {
                int length = int.Parse(voting.Argument1);
                var policy = voting.Country.CountryPolicy;
                policy.MaximumContractLength = length;
                break;
            }

            case VotingTypeEnum.PrintMoney:
            {
                int moneyAmount = int.Parse(voting.Argument1);

                var money = new Money()
                {
                    Currency = Persistent.Countries.GetCountryCurrency(voting.CountryID),
                    Amount   = moneyAmount
                };

                transactionsService.PrintMoney(voting.Country, money);



                RemoveFromGameMoneyInVoting(voting);
                break;
            }

            case VotingTypeEnum.ChangeMinimalWage:
            {
                var minimalWage = decimal.Parse(voting.Argument1);

                voting.Country.CountryPolicy.MinimalWage = minimalWage;
                companyService.RemoveJobOffersThatDoesNotMeetMinimalWage(minimalWage, voting.CountryID);

                break;
            }

            case VotingTypeEnum.BuildDefenseSystem:
            {
                var quality  = int.Parse(voting.Argument3);
                var regionID = int.Parse(voting.Argument1);

                var region = regionRepository.GetById(regionID);
                defenseSystemService.BuildDefenseSystem(region, voting.Country, quality, constructionService);
                break;
            }

            case VotingTypeEnum.ChangeHotelTax:
            {
                var tax = decimal.Parse(voting.Argument1);
                voting.Country.CountryPolicy.HotelTax = tax / 100m;
                break;
            }

            case VotingTypeEnum.ChangeHouseTax:
            {
                var tax = decimal.Parse(voting.Argument1);
                voting.Country.CountryPolicy.HouseTax = tax / 100m;
                break;
            }

            default:
            {
                throw new NotImplementedException();
            }
            }

            countryEventService.AddVotingEvent(voting, VotingStatusEnum.Accepted);
            ConditionalSaveChanges(congressVotingRepository);
        }
示例#18
0
 public async Task <Citizen> GetById(long id)
 {
     return(await _citizenRepository.GetById(id));
 }