public Task <bool> Handle(RegisterCitizenCommand message, CancellationToken cancellationToken) { var citizen = new Citizen(message.Id, message.Name, message.NickName, message.Document, message.Email, message.Gender, message.DateRegister); if (!CitizenIsValid(citizen)) { return(Task.FromResult(false)); } var citizenRegistred = _citizenRepository.Find(c => c.Document == citizen.Document || c.Email == citizen.Email); if (citizenRegistred.Any()) { _mediator.PublishEvent(new DomainNotification(message.MessageType, "CPF ou e-mail já utilizados")); } _citizenRepository.Add(citizen); if (Commit()) { _mediator.PublishEvent(new CitizenRegisteredEvent(citizen.Id, citizen.Name, citizen.NickName, citizen.Document, citizen.Email, citizen.Gender, citizen.DateRegister)); } return(Task.FromResult(true)); }
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); }