private WalletTemplate CreateWalletTemplate( Guid brandId, string name, IEnumerable <Guid> productIds, bool isMain) { var brand = _repository.Brands.Single(x => x.Id == brandId); var walletTemplate = new WalletTemplate { Id = Guid.NewGuid(), DateCreated = DateTime.UtcNow, CreatedBy = _actorInfoProvider.Actor.Id, Name = name, CurrencyCode = brand.DefaultCurrency, IsMain = isMain }; foreach (var productId in productIds) { var walletProduct = new WalletTemplateProduct { Id = Guid.NewGuid(), ProductId = productId }; walletTemplate.WalletTemplateProducts.Add(walletProduct); } brand.WalletTemplates.Add(walletTemplate); return(walletTemplate); }
public void Handle(WalletTemplateUpdated @event) { var bonusRepository = _container.Resolve <IBonusRepository>(); var brand = bonusRepository.Brands.SingleOrDefault(b => b.Id == @event.BrandId); if (brand == null) { throw new RegoException(string.Format(NoBrandFormat, @event.BrandId)); } var brandPlayers = bonusRepository.Players.Where(p => p.Brand.Id == brand.Id); foreach (var walletTemplate in @event.NewWalletTemplates) { var walletTemplateData = new WalletTemplate { Id = walletTemplate.Id, IsMain = walletTemplate.IsMain, Products = walletTemplate.ProductIds.Select(id => new Product { ProductId = id }).ToList() }; brand.WalletTemplates.Add(walletTemplateData); foreach (var brandPlayer in brandPlayers) { brandPlayer.Wallets.Add(new Wallet { Player = brandPlayer, Template = walletTemplateData }); } } foreach (var walletTemplateDto in @event.RemainedWalletTemplates) { var walletTemplate = brand.WalletTemplates.Single(wt => wt.Id == walletTemplateDto.Id); walletTemplate.Products.Clear(); walletTemplate.Products.AddRange(walletTemplateDto.ProductIds.Select(id => new Product { ProductId = id })); walletTemplate.IsMain = walletTemplate.IsMain; } bonusRepository.SaveChanges(); }
private void CreateWallet(Brand brand) { var walletTemplate = new WalletTemplate() { Brand = brand, Name = "Main Wallet", Id = Guid.NewGuid(), IsMain = true, CreatedBy = _sharedData.User.UserId, DateCreated = DateTimeOffset.UtcNow }; brand.WalletTemplates.Add(walletTemplate); _brandRepository.WalletTemplates.Add(walletTemplate); _brandRepository.SaveChanges(); }
/** * sumarry Loads the transaction history to a StackLayout * param name="Stack" the stacklayout where the transaction history should be loaded * **/ public static async Task LoadTransactionHistoryToStack(StackLayout Stack, Label Balance) { Stack.Children.Clear(); Dictionary <int, String[]> Data = new Dictionary <int, string[]> { { 0, new String[] { "user_id", Utilities.ID.ToString() } }, }; //try //{ String ResponseJson = await TransactionModel.TransactionHistory(Utilities.PostDataEncoder(Data)); var DecodedJson = JObject.Parse(ResponseJson); Balance.Text = Utilities.Currency + " " + Convert.ToDouble(DecodedJson["transactions"]["balance"]); Utilities.Balance = Convert.ToDouble(DecodedJson["transactions"]["balance"]); await Utilities.RunTask(delegate { foreach (var Transaction in DecodedJson["transactions"]["history"]) { Device.BeginInvokeOnMainThread(() => { try { Stack.Children.Add(WalletTemplate.TransactionTemplate01( Transaction["amount"].ToString(), ((Transaction["action"].ToString() == "Deposit") ? TransactionType.Credit : TransactionType.Debit), "Date " + DateTime.Parse(Transaction["time"].ToString()).ToShortDateString() + "\n" + Transaction["reason"].ToString()) ); } catch (Exception exx) { App.Current.MainPage.DisplayAlert("Alert", exx.Message, "Ok"); } }); } }); //} //catch (Exception ex) //{ // await App.Current.MainPage.DisplayAlert("Alert",ex.StackTrace,"Ok"); // } }
public override void BeforeEach() { base.BeforeEach(); FakeBrandRepository = Container.Resolve <FakeBrandRepository>(); FakePlayerRepository = Container.Resolve <FakePlayerRepository>(); FakePaymentRepository = Container.Resolve <FakePaymentRepository>(); FakeEventRepository = Container.Resolve <FakeEventRepository>(); FakeSecurityRepository = Container.Resolve <FakeSecurityRepository>(); FakeMessagingRepository = Container.Resolve <FakeMessagingRepository>(); for (int i = 0; i < TestDataGenerator.CountryCodes.Length; i++) { FakeBrandRepository.Countries.Add(new Country { Code = TestDataGenerator.CountryCodes[i] }); } for (int i = 0; i < TestDataGenerator.CurrencyCodes.Length; i++) { FakeBrandRepository.Currencies.Add(new Currency { Code = TestDataGenerator.CurrencyCodes[i] }); } for (int i = 0; i < TestDataGenerator.CultureCodes.Length; i++) { FakeBrandRepository.Cultures.Add(new Culture { Code = TestDataGenerator.CultureCodes[i] }); } var brandId = new Guid("00000000-0000-0000-0000-000000000138"); var brand = new Core.Brand.Interface.Data.Brand { Id = brandId, Name = "138", Status = BrandStatus.Active, TimezoneId = "Pacific Standard Time" }; for (int i = 0; i < TestDataGenerator.CurrencyCodes.Length; i++) { var currencyCode = TestDataGenerator.CurrencyCodes[i]; brand.BrandCurrencies.Add(new BrandCurrency { BrandId = brand.Id, Brand = brand, CurrencyCode = currencyCode, Currency = FakeBrandRepository.Currencies.Single(x => x.Code == currencyCode), DefaultPaymentLevelId = currencyCode == "CAD" ? new Guid("E1E600D4-0729-4D5C-B93E-085A94B55B33") : new Guid("1ED97A2B-EBA2-4B68-A70C-18A7070908F9") }); } for (int i = 0; i < TestDataGenerator.CountryCodes.Length; i++) { var countryCode = TestDataGenerator.CountryCodes[i]; brand.BrandCountries.Add(new BrandCountry { BrandId = brand.Id, Brand = brand, CountryCode = countryCode, Country = FakeBrandRepository.Countries.Single(x => x.Code == countryCode) }); } for (int i = 0; i < TestDataGenerator.CultureCodes.Length; i++) { var cultureCode = TestDataGenerator.CultureCodes[i]; brand.BrandCultures.Add(new BrandCulture { BrandId = brand.Id, Brand = brand, CultureCode = cultureCode, Culture = FakeBrandRepository.Cultures.Single(x => x.Code == cultureCode) }); } var walletTemplate = new WalletTemplate() { Brand = brand, Id = Guid.NewGuid(), IsMain = true, Name = "Main wallet", DateCreated = DateTimeOffset.UtcNow, CreatedBy = Guid.NewGuid() }; brand.WalletTemplates.Add(walletTemplate); brand.DefaultCulture = brand.BrandCultures.First().Culture.Code; brand.DefaultCurrency = brand.BrandCurrencies.First().Currency.Code; var vipLevel = new Core.Brand.Interface.Data.VipLevel { Name = "Standard", BrandId = brandId }; brand.DefaultVipLevelId = vipLevel.Id; brand.DefaultVipLevel = vipLevel; FakeBrandRepository.WalletTemplates.Add(walletTemplate); var playerVipLevel = new VipLevel { Id = Guid.NewGuid(), Name = "Standard", BrandId = brandId }; brand.DefaultVipLevelId = playerVipLevel.Id; FakeBrandRepository.Brands.Add(brand); var playerBrand = new Core.Common.Data.Player.Brand { Id = brand.Id, TimezoneId = brand.TimezoneId }; FakePlayerRepository.Brands.Add(playerBrand); FakePlayerRepository.VipLevels.Add(playerVipLevel); FakeMessagingRepository.VipLevels.Add(new Core.Messaging.Data.VipLevel { Id = playerVipLevel.Id, Name = playerVipLevel.Name }); FakeMessagingRepository.SaveChanges(); playerBrand.DefaultVipLevelId = playerVipLevel.Id; FakePlayerRepository.SaveChanges(); foreach (var questionid in TestDataGenerator.SecurityQuestions) { FakePlayerRepository.SecurityQuestions.Add(new SecurityQuestion { Id = new Guid(questionid), Question = TestDataGenerator.GetRandomString() }); } Container.Resolve <FakeGameRepository>().Brands.Add(new Core.Game.Interface.Data.Brand { Id = new Guid("00000000-0000-0000-0000-000000000138"), TimezoneId = TestDataGenerator.GetRandomTimeZone().Id }); var bankAccountType = new BankAccountType { Id = new Guid("00000000-0000-0000-0000-000000000100"), Name = "Main" }; FakePaymentRepository.Brands.Add(new Core.Payment.Data.Brand { Id = new Guid("00000000-0000-0000-0000-000000000138"), TimezoneId = "Pacific Standard Time" }); FakePaymentRepository.BankAccountTypes.Add(bankAccountType); var bank = new Bank { Id = Guid.NewGuid(), BankId = "SE45", BankName = "Bank of Canada", BrandId = brandId, CountryCode = "Canada", Created = DateTime.Now, CreatedBy = "initializer" }; FakePaymentRepository.Banks.Add(bank); var cadAccountId = new Guid("B6755CB9-8F9A-4EBA-87E0-1ED5493B7534"); FakePaymentRepository.BankAccounts.Add( new BankAccount { Id = cadAccountId, AccountId = "BoC1", AccountName = "John Doe", AccountNumber = "SE45 0583 9825 7466", AccountType = bankAccountType, Bank = bank, Branch = "Main", Province = "Vancouver", CurrencyCode = "CAD", Created = DateTime.Now, CreatedBy = "Initializer", Status = BankAccountStatus.Active, Updated = DateTime.Now, UpdatedBy = "Initializer" } ); bankAccountType = new BankAccountType { Id = new Guid("00000000-0000-0000-0000-000000000101"), Name = "VIP" }; FakePaymentRepository.BankAccountTypes.Add(bankAccountType); bank = new Bank { Id = Guid.NewGuid(), BankId = "70AC", BankName = "Hua Xia Bank", BrandId = brandId, CountryCode = "China", Created = DateTime.Now, CreatedBy = "initializer" }; FakePaymentRepository.Banks.Add(bank); var rmbAccountId = new Guid("13672261-70AC-46E3-9E62-9E2E3AB77663"); FakePaymentRepository.BankAccounts.Add( new BankAccount { Id = rmbAccountId, AccountId = "HXB1", AccountName = "Beijing", AccountNumber = "BA3912940494", //AccountType = "Main", AccountType = bankAccountType, Bank = bank, Branch = "Main", Province = "Beijing Municipality", CurrencyCode = "RMB", Created = DateTime.Now, CreatedBy = "Initializer", Status = BankAccountStatus.Active, Updated = DateTime.Now, UpdatedBy = "Initializer" } ); var paymentLevel = new PaymentLevel { Id = new Guid("E1E600D4-0729-4D5C-B93E-085A94B55B33"), BrandId = brandId, CurrencyCode = "CAD", Name = "CADLevel", Code = "CADLevel", EnableOfflineDeposit = true, DateCreated = DateTimeOffset.Now, CreatedBy = "Initializer" }; paymentLevel.BankAccounts.Add(FakePaymentRepository.BankAccounts.Single(a => a.Id == cadAccountId)); FakePaymentRepository.PaymentLevels.Add(paymentLevel); paymentLevel = new PaymentLevel { Id = new Guid("1ED97A2B-EBA2-4B68-A70C-18A7070908F9"), BrandId = brandId, CurrencyCode = "RMB", Name = "RMBLevel", Code = "RMBLevel", EnableOfflineDeposit = true, DateCreated = DateTimeOffset.Now, CreatedBy = "Initializer" }; paymentLevel.BankAccounts.Add(FakePaymentRepository.BankAccounts.Single(a => a.Id == rmbAccountId)); FakePaymentRepository.PaymentLevels.Add(paymentLevel); var licensee = new Licensee { Id = Guid.NewGuid(), AllowedBrandCount = 1, Status = LicenseeStatus.Active }; FakeBrandRepository.Licensees.Add(licensee); FakeBrandRepository.SaveChanges(); foreach (var culture in FakeBrandRepository.Cultures) { FakeMessagingRepository.Languages.Add(new Language { Code = culture.Code, Name = culture.Name }); } foreach (var thisBrand in FakeBrandRepository.Brands.Include(x => x.BrandCultures.Select(y => y.Culture))) { FakeMessagingRepository.Brands.Add(new Core.Messaging.Data.Brand { Id = thisBrand.Id, Name = thisBrand.Name, SmsNumber = TestDataGenerator.GetRandomPhoneNumber(), Email = TestDataGenerator.GetRandomEmail(), Languages = thisBrand.BrandCultures.Select(x => new Language { Code = x.Culture.Code, Name = x.Culture.Name }).ToList() }); } foreach (var thisPlayer in FakePlayerRepository.Players) { FakeMessagingRepository.Players.Add(new Core.Messaging.Data.Player { Id = thisPlayer.Id, Username = thisPlayer.Username, FirstName = thisPlayer.FirstName, LastName = thisPlayer.LastName, Email = thisPlayer.Email, Language = FakeMessagingRepository.Languages.Single(x => x.Code == thisPlayer.CultureCode), Brand = FakeMessagingRepository.Brands.Single(x => x.Id == thisPlayer.BrandId) }); } foreach (var thisBrand in FakeMessagingRepository.Brands.Include(x => x.Languages)) { foreach (var thisLanguage in thisBrand.Languages) { foreach (var messageType in (MessageType[])Enum.GetValues(typeof(MessageType))) { FakeMessagingRepository.MessageTemplates.Add(new MessageTemplate { BrandId = thisBrand.Id, LanguageCode = thisLanguage.Code, MessageType = messageType, MessageDeliveryMethod = MessageDeliveryMethod.Email, TemplateName = TestDataGenerator.GetRandomString(), MessageContent = string.Format("Fake email message Template. {0}.", Enum.GetName(typeof(MessageType), messageType)), Subject = TestDataGenerator.GetRandomString(), Status = Status.Active, CreatedBy = "System", Created = DateTimeOffset.UtcNow, ActivatedBy = "System", Activated = DateTimeOffset.UtcNow }); FakeMessagingRepository.MessageTemplates.Add(new MessageTemplate { BrandId = thisBrand.Id, LanguageCode = thisLanguage.Code, MessageType = messageType, MessageDeliveryMethod = MessageDeliveryMethod.Sms, TemplateName = TestDataGenerator.GetRandomString(), MessageContent = string.Format("Fake SMS message Template. {0}.", Enum.GetName(typeof(MessageType), messageType)), Status = Status.Active, CreatedBy = "System", Created = DateTimeOffset.UtcNow, ActivatedBy = "System", Activated = DateTimeOffset.UtcNow }); } } } FakeMessagingRepository.SaveChanges(); var securityHelper = Container.Resolve <SecurityTestHelper>(); securityHelper.PopulatePermissions(); var licenseeIds = new[] { licensee.Id }; var brandIds = new[] { brand.Id }; const string superAdminUsername = "******"; var adminId = RoleIds.SuperAdminId; var role = new Role { Id = adminId, Code = "SuperAdmin", Name = "SuperAdmin", CreatedDate = DateTime.UtcNow }; role.SetLicensees(licenseeIds); var user = new Core.Security.Data.Users.Admin { Id = adminId, Username = superAdminUsername, FirstName = superAdminUsername, LastName = superAdminUsername, IsActive = true, Description = superAdminUsername, Role = role }; user.SetLicensees(licenseeIds); foreach (var licenseeId in licenseeIds) { user.LicenseeFilterSelections.Add(new LicenseeFilterSelection { AdminId = user.Id, LicenseeId = licenseeId, Admin = user }); } user.SetAllowedBrands(brandIds); foreach (var item in brandIds) { user.BrandFilterSelections.Add(new BrandFilterSelection { AdminId = user.Id, BrandId = item, Admin = user }); } FakeSecurityRepository.Admins.AddOrUpdate(user); var authCommands = Container.Resolve <IAuthCommands>(); authCommands.CreateRole(new CreateRole { RoleId = adminId, Permissions = Container.Resolve <IAuthQueries>().GetPermissions().Select(p => p.Id).ToList() }); authCommands.CreateActor(new CreateActor { ActorId = adminId, Username = superAdminUsername, Password = superAdminUsername }); authCommands.AssignRoleToActor(new AssignRole { ActorId = adminId, RoleId = adminId }); FakeSecurityRepository.SaveChanges(); securityHelper.SignInAdmin(user); var testServerUri = ConfigurationManager.AppSettings["TestServerUri"]; TestStartup.Container = Container; _webServer = WebApp.Start <TestStartup>(testServerUri); PlayerWebservice = new MemberApiProxy(testServerUri); }
// draws a single Paper Wallet in to a PdfSharp XForm private PdfSharp.Drawing.XForm getSingleWallet(PdfDocument doc, WalletBundle b, XImage imgArtwork, string address, string privkey, int numberWithinBatch, bool layoutDebugging) { WalletTemplate t = b.template; double width = t.widthMM; double height = t.heightMM; XUnit walletSizeWide = XUnit.FromMillimeter(width); XUnit walletSizeHigh = XUnit.FromMillimeter(height); PdfSharp.Drawing.XForm form = new PdfSharp.Drawing.XForm(doc, walletSizeWide, walletSizeHigh); using (XGraphics formGfx = XGraphics.FromForm(form)) { XGraphicsState state = formGfx.Save(); bool interpolateArtwork = true; bool interpolateQRcodes = false; // XImage imgArtwork is now provided by caller, so this process only has to be done ONCE - because the artwork does not change between Wallets in a run! //XImage imgArtwork = XImage.FromGdiPlusImage(b.getArtworkImage()); imgArtwork.Interpolate = interpolateArtwork; formGfx.DrawImage(imgArtwork, new RectangleF(0f, 0f, (float)walletSizeWide.Point, (float)walletSizeHigh.Point)); // draw the QR codes and legible-text things // Address // QR Bitmap bmpAddress = BtcAddress.QR.EncodeQRCode(address); XImage imgAddress = XImage.FromGdiPlusImage(bmpAddress); imgAddress.Interpolate = interpolateQRcodes; XUnit addressQrLeft = XUnit.FromMillimeter(t.addressQrLeftMM); XUnit addressQrTop = XUnit.FromMillimeter(t.addressQrTopMM); XUnit addressQrSize = XUnit.FromMillimeter(t.addressQrSizeMM); // only print Address QR if called for if (t.addressQrSizeMM > 0.1) { XRect addressQrRect = new XRect(addressQrLeft.Point, addressQrTop.Point, addressQrSize.Point, addressQrSize.Point); formGfx.DrawImage(imgAddress, addressQrRect); } // text address string addressSplitForLines = addressOrReferencePrep(address, t.addressTextCharsPerLine, t.addressTextContentVariant, numberWithinBatch); XFont fontAddress = new XFont(t.addressTextFontName, t.addressTextFontSize, t.addressTextFontStyle); XTextFormatter tf = new XTextFormatter(formGfx); XUnit addressTxtLeft = XUnit.FromMillimeter(t.addressTextLeftMM); XUnit addressTxtTop = XUnit.FromMillimeter(t.addressTextTopMM); XUnit addressTxtWidth = XUnit.FromMillimeter(t.addressTextWidthMM); XUnit addressTxtHeight = XUnit.FromMillimeter(t.addressTextHeightMM); XRect addressRect = new XRect(addressTxtLeft.Point, addressTxtTop.Point, addressTxtWidth.Point, addressTxtHeight.Point); tf.Alignment = XParagraphAlignment.Center; TextRotation addressTxtRotation = t.addressTextRotation; double addressTxtRotationDegrees = RotationMarkerToDegrees(addressTxtRotation); if (layoutDebugging) { formGfx.DrawRectangle(XBrushes.PowderBlue, addressRect); } XPoint rotateCentre = new XPoint(addressTxtLeft + (addressTxtWidth / 2), addressTxtTop + (addressTxtHeight / 2)); XPoint matrixRotatePoint = new XPoint(addressRect.X + (addressRect.Width / 2), addressRect.Y + (addressRect.Height / 2)); XMatrix rotateMatrix = new XMatrix(); rotateMatrix.RotateAtAppend(addressTxtRotationDegrees, rotateCentre); addressRect.Transform(rotateMatrix); if (layoutDebugging) { // draw a little tracer dot for where the centre of rotation is going to be double rotateDotSize = 2.0; formGfx.DrawEllipse(XBrushes.Red, rotateCentre.X - (rotateDotSize / 2), rotateCentre.Y - (rotateDotSize / 2), rotateDotSize, rotateDotSize); } // maybe even do some rotation of the lovely text! formGfx.Save(); formGfx.RotateAtTransform(addressTxtRotationDegrees, rotateCentre); if (layoutDebugging) { formGfx.DrawRectangle(XPens.OrangeRed, addressRect); } if (t.addressTextWidthMM > 0.1) { tf.DrawString(addressSplitForLines, fontAddress, t.GetBrushAddress, addressRect); } formGfx.Restore(); // Privkey // QR Bitmap bmpPrivkey = BtcAddress.QR.EncodeQRCode(privkey); XImage imgPrivkey = XImage.FromGdiPlusImage(bmpPrivkey); imgPrivkey.Interpolate = interpolateQRcodes; XUnit privkeyQrLeft = XUnit.FromMillimeter(t.privkeyQrLeftMM); XUnit privkeyQrTop = XUnit.FromMillimeter(t.privkeyQrTopMM); XUnit privkeyQrSize = XUnit.FromMillimeter(t.privkeyQrSizeMM); XRect privkeyQrRect = new XRect(privkeyQrLeft.Point, privkeyQrTop.Point, privkeyQrSize.Point, privkeyQrSize.Point); // only print privkey QR if specified - but you'd have to be an UTTER IDIOT to want to exclude this. Still, user input comes first! if (t.privkeyQrSizeMM > 0.1) { formGfx.DrawImage(imgPrivkey, privkeyQrRect); } // legible string privkeySplitForLines = lineSplitter(privkey, t.privkeyTextCharsPerLine); XFont fontPrivkey = new XFont(t.privkeyTextFontName, t.privkeyTextFontSize, t.privkeyTextFontStyle); XUnit privkeyTxtLeft = XUnit.FromMillimeter(t.privkeyTextLeftMM); XUnit privkeyTxtTop = XUnit.FromMillimeter(t.privkeyTextTopMM); XUnit privkeyTxtWidth = XUnit.FromMillimeter(t.privkeyTextWidthMM); XUnit privkeyTxtHeight = XUnit.FromMillimeter(t.privkeyTextHeightMM); TextRotation privkeyTxtRotation = t.privkeyTextRotation; double privkeyTxtRotationDegrees = RotationMarkerToDegrees(privkeyTxtRotation); XRect privkeyRect = new XRect(privkeyTxtLeft.Point, privkeyTxtTop.Point, privkeyTxtWidth.Point, privkeyTxtHeight.Point); if (layoutDebugging) { // draw a tracer rectangle for the original un-rotated text rectangle formGfx.DrawRectangle(XBrushes.PowderBlue, privkeyRect); } // rotate that lovely text around its middle when drawing! rotateCentre = new XPoint(privkeyTxtLeft + (privkeyTxtWidth / 2), privkeyTxtTop + (privkeyTxtHeight / 2)); matrixRotatePoint = new XPoint(privkeyRect.X + (privkeyRect.Width / 2), privkeyRect.Y + (privkeyRect.Height / 2)); rotateMatrix = new XMatrix(); rotateMatrix.RotateAtAppend(privkeyTxtRotationDegrees, rotateCentre); privkeyRect.Transform(rotateMatrix); if (layoutDebugging) { // draw a little tracer dot for where the centre of rotation is going to be double rotateDotSize = 2.0; formGfx.DrawEllipse(XBrushes.Red, rotateCentre.X - (rotateDotSize / 2), rotateCentre.Y - (rotateDotSize / 2), rotateDotSize, rotateDotSize); } formGfx.Save(); formGfx.RotateAtTransform(privkeyTxtRotationDegrees, rotateCentre); if (layoutDebugging) { formGfx.DrawRectangle(XPens.OrangeRed, privkeyRect); } // only print privkey text if specified. if (t.privkeyTextWidthMM > 0.1) { tf.DrawString(privkeySplitForLines, fontPrivkey, t.GetBrushPrivkey, privkeyRect); } formGfx.Restore(); } return(form); }