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); }
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()); } }
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); }
public double CalculateTotalAmount(WalletItemDTO item) { return(item.Quantity * item.Cryptocurrency.Price); }