public async Task <IActionResult> PutTransaction(string id, Transaction transaction) { if (id != transaction.Id) { return(BadRequest(new ResponseResult("Id trong giao dịch phải giống nhau"))); } _context.Entry(transaction).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TransactionExists(id)) { return(BadRequest(new ResponseResult("Không tìm thấy giao dịch!"))); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutOwnerBank(Guid id, OwnerBank ownerBank) { if (id != ownerBank.Id) { return(BadRequest()); } _context.Entry(ownerBank).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OwnerBankExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutTransactionHistory(string id, TransactionHistory transactionHistory) { if (id != transactionHistory.Id) { return(BadRequest()); } _context.Entry(transactionHistory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TransactionHistoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutWallet(string id, WalletViewModel wallet) { if (id != wallet.Id) { return(BadRequest()); } try { var currentWallet = await _context.Wallets.Where(x => x.Id == id).FirstOrDefaultAsync(); var user = await _context.AppUsers.Where(x => x.Id.ToString() == currentWallet.UserId).FirstOrDefaultAsync(); var newCoin = wallet.Coin - currentWallet.Coin; var newPromotionCoin = wallet.PromotionCoin - currentWallet.PendingCoin; var transactionHistory = new TransactionHistory { Id = Guid.NewGuid().ToString(), UserId = wallet.UserId, BillStatus = BillStatus.Completed, Coin = Math.Abs(newCoin), DateCreated = DateTime.Now, Status = Status.Active, TransactionHistoryType = (newCoin > 0) ? TransactionHistoryType.PayIn : TransactionHistoryType.Withdraw, }; string notifyTransaction = " đã nạp "; if (transactionHistory.TransactionHistoryType == TransactionHistoryType.Withdraw) { notifyTransaction = " đã rút "; } transactionHistory.Content = "Tài khoản " + user.UserName + notifyTransaction + newCoin + " vào lúc " + transactionHistory.DateCreated.ToString("dd/MM/yyyy hh:mm:ss tt"); _context.TransactionHistories.Add(transactionHistory); currentWallet.PromotionCoin = wallet.PromotionCoin; currentWallet.Coin = wallet.Coin; _context.Wallets.Update(currentWallet); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WalletExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <BankCard> > DeleteBankCard(string id) { var bankCard = await _context.BankCards.FindAsync(id); if (bankCard == null) { return(NotFound()); } _context.BankCards.Remove(bankCard); await _context.SaveChangesAsync(); return(bankCard); }
public async Task <ActionResult <De_Lotto> > DeleteDe_Lotto(string id) { var de_Lotto = await _context.De_Lottos.FindAsync(id); if (de_Lotto == null) { return(NotFound()); } _context.De_Lottos.Remove(de_Lotto); await _context.SaveChangesAsync(); return(de_Lotto); }
// Đăng ký thường không qua tài khoản nào public async Task <bool> Register(AppUserViewModel request) { var user = new AppUser() { DateOfBirth = request.DateOfBirth, Email = request.Email, FirstName = (string.IsNullOrEmpty(request.FirstName))? request.FirstName: "", LastName = (string.IsNullOrEmpty(request.LastName)) ? request.LastName : "", UserName = request.UserName, PhoneNumber = request.PhoneNumber, Avatar = request.Avatar, NickName = request.NickName, TransactionPassword = request.TransactionPassword, Id = Guid.NewGuid() }; if (!string.IsNullOrEmpty(request.RootUserId)) { // generate link ref var rootUser = _context.AppUsers.Where(x => x.Id.ToString() == request.RootUserId).FirstOrDefault(); if (rootUser != null) { user.RootUserId = rootUser.Id; user.RefRegisterLink = DomainConsts.LotteryDomain + "/api/Users/register/" + user.Id.ToString(); } } // create wallet var wallet = new Wallet { DateCreated = DateTime.Now, Coin = 0, PendingCoin = 0, PromotionCoin = 0, Status = Status.Active, WalletId = TextHelper.RandomString(10), Id = Guid.NewGuid().ToString(), UserId = "" }; _context.Wallets.Add(wallet); await _context.SaveChangesAsync(); var newWallet = _context.Wallets.Where(x => string.IsNullOrEmpty(x.UserId)).FirstOrDefault(); user.WalletId = newWallet.WalletId; var result = await _userManager.CreateAsync(user, request.Password); if (result.Succeeded) { newWallet.UserId = user.Id.ToString(); await _context.SaveChangesAsync(); var createdUser = await _context.AppUsers.Where(x => x.Id == user.Id).FirstOrDefaultAsync(); var createdUserView = Mapper.Map <AppUser, AppUserViewModel>(createdUser); return(true); } else { _context.Wallets.Remove(newWallet); await _context.SaveChangesAsync(); string error = ""; foreach (var e in result.Errors) { error += e.Description; } return(false); } }
public async Task <IActionResult> SeedData() { try { if (_context.Functions.ToList().Count == 0) { List <Function> functions = new List <Function>() { new Function() { Id = TextHelper.RandomString(10, false), Name = "Quyền Admin", Code = "ExportXLS", Status = Status.Active }, new Function() { Id = TextHelper.RandomString(10, false), Name = "Điều chỉnh tài khoản", Code = "Admin", Status = Status.Active }, new Function() { Id = TextHelper.RandomString(10, false), Name = "", Code = "Player", Status = Status.Active }, new Function() { Id = TextHelper.RandomString(10, false), Name = "", Code = "ProfitPercent.Read", Status = Status.Active }, new Function() { Id = TextHelper.RandomString(10, false), Name = "", Code = "ProfitPercent.Write", Status = Status.Active }, new Function() { Id = TextHelper.RandomString(10, false), Name = "", Code = "ProfitPercent.Delete", Status = Status.Active }, new Function() { Id = TextHelper.RandomString(10, false), Name = "", Code = "Account.Read", Status = Status.Active }, new Function() { Id = TextHelper.RandomString(10, false), Name = "", Code = "Account.Write", Status = Status.Active }, new Function() { Id = TextHelper.RandomString(10, false), Name = "", Code = "Account.Delete", Status = Status.Active }, new Function() { Id = TextHelper.RandomString(10, false), Name = "", Code = "Transaction.Read", Status = Status.Active }, new Function() { Id = TextHelper.RandomString(10, false), Name = "", Code = "Transaction.Write", Status = Status.Active }, new Function() { Id = TextHelper.RandomString(10, false), Name = "", Code = "Transaction.Delete", Status = Status.Active }, }; await _context.Functions.AddRangeAsync(functions); await _context.SaveChangesAsync(); } if (_context.AppUsers.ToList().Count == 0) { var user = new AppUser() { DateOfBirth = DateTime.Now, Email = "*****@*****.**", FirstName = "Admin", LastName = "Lottery", UserName = "******", PhoneNumber = "0900000000", Avatar = "", NickName = "Adminstrator", TransactionPassword = "******", RefRegisterLink = "", WalletId = "" }; var result = await _userManager.CreateAsync(user, "123123aA@"); await _context.AppUsers.AddAsync(user); } if (!_context.Wallets.Any()) { var user = _context.AppUsers.Where(x => x.UserName == "admin").FirstOrDefault(); var wallet = new Wallet { DateCreated = DateTime.Now, PendingCoin = 0, Coin = 999999999, Id = Guid.NewGuid().ToString(), Status = Status.Active, PromotionCoin = 0, WalletId = TextHelper.RandomString(10), UserId = user.Id.ToString() }; string walletId = wallet.WalletId; await _context.Wallets.AddAsync(wallet); _context.SaveChanges(); user.WalletId = walletId; _context.AppUsers.Update(user); _context.SaveChanges(); } if (!_context.OwnerBanks.Any()) { var banks = new List <OwnerBank> { new OwnerBank { FullNameOwner = "Adminstrator", BankName = "Ngân hàng ABC", AccountNumber = "xxxx xxxx xxxx xxxx", Branch = "Chi nhánh VN", }, new OwnerBank { FullNameOwner = "Adminstrator", BankName = "Ngân hàng ABC 1", AccountNumber = "xxxx xxxx xxxx xxxx", Branch = "Chi nhánh VN", }, new OwnerBank { FullNameOwner = "Adminstrator", BankName = "Ngân hàng ABC 2", AccountNumber = "xxxx xxxx xxxx xxxx", Branch = "Chi nhánh VN", } }; _context.OwnerBanks.AddRange(banks); _context.SaveChanges(); } if (_context.Permissions.ToList().Count == 0) { List <Permission> permissions = new List <Permission>(); var user = _context.Users.ToList()[0]; foreach (var fun in _context.Functions.ToList()) { var per = new Permission() { Id = Guid.NewGuid().ToString(), DateCreated = DateTime.Now, Status = Status.Active, UserId = user.Id, FunctionId = fun.Id }; permissions.Add(per); } await _context.Permissions.AddRangeAsync(permissions); } await _context.SaveChangesAsync(); return(Ok("Đã tạo được dữ liệu mẫu thành công")); } catch { return(BadRequest("Không tạo được dữ liệu mẫu")); } }
public async Task <ActionResult <Object> > PostAppUser(AppUserViewModel appUserView) { try { if (EmailExits(appUserView.Email) || string.IsNullOrEmpty(appUserView.Email)) { return(BadRequest(new ResponseResult("Email đã tồn tại hoặc bị bỏ trống!"))); } var user = new AppUser() { DateOfBirth = appUserView.DateOfBirth, Email = appUserView.Email, FirstName = appUserView.FirstName, LastName = appUserView.LastName, UserName = appUserView.UserName, PhoneNumber = appUserView.PhoneNumber, Avatar = appUserView.Avatar, NickName = appUserView.NickName, TransactionPassword = appUserView.TransactionPassword, Id = Guid.NewGuid() }; if (!string.IsNullOrEmpty(appUserView.RootUserId)) { // generate link ref var rootUser = _context.AppUsers.Where(x => x.Id.ToString() == appUserView.RootUserId).FirstOrDefault(); if (rootUser != null) { user.RootUserId = rootUser.Id; user.RefRegisterLink = DomainConsts.LotteryDomain + "/api/Users/register/" + user.Id.ToString(); } } // create wallet var wallet = new Wallet { DateCreated = DateTime.Now, Coin = 0, PendingCoin = 0, PromotionCoin = 0, Status = Status.Active, WalletId = TextHelper.RandomString(10), Id = Guid.NewGuid().ToString(), UserId = "" }; _context.Wallets.Add(wallet); await _context.SaveChangesAsync(); var newWallet = _context.Wallets.Where(x => string.IsNullOrEmpty(x.UserId)).FirstOrDefault(); user.WalletId = newWallet.WalletId; var result = await _userManager.CreateAsync(user, appUserView.Password); if (result.Succeeded) { newWallet.UserId = user.Id.ToString(); await _context.SaveChangesAsync(); var createdUser = await _context.AppUsers.Where(x => x.Id == user.Id).FirstOrDefaultAsync(); var createdUserView = Mapper.Map <AppUser, AppUserViewModel>(createdUser); return(createdUserView); ; } else { _context.Wallets.Remove(newWallet); await _context.SaveChangesAsync(); string error = ""; foreach (var e in result.Errors) { error += e.Description; } return(BadRequest(new ResponseResult(error))); } } catch (DbUpdateConcurrencyException) { throw new DbUpdateConcurrencyException("Lỗi hệ thống!"); } catch (Exception) { throw new Exception(); } }