public async Task <IActionResult> CreateWallet([FromBody] WalletForCreateDto walletForListDtos) { var user = await HttpContext.GetUserAsync(_userManager); var wallet = WalletFactory.CreateEmptyWallet(walletForListDtos.CurrencyCode); _mapper.Map(walletForListDtos, wallet); wallet.OwnerId = user.Id; await _repository.Add(wallet); await _repository.SaveChangesAsync(); var walletDto = _mapper.Map <WalletDto>(wallet); return(CreatedAtAction(nameof(GetWallet), new { id = walletDto.Id }, walletDto)); }
public async Task <IActionResult> AddWallet(string userId, WalletForCreateDto walletForCreateDto) { var walletFromRepo = await _db._WalletRepository .GetAsync(p => p.Name == walletForCreateDto.WalletName && p.UserId == userId); var walletCount = await _db._WalletRepository.WalletCountAsync(userId); if (walletFromRepo == null) { if (walletCount <= 10) { var code = await _db._WalletRepository.GetLastWalletCodeAsync() + 1; while (await _db._WalletRepository.WalletCodeExistAsync(code)) { code += 1; } if (await _walletService.CheckInventoryAsync(1000, walletForCreateDto.WalletId)) { var decResult = await _walletService.DecreaseInventoryAsync(1000, walletForCreateDto.WalletId); if (decResult.status) { var wallet = new Wallet() { UserId = userId, IsBlock = false, Code = code, Name = walletForCreateDto.WalletName, IsMain = false, IsSms = false, Inventory = 0, InterMoney = 0, ExitMoney = 0, OnExitMoney = 0 }; await _db._WalletRepository.InsertAsync(wallet); if (await _db.SaveAcync() > 0) { var walletForReturn = _mapper.Map <WalletForReturnDto>(wallet); return(CreatedAtRoute("GetWallet", new { id = wallet.Id, userId = userId }, walletForReturn)); } else { var incResult = await _walletService.IncreaseInventoryAsync(1000, walletForCreateDto.WalletId); if (incResult.status) { return(BadRequest("خطا در ثبت اطلاعات")); } else { return(BadRequest("خطا در ثبت اطلاعات در صورت کسری موجودی با پشتیبانی در تماس باشید")); } } } else { return(BadRequest(decResult.message)); } } else { return(BadRequest("کیف پول انتخابی موجودی کافی ندارد")); } } { return(BadRequest("شما اجازه وارد کردن بیش از 10 کیف پول را ندارید")); } } { return(BadRequest("این کیف پول قبلا ثبت شده است")); } }