Example #1
0
 //Purchase a coin
 public IActionResult PurchaseCoin([FromBody] PurchasedCoin purchasedCoin, int Id)
 {
     try
     {
         _userService.PurchaseCoin(purchasedCoin, Id);
         return(Ok());
     }
     catch (Exception e)
     {
         return(BadRequest(new { message = e.Message }));
     }
 }
Example #2
0
        //Service to purchase a coin
        public void PurchaseCoin(PurchasedCoin purchaseCoin, int id)
        {
            var checkWallet = _dbContext.Wallet.FirstOrDefault(x => x.UserId == id);

            if (checkWallet == null)
            {
                throw new AlreadyExistsException("You have no wallet");
            }
            purchaseCoin.WalletId   = checkWallet.WalletId;
            purchaseCoin.TotalValue = Convert.ToInt32(purchaseCoin.Quantity * purchaseCoin.Price);
            _dbContext.PurchasedCoin.Add(purchaseCoin);
            _dbContext.SaveChanges();
        }