コード例 #1
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] SaveWalletResource resource)
        {
            var wallet = _mapper.Map <SaveWalletResource, Wallet>(resource);
            var result = await _walletService.UpdateAsync(id, wallet);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            var walletResource = _mapper.Map <Wallet, WalletResource>(result.Resource);

            return(Ok(walletResource));
        }
コード例 #2
0
        public async Task <IActionResult> PostAsync([FromBody] SaveWalletResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }
            var wallet = _mapper.Map <SaveWalletResource, Wallet>(resource);
            var result = await _walletService.SaveAsync(wallet);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            var walletResource = _mapper.Map <Wallet, WalletResource>(result.Resource);

            return(Ok(walletResource));
        }