public UpdateCountryCommandHandler( WalletDbContext context, INotificationService notificationService) { _context = context; _notificationService = notificationService; }
public OrderStockUpdatedHandler(WalletDbContext dbContext, ILogger <OrderStockUpdatedHandler> logger, IKafkaMessageProducer kafkaMessageProducer) { _dbContext = dbContext; _logger = logger; _kafkaMessageProducer = kafkaMessageProducer; }
private static async Task InsertPageElements(WalletDbContext context) { if (context.PageData.Any()) { return; } var data = new List <PageData>() { new PageData() { ElementName = "AboutPage", ElementData = "Test data for about page" }, new PageData() { ElementName = "ContactPage", ElementData = "Test data for contact page" }, new PageData() { ElementName = "TipsETH", ElementData = "0x53d284357ec70ce289d6d64134dfac8e511c8a3d" }, new PageData() { ElementName = "TipsBTC", ElementData = "0x742d35cc6634c0532925a3b844bc454e4438f44e" } }; context.PageData.AddRange(data); await context.SaveChangesAsync(); }
public DeleteSavedCardCommandHandler( WalletDbContext context, INotificationService notificationService) { _context = context; _notificationService = notificationService; }
public int CancelCrashApply(DateTime outTime) { using (var dbContext = new WalletDbContext()) { var query = dbContext.CrashApplys.Where(ca => ca.ApplyState == ApplyState.Applying && ca.CreateTime < outTime).ToList(); int success = 0; foreach (var apply in query) { using (TransactionScope scope = new TransactionScope()) { string error; if (Thaw(apply.MemberId, WalletType.Cash, apply.Money, "申请超时未审核,自动取消", out error)) { apply.ApplyState = ApplyState.Failure; _currencyService.Update(apply); Logger.Operation($"申请超时未审核,自动取消,单号:{apply.TransactionNo}", WalletModule.Instance, Security.SecurityLevel.Warning); success++; } //提交 scope.Complete(); } } return(success); } }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, WalletDbContext walletDbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); var extenderDbConnectionString = Configuration.GetConnectionString(WalletDbContext.ConnectionStringName); if (!SqlServerDbUtil.DatabaseExists(extenderDbConnectionString)) { SqlServerDbUtil.CreateDatabase(extenderDbConnectionString, collation: "SQL_Latin1_General_CP1_CI_AI"); walletDbContext.Database.EnsureCreated(); } } app.UseHttpsRedirection(); app.UseCustomExceptionHandler(); app.UseRouting(); if (!env.IsProduction()) { app.UseSwagger(); app.UseSwaggerUI(o => { o.SwaggerEndpoint($"/swagger/{SwaggerApiDocumentationKey}/swagger.json", "Wallet API v1"); o.DocExpansion(DocExpansion.None); }); } app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public bool Thaw(string memberId, WalletType walletType, decimal money, string remark, out string error) { error = string.Empty; if (money == 0) { return(true); } using (var dbContext = new WalletDbContext()) { var wallet = dbContext.Set <Models.Wallet>() .FirstOrDefault(w => w.WalletType == walletType && w.MemberId.Equals(memberId, StringComparison.OrdinalIgnoreCase)); if (wallet == null) { error = "冻结金额不足"; return(false); } else { if (wallet.Frozen < money) { error = "冻结金额不足"; return(false); } wallet.Available += money; wallet.Frozen -= money; dbContext.Set <Models.Wallet>().Attach(wallet); dbContext.Entry(wallet).State = EntityState.Modified; } dbContext.SaveChanges(); return(true); } }
public CreatePaymentMethodCommandHandler( WalletDbContext context, INotificationService notificationService) { _context = context; _notificationService = notificationService; }
/// <summary> /// 提现申请 /// </summary> /// <returns></returns> public bool AuditApply(Guid id) { using (var dbContext = new WalletDbContext()) { CrashApply crashApply = dbContext.CrashApplys.FirstOrDefault(c => c.Id == id); if (crashApply == null) { throw new Exception("找不到提现的记录"); } crashApply.ApplyState = ApplyState.ApplyPassed; crashApply.AuditTime = DateTime.Now; dbContext.Set <CrashApply>().Attach(crashApply); dbContext.Entry(crashApply).State = EntityState.Modified; Models.Wallet wallet = GetWalletByMemberId(crashApply.MemberId); if (wallet == null) { throw new Exception("钱包是空的"); } else if (crashApply.Money > wallet.Frozen) { throw new Exception("提现的金额不能大于冻结的金额"); } return(dbContext.SaveChanges() > 0); } }
public UnitOfWork(WalletDbContext context) { _context = context; Report = new ReportRepository(context); Transaction = new TransactionRepository(context); ManageCatsAndSubsRepository = new ManageCatsAndSubsRepository(context); }
public CreateWalletAccountCommandHandler( WalletDbContext context, INotificationService notificationService) { _context = context; _notificationService = notificationService; }
public CreateCurrencyCommandHandler( WalletDbContext context, INotificationService notificationService) { _context = context; _notificationService = notificationService; }
public async Task Wallet() { var user_id = this.Context.Message.Author.AvatarId; long guild_id = (long)this.Context.Guild.Id; using (var db = new DatabaseContext()) { db.Database.Initialize(true); } if (this.ValidateUser(user_id, guild_id)) { using (var db = new WalletDbContext()) { var row = db.Wallets.SingleOrDefault(u => u.User_id == user_id && u.Guild_id == guild_id); using (var wdb = new WalletInfoDbContext()) { var info = wdb.WalletInfos.SingleOrDefaultAsync(w => w.Guid == row.Guid); var user = Context.User.Mention; this.Context.Channel.SendMessageAsync(user + "Your wallet balance is : " + info.Result.Points); } } } else { this.Context.Channel.SendMessageAsync("You must !register first to obtain a wallet."); } }
private void SaveToDb <T>(List <T> collectionToInsert) where T : class { WalletDbContext context = null; try { context = new WalletDbContext(DbContextOptionsFactory.DbContextOptions()); context.ChangeTracker.AutoDetectChangesEnabled = false; int count = 0; foreach (var entity in collectionToInsert) { ++count; context = AddToContext(context, entity, count, 100, true); } context.SaveChanges(); } finally { if (context != null) { context.Dispose(); } } }
public RegisterUserCommandHandler( WalletDbContext context, INotificationService notificationService) { _context = context; _notificationService = notificationService; }
public DeleteRecipientCommandHandler( WalletDbContext context, INotificationService notificationService) { _context = context; _notificationService = notificationService; }
public WalletManager(ILogger <WalletManager> log, IConfiguration configuration, IHttpContextAccessor httpContextAccessor, IRepository <Wallet> walletrepo, ICurrencyManager currency, WalletDbContext context, IRepository <FXUser> fxuser) { _walletrepo = walletrepo ?? throw new ArgumentNullException(nameof(walletrepo)); this.log = log ?? throw new ArgumentNullException(nameof(log)); this.configuration = configuration; _httpContextAccessor = httpContextAccessor; _currency = currency; Context = context; _fxuser = fxuser; }
public CurrencyManager(IRepository <FXUser> userrepository, ILogger <CurrencyManager> log, IConfiguration configuration, IHttpContextAccessor httpContextAccessor, IHttpClientFactory httpClientFactory, IRepository <Wallet> wallet = null, WalletDbContext ctx = null) { _userrepository = userrepository ?? throw new ArgumentNullException(nameof(userrepository)); this.log = log ?? throw new ArgumentNullException(nameof(log)); this.configuration = configuration; _httpContextAccessor = httpContextAccessor; _httpClientFactory = httpClientFactory; _wallet = wallet; _ctx = ctx; }
private static async Task InsertTokens(WalletDbContext context) { if (context.Erc20Tokens.Any()) { return; } var tokens = ERC20TokensData.GetTokens(); context.Erc20Tokens.AddRange(tokens); await context.SaveChangesAsync(); }
public List <CrashApply> GetCrashApplyByPage <TKey>(int pageNo, int limit, Expression <Func <CrashApply, bool> > expression, Expression <Func <CrashApply, TKey> > orderByExpression, bool isDesc, out int totalCount) { using (var dbContext = new WalletDbContext()) { var query = dbContext.CrashApplys.Where(expression); totalCount = query.Count(); query = isDesc ? query.OrderByDescending(orderByExpression) : query.OrderBy(orderByExpression); var list = query.Skip((pageNo - 1) * limit).Take(limit).ToList(); return(list); } }
public bool Draw(string memberId, WalletType walletType, decimal money, string remark, out string error, string tag = null, string toMemberId = null, bool drawFrozen = false) { error = string.Empty; if (money == 0) { return(true); } using (var dbContext = new WalletDbContext()) { var wallet = dbContext.Set <Models.Wallet>() .FirstOrDefault(w => w.WalletType == walletType && w.MemberId == memberId); if (drawFrozen) { if (wallet == null || wallet.Frozen < money) { error = "冻结余额不足"; return(false); } wallet.Frozen -= money; } else { if (wallet == null || wallet.Available < money) { error = "余额不足"; return(false); } wallet.Available -= money; } dbContext.Set <Models.Wallet>().Attach(wallet); dbContext.Entry(wallet).State = EntityState.Modified; WalletBill walletBill = new WalletBill(); walletBill.Id = KeyGenerator.GetGuidKey(); walletBill.MemberId = memberId; walletBill.BillType = BillType.TakeOut; walletBill.WalletType = walletType; walletBill.Money = money; walletBill.Remark = remark; walletBill.BillTag = tag; walletBill.CreateTime = DateTime.Now; walletBill.FromMemberId = toMemberId; dbContext.WalletBills.Add(walletBill); dbContext.SaveChanges(); return(true); } }
public async Task Topup() { var amount = 20; var time = 1; var user_id = this.Context.Message.Author.AvatarId; long guild_id = (long)this.Context.Guild.Id; DateTime current = DateTime.Now; using (var db = new DatabaseContext()) { db.Database.Initialize(true); } using (var db = new WalletDbContext()) { var row = db.Wallets.SingleOrDefault(u => u.User_id == user_id && u.Guild_id == guild_id); using (var wdb = new WalletInfoDbContext()) { var info = wdb.WalletInfos.SingleOrDefaultAsync(w => w.Guid == row.Guid); var user = Context.User.Mention; WalletInfo walletinfo = (from x in wdb.WalletInfos where x.Guid == row.Guid select x).First(); if (info.Result.Modified_on <= current.AddHours(-time)) { walletinfo.Points = walletinfo.Points + amount; walletinfo.TopupAmount = walletinfo.TopupAmount + amount; walletinfo.TopupCount = walletinfo.TopupCount + 1; walletinfo.Modified_on = current; this.Context.Channel.SendMessageAsync(user + " Topup successfull. Your new wallet balance is : " + walletinfo.Points); } else { walletinfo.TopupFail = walletinfo.TopupFail + 1; TimeSpan span = current.Subtract(info.Result.Modified_on); if (time == 1) { this.Context.Channel.SendMessageAsync(user + "You may top up every hour. It has been " + (int)span.TotalMinutes + " minutes since your last topup."); } else { this.Context.Channel.SendMessageAsync(user + "You may top up every " + time + " hours. It has been " + (int)span.TotalMinutes + " minutes since your last topup."); } } wdb.SaveChanges(); } } }
private WalletDbContext AddToContext <T>(WalletDbContext context, T entity, int count, int commitCount, bool recreateContext) where T : class { context.Set <T>().Add(entity); if (count % commitCount == 0) { context.SaveChanges(); if (recreateContext) { context.Dispose(); context = new WalletDbContext(DbContextOptionsFactory.DbContextOptions()); context.ChangeTracker.AutoDetectChangesEnabled = false; } } return(context); }
public bool Deposit(string memberId, WalletType walletType, decimal money, string remark, out string error, string tag = null, string fromMemberId = null) { error = string.Empty; if (money == 0) { return(true); } using (var dbContext = new WalletDbContext()) { var wallet = dbContext.Set <Models.Wallet>() .FirstOrDefault(w => w.WalletType == walletType && w.MemberId.Equals(memberId, StringComparison.OrdinalIgnoreCase)); if (wallet == null) { wallet = new Models.Wallet(); wallet.Id = KeyGenerator.GetGuidKey(); wallet.MemberId = memberId; wallet.WalletType = walletType; wallet.Frozen = 0; wallet.Available = money; dbContext.Wallets.Add(wallet); } else { wallet.Available += money; dbContext.Set <Models.Wallet>().Attach(wallet); dbContext.Entry(wallet).State = EntityState.Modified; } WalletBill walletBill = new WalletBill(); walletBill.Id = KeyGenerator.GetGuidKey(); walletBill.MemberId = memberId; walletBill.BillType = BillType.TakeIn; walletBill.WalletType = walletType; walletBill.Money = money; walletBill.Remark = remark; walletBill.BillTag = tag; walletBill.CreateTime = DateTime.Now; walletBill.FromMemberId = fromMemberId; dbContext.WalletBills.Add(walletBill); dbContext.SaveChanges(); return(true); } }
private static async Task InsertUser(WalletDbContext context, UserManager <User> userManager, RoleManager <IdentityRole> roleManager) { if ((await context.Users.FirstOrDefaultAsync(u => u.Email == "*****@*****.**")) != null) { return; } const string email = "*****@*****.**"; const string role = "Admin"; await CreateDefaultAdministratorRole(roleManager, role); var user = await CreateDefaultUser(userManager, email); await AddDefaultRoleToDefaultUser(userManager, role, user); user.EmailConfirmed = true; await context.SaveChangesAsync(); }
/// <summary> /// 申请提现 /// </summary> public bool ApplyCrash(string memberId, string account, decimal money, PaymentType paymentType, string name) { using (var dbContext = new WalletDbContext()) { CrashApply crashApply = new CrashApply(); crashApply.Id = KeyGenerator.GetGuidKey(); crashApply.MemberId = memberId; crashApply.Account = account; crashApply.TransactionNo = KeyGenerator.GetOrderNumber(); crashApply.RealName = name; crashApply.Money = money; crashApply.PaymentType = paymentType; crashApply.ApplyState = ApplyState.Applying; crashApply.CreateTime = DateTime.Now; dbContext.CrashApplys.Add(crashApply); if (paymentType == PaymentType.WeiXin) { //判断是否绑定了微信 } Models.Wallet wallet = GetWalletByMemberId(memberId); if (wallet == null) { throw new WebApiInnerException("0003", "钱包没有可以提现的余额"); } else { if (money > wallet.Available) { throw new WebApiInnerException("0004", "提现的金额不能大于钱包的余额"); } wallet.Frozen += money; wallet.Available -= money; } dbContext.Set <Models.Wallet>().Attach(wallet); dbContext.Entry(wallet).State = EntityState.Modified; return(dbContext.SaveChanges() > 0); } }
public decimal Sum(string memberId, WalletType walletType, BillType?billType, string billTag = null, DateTime?startTime = null, DateTime?endTime = null, string fromMemberId = null) { Expression <Func <WalletBill, bool> > expression = wb => wb.WalletType == walletType && wb.MemberId.Equals(memberId); using (var dbContext = new WalletDbContext()) { var query = dbContext.WalletBills.Where(expression); if (billType != null) { var billTypeValue = billType.Value; query = query.Where(wb => wb.BillType == billTypeValue); } if (!string.IsNullOrWhiteSpace(billTag)) { query = query.Where(wb => wb.BillTag.Equals(billTag, StringComparison.OrdinalIgnoreCase)); } if (startTime != null) { var startTimeValue = startTime.Value; query = query.Where(wb => wb.CreateTime >= startTimeValue); } if (endTime != null) { var endTimeValue = endTime.Value; query = query.Where(wb => wb.CreateTime <= endTimeValue); } if (!string.IsNullOrWhiteSpace(fromMemberId)) { query = query.Where(wb => wb.FromMemberId.Equals(fromMemberId, StringComparison.OrdinalIgnoreCase)); } return(query.Sum(wb => (decimal?)wb.Money) ?? 0); } }
/// <summary> /// 获取我的钱包账单 /// </summary> /// <param name="memberId"></param> /// <param name="pageNo"></param> /// <param name="limit"></param> /// <param name="totalCount"></param> /// <param name="walletType"></param> /// <param name="billType"></param> /// <param name="billTag"></param> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <returns></returns> public List <WalletBill> GetWalletBillByMemberId(string memberId, int pageNo, int limit, out int totalCount, WalletType walletType = WalletType.Cash, BillType?billType = null, string billTag = null, DateTime?startTime = null, DateTime?endTime = null) { Expression <Func <WalletBill, bool> > expression = wb => wb.MemberId.Equals(memberId, StringComparison.OrdinalIgnoreCase) && wb.WalletType == walletType; using (var dbContext = new WalletDbContext()) { var query = dbContext.WalletBills.Where(expression); if (billType != null) { var billTypeValue = billType.Value; query = query.Where(wb => wb.BillType == billTypeValue); } if (!string.IsNullOrWhiteSpace(billTag)) { query = query.Where(wb => wb.BillTag.Equals(billTag, StringComparison.OrdinalIgnoreCase)); } if (startTime != null) { var startTimeValue = startTime.Value; query = query.Where(wb => wb.CreateTime >= startTimeValue); } if (endTime != null) { var endTimeValue = endTime.Value; query = query.Where(wb => wb.CreateTime <= endTimeValue); } totalCount = query.Count(); query = query.OrderByDescending(wb => wb.CreateTime); return(query.AsQueryable().Skip((pageNo - 1) * limit).Take(limit).ToList()); } }
public WalletRepository(WalletDbContext dbContext) : base(dbContext) { }
public WalletController(WalletDbContext dbContext) { _dbContext = dbContext; }