示例#1
0
        public async Task <WalletItemDTO> GetTotalValue(List <WalletItemDTO> from, string c_to)
        {
            string data = JsonConvert.SerializeObject(from);

            var content = new StringContent(data, Encoding.UTF8, "application/json");

            var url = ApiEndpoint.TotalEndpoint(c_to);

            var response = await client.PostAsync(url, content).ConfigureAwait(false);

            var           jsonResult = response.Content.ReadAsStringAsync().Result;
            WalletItemDTO item       = JsonConvert.DeserializeObject <WalletItemDTO>(jsonResult);

            return(item);
        }
示例#2
0
 public IActionResult AddItem(int userId, [FromBody] WalletItemDTO item)
 {
     if (_tokenService.ValidateToken(userId))
     {
         var wallet = _walletBL.GetWallet(userId);
         item.WalletId = wallet.Id;
         if (_walletBL.AddItem(item))
         {
             return(Ok());
         }
         else
         {
             return(NotFound());
         }
     }
     else
     {
         return(Unauthorized());
     }
 }
示例#3
0
        public bool AddItem(WalletItemDTO item)
        {
            var wallet = _repository.GetWalletById(item.WalletId);

            if (wallet != null)
            {
                var  existingItem = wallet.Items.Where(i => i.CryptoId == item.CryptoId).FirstOrDefault();
                bool ok           = existingItem != null;
                if (ok)
                {
                    existingItem.Quantity += item.Quantity;
                    _repository.InsertItem(existingItem, ok);
                }
                else
                {
                    _repository.InsertItem(_mapper.Map <WalletItem>(item), ok);
                }
                return(true);
            }
            return(false);
        }
示例#4
0
 public double CalculateTotalAmount(WalletItemDTO item)
 {
     return(item.Quantity * item.Cryptocurrency.Price);
 }