Пример #1
0
        public async Task <IActionResult> ActiveDirectGate(string userId, string id, ActiveDirectGateDto activeDirectGateDto)
        {
            var gateFromRepo = (await _db.GateRepository
                                .GetManyAsync(p => p.Id == id, null, "Wallet")).SingleOrDefault();

            if (gateFromRepo == null)
            {
                return(BadRequest("درگاهی وجود ندارد"));
            }
            if (!gateFromRepo.IsActive)
            {
                return(BadRequest("درگاه فعال نمیباشد"));
            }
            if (gateFromRepo.Wallet.UserId == User.FindFirst(ClaimTypes.NameIdentifier).Value)
            {
                if (activeDirectGateDto.IsDirect)
                {
                    if (await _walletService.CheckInventoryAsync(20000, activeDirectGateDto.WalletId))
                    {
                        var decResult = await _walletService.DecreaseInventoryAsync(20000, activeDirectGateDto.WalletId);

                        if (decResult.status)
                        {
                            gateFromRepo.IsDirect = activeDirectGateDto.IsDirect;
                            _db.GateRepository.Update(gateFromRepo);

                            if (await _db.SaveAsync())
                            {
                                return(NoContent());
                            }
                            else
                            {
                                var incResult = await _walletService.IncreaseInventoryAsync(20000, activeDirectGateDto.WalletId);

                                if (incResult.status)
                                {
                                    return(BadRequest("خطا در ثبت اطلاعات"));
                                }
                                else
                                {
                                    return(BadRequest("خطا در ثبت اطلاعات در صورت کسری موجودی با پشتیبانی در تماس باشید"));
                                }
                            }
                        }
                        else
                        {
                            return(BadRequest(decResult.message));
                        }
                    }
                    else
                    {
                        return(BadRequest("کیف پول انتخابی موجودی کافی ندارد"));
                    }
                }
                else
                {
                    gateFromRepo.IsDirect = activeDirectGateDto.IsDirect;
                    _db.GateRepository.Update(gateFromRepo);

                    if (await _db.SaveAsync())
                    {
                        return(NoContent());
                    }
                    else
                    {
                        return(BadRequest("خطا در ثبت اطلاعات"));
                    }
                }
            }
            else
            {
                _logger.LogError($"کاربر   {RouteData.Values["userId"]} قصد اپدیت به درگاه دیگری را دارد");

                return(BadRequest("شما اجازه اپدیت درگاه کاربر دیگری را ندارید"));
            }
        }
Пример #2
0
        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("این کیف پول قبلا ثبت شده است"));
            }
        }