public ActionResult <object> PostTransaction(Transaction transaction) { try { if (string.IsNullOrEmpty(transaction.Content)) { return(BadRequest(new ResponseResult("Nội dung không được để trống!"))); } var user = _context.AppUsers.Where(x => x.Id == transaction.UserId).FirstOrDefault(); if (user == null) { return(BadRequest(new ResponseResult("Không tìm thấy người dùng này! Vui lòng kiểm tra lại."))); } var wallet = _context.Wallets.Where(x => x.UserId == transaction.UserId.ToString()).FirstOrDefault(); if (wallet == null) { return(BadRequest(new ResponseResult("Không tìm tài khoản ví của bạn !, liên hệ giúp đỡ theo đường dây nóng"))); } if (TransactionType.Withdraw == transaction.TransactionType) { if (wallet.Coin < transaction.Coin) { return(BadRequest(new ResponseResult("Số tiền trong ví không đủ để thực hiện thao tác này!"))); } else { wallet.PendingCoin += transaction.Coin; wallet.Coin -= transaction.Coin; _context.Wallets.Update(wallet); } } transaction.Id = Guid.NewGuid().ToString(); transaction.DateCreated = DateTime.Now; transaction.Status = Status.Active; transaction.BillStatus = BillStatus.InProgress; _context.Transactions.Add(transaction); _context.SaveChanges(); var transViewModel = Mapper.Map <Transaction, TransactionViewModel>(transaction); return(transViewModel); } catch (DbUpdateException) { return(BadRequest(new ResponseResult("Lỗi! "))); } catch (Exception e) { return(BadRequest(new ResponseResult("Lỗi không xác định! " + e.Message))); } }
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> > Post_BettingOn_BaoLo_Lotto(BettingOnBaoLo bettingOnBaoLo) { /* * Nhận về là 1 string => danh sách các con số được ngăn cách nhau bởi dấu ";" or "," or " " * Xử lí: Tách chuỗi để lấy ra các con đề rồi insert vào db với các tài khoản tương ứng ticket */ try { if (string.IsNullOrEmpty(bettingOnBaoLo.BaoLoArray)) { return(BadRequest(new ResponseResult("Lỗi đặt cược!, danh sách cược không thể để trống."))); } // trường hợp không phải đầu cũng không phải đuôi thì xử lí bên dưới! var baoLoList = new List <string>(); if (bettingOnBaoLo.DivideType == DivideType.Comma) { baoLoList = new List <string>(bettingOnBaoLo.BaoLoArray.Split(',')); } if (bettingOnBaoLo.DivideType == DivideType.SemiColon) { baoLoList = new List <string>(bettingOnBaoLo.BaoLoArray.Split(';')); } if (bettingOnBaoLo.DivideType == DivideType.Space) { baoLoList = new List <string>(bettingOnBaoLo.BaoLoArray.Split(' ')); } if (baoLoList.Count <= 1) { return(BadRequest(new ResponseResult("Chọn sai định dạng ngăn cách!"))); } // loại bỏ các khoảng cách thừa và các phần tử rỗng, lọc các phần tử chỉ có 2 kí tự hoặc 3 kí tự là số baoLoList = baoLoList.Select(innerItem => innerItem?.Trim()) .Where(x => (!string.IsNullOrEmpty(x) && !string.IsNullOrWhiteSpace(x)) && ( (x.Length == 2 && (bettingOnBaoLo.Bao_LottoStatus == Bao_LottoStatus.Lo2So || bettingOnBaoLo.Bao_LottoStatus == Bao_LottoStatus.Lo2So1K || bettingOnBaoLo.Bao_LottoStatus == Bao_LottoStatus.Lo2SoDau)) || (x.Length == 3 && bettingOnBaoLo.Bao_LottoStatus == Bao_LottoStatus.Lo3So) || (x.Length == 4 && bettingOnBaoLo.Bao_LottoStatus == Bao_LottoStatus.Lo4So) ) && IsNumber(x) ).ToList(); if (baoLoList.Count == 0) { return(BadRequest(new ResponseResult("Bộ sô cược của bạn chọn không phù hợp. Yêu cầu kiểm tra lại!"))); } // kiểm tra xem đủ xiền để đặt với bộ số lọc đc ở trên không var walletOfUser = await _context.Wallets.Where(x => x.UserId == bettingOnBaoLo.UserId.ToString()).FirstOrDefaultAsync(); if (walletOfUser == null) { return(BadRequest(new ResponseResult("Không tìm thấy ví của bạn!"))); } double feeTotal = 0; double fee = 0; if (RegionStatus.North == bettingOnBaoLo.RegionStatus) { if (Bao_LottoStatus.Lo2So == bettingOnBaoLo.Bao_LottoStatus) { fee = BettingOnPrice.BaoLo2So_MienBac; } else { if (Bao_LottoStatus.Lo2SoDau == bettingOnBaoLo.Bao_LottoStatus || Bao_LottoStatus.Lo3So == bettingOnBaoLo.Bao_LottoStatus) { fee = BettingOnPrice.BaoLo3So_MienBac; } else { if (Bao_LottoStatus.Lo4So == bettingOnBaoLo.Bao_LottoStatus) { fee = BettingOnPrice.BaoLo4So_MienBac; } else { if (Bao_LottoStatus.Lo2So1K == bettingOnBaoLo.Bao_LottoStatus) { fee = BettingOnPrice.BaoLo2So1K_MienBac; } else { return(BadRequest(new ResponseResult("Lỗi sai định dạng cược!"))); } } } } } if (RegionStatus.Central == bettingOnBaoLo.RegionStatus) { if (Bao_LottoStatus.Lo2So == bettingOnBaoLo.Bao_LottoStatus) { fee = BettingOnPrice.BaoLo2So_MienTrung; } else { if (Bao_LottoStatus.Lo3So == bettingOnBaoLo.Bao_LottoStatus) { fee = BettingOnPrice.BaoLo3So_MienTrung; } else { if (Bao_LottoStatus.Lo4So == bettingOnBaoLo.Bao_LottoStatus) { fee = BettingOnPrice.BaoLo4So_MienTrung; } else { if (Bao_LottoStatus.Lo2So1K == bettingOnBaoLo.Bao_LottoStatus) { fee = BettingOnPrice.BaoLo2So1K_MienTrung; } else { return(BadRequest(new ResponseResult("Lỗi sai định dạng cược!"))); } } } } } if (RegionStatus.South == bettingOnBaoLo.RegionStatus) { if (Bao_LottoStatus.Lo2So == bettingOnBaoLo.Bao_LottoStatus) { fee = BettingOnPrice.BaoLo2So_MienNam; } else { if (Bao_LottoStatus.Lo3So == bettingOnBaoLo.Bao_LottoStatus) { fee = BettingOnPrice.BaoLo3So_MienNam; } else { if (Bao_LottoStatus.Lo4So == bettingOnBaoLo.Bao_LottoStatus) { fee = BettingOnPrice.BaoLo4So_MienNam; } else { if (Bao_LottoStatus.Lo2So1K == bettingOnBaoLo.Bao_LottoStatus) { fee = BettingOnPrice.BaoLo2So1K_MienNam; } else { return(BadRequest(new ResponseResult("Lỗi sai định dạng cược!"))); } } } } } feeTotal = baoLoList.Count * bettingOnBaoLo.MultipleNumber * fee; if (walletOfUser.Coin <= 0 || walletOfUser.Coin < feeTotal) { return(BadRequest(new ResponseResult("Số dư của bạn không đủ để đặt cược"))); } // trừ tiền ở ví trước khi đặt cược walletOfUser.Coin -= feeTotal; _context.Wallets.Update(walletOfUser); _context.SaveChanges(); var currentProfit = await _context.ProfitPercents.Where(x => x.Status == Status.Active && x.RegionStatus == bettingOnBaoLo.RegionStatus).FirstOrDefaultAsync(); var ticket = new Ticket() { RegionStatus = currentProfit.RegionStatus, Lo2So1K = currentProfit.Lo2So1K, Lo2So = currentProfit.Lo2So, Lo2SoDau = currentProfit.Lo2SoDau, Lo3So = currentProfit.Lo3So, Lo4So = currentProfit.Lo4So, Cang3 = currentProfit.Cang3, Dau = currentProfit.Dau, Cang4 = currentProfit.Cang4, DeDacBiet = currentProfit.DeDacBiet, DeDauDacBiet = currentProfit.DeDauDacBiet, DeGiai7 = currentProfit.DeGiai7, DeGiaiNhat = currentProfit.DeGiaiNhat, DeDau = currentProfit.DeDau, DeDauDuoi = currentProfit.DeDauDuoi, Duoi = currentProfit.Duoi, TruotXien10 = currentProfit.TruotXien10, TruotXien4 = currentProfit.TruotXien4, TruotXien8 = currentProfit.TruotXien8, Xien2 = currentProfit.Xien2, Xien3 = currentProfit.Xien3, Xien4 = currentProfit.Xien4, UserId = bettingOnBaoLo.UserId, Status = Status.Active, DateCreated = DateTime.Now, De_Total = 0, Bao_Total = feeTotal, Cang_Total = 0, Xien_Total = 0, ProvincialCity = bettingOnBaoLo.ProvincialCity, Id = Guid.NewGuid().ToString() }; ticket.Content = "Bao lô: "; foreach (var item in baoLoList) { ticket.Content += item + " "; } ticket.Content += "\nĐơn giá: " + fee * bettingOnBaoLo.MultipleNumber; await _context.Tickets.AddAsync(ticket); _context.SaveChanges(); List <Bao_Lotto> bao_Lottos = new List <Bao_Lotto>(); foreach (var baoLo in baoLoList) { var baoLoTemp = new Bao_Lotto() { Value = baoLo, Bao_LottoStatus = bettingOnBaoLo.Bao_LottoStatus, RegionStatus = bettingOnBaoLo.RegionStatus, ProvincialCity = bettingOnBaoLo.ProvincialCity, Price = fee * bettingOnBaoLo.MultipleNumber, IsGoal = null, DateCreated = DateTime.Now, Status = Status.Active, TicketId = ticket.Id, }; bao_Lottos.Add(baoLoTemp); } await _context.Bao_Lottos.AddRangeAsync(bao_Lottos); _context.SaveChanges(); return(Ok("Đặt cược thành công!")); } catch (DbUpdateException e) { return(BadRequest(new ResponseResult("Lỗi không xác định! " + e.Message))); } catch (Exception e) { return(BadRequest(new ResponseResult("Lỗi không xác định! " + e.Message))); } }
public ActionResult PutBankCard(string id, BankCardViewModel bankCardViewModel) { if (id != bankCardViewModel.Id) { return(BadRequest()); } var bankCardList = _context.BankCards.Where(x => x.UserId.ToString() == bankCardViewModel.UserId).ToList(); // Kiểm tra có trùng tên với tối đa 5 tài khoản và phải khác số tài khoản if (bankCardList.Count >= 5) { return(BadRequest(new ResponseResult("Bạn đã liên kết tối đa số tài khoản là 5 rồi!"))); } foreach (var bank in bankCardList) { if (bank.FullNameOwner != bankCardViewModel.FullNameOwner) { return(BadRequest(new ResponseResult("Tên của chủ tài khoản phải trùng với những thẻ còn lại!"))); } if (bank.BankAccountNumber == bankCardViewModel.BankAccountNumber) { return(BadRequest(new ResponseResult("Số tài khoản đã tồn tại!"))); } } // Kiểm tra toàn bộ tài khoản còn lại xem có trùng stk var otherBank = _context.BankCards.Where(x => x.UserId.ToString() != bankCardViewModel.UserId && x.BankAccountNumber == bankCardViewModel.BankAccountNumber).ToList(); if (otherBank.Count != 0) { return(BadRequest(new ResponseResult("Số tài khoản đã tồn tại!"))); } var bankCard = _context.BankCards.Find(bankCardViewModel.Id); bankCard.BankAccountNumber = bankCardViewModel.BankAccountNumber; bankCard.BankBranch = bankCardViewModel.BankBranch; bankCard.BankName = bankCardViewModel.BankName; bankCard.FullNameOwner = bankCardViewModel.FullNameOwner; try { _context.BankCards.Update(bankCard); _context.SaveChanges(); return(Ok(new ResponseResult("Cập nhật ngân hàng thành công!"))); } catch (DbUpdateConcurrencyException) { if (!BankCardExists(id)) { return(BadRequest(new ResponseResult("Không tìm thấy thông tin thẻ này!"))); } else { return(BadRequest(new ResponseResult("Lỗi không xác định!"))); } } }