Example #1
0
        public async Task <IHttpActionResult> CreateUserWalletAsync(int id, [FromBody] WalletInputModel inputModel)
        {
            var wallet = await _service.AddUserWalletAsync(id, inputModel);

            var url = Url.LinkController("wallets", wallet.Id);

            return(Created(url, wallet));
        }
Example #2
0
        public async Task <Wallet> AddUserWalletAsync(int userId, WalletInputModel inputModel)
        {
            var user = await _userService.GetAsync(userId);

            var wallet = Mapper.Map <Wallet>(inputModel);

            wallet.User = user ?? throw new NotFoundException("User not found");

            await _walletsService.AddAsync(wallet);

            return(wallet);
        }
Example #3
0
        public ActionResult AddWallet(WalletInputModel model)
        {
            if (ModelState.IsValid)
            {
                Wallet wallet;

                if (model.IsCreditCard)
                {
                    wallet = new Wallet(model.Name, model.Balance, CurrencyTools.GetCurrency(model.Currency), model.Overdraft);
                }
                else
                {
                    wallet = new Wallet(model.Name, model.Balance, CurrencyTools.GetCurrency(model.Currency));
                }
                var newItem = _service.AddWallet(wallet).MapToWalletOutputModel();


                return(PartialView("_wallet", newItem));
            }

            return(new HttpStatusCodeResult(422));
        }