public async Task <IEnumerable <string> > Get() { try { var purchase = new Purchase(); purchase.PurchaseId = 1; purchase.StockId = 1; purchase.Price = 100; purchase.Quantity = 5; await _stockHoldingService.AddPurchaseToHoldings(1, purchase); return(new string[] { "value1", "value2" }); } catch (Exception e) { throw e; } }
public async Task ImportTransactionHistory(ulong userId, string fileName) { var transactionCollection = await Task.Run(() => ReadPurchasesFromTransactions(fileName)); if (transactionCollection.Count > 0) { var allowedTypesForFiltering = new List <string>() { FidelityTransactionTypes.Purchase, DividendReinvestment }; var lastPurchaseDate = await GetLastPurchaseDateForUser(userId); var columnMapping = GetColumnMapping(transactionCollection[0]); var filteredTransactions = await Task.Run(() => GetTransactionsOfSpecificTypesAfterSpecificDate ( transactionCollection[0], lastPurchaseDate, allowedTypesForFiltering, columnMapping) ); if (filteredTransactions.Count > 0) { var purchases = await Task.Run(() => MapTransactionsToPurchases ( userId, filteredTransactions, columnMapping) ); foreach (var purchase in purchases) { var stockPurchase = await _stockPurchaseService.AddStockAndPurchaseInfo(purchase); await _stockHoldingService.AddPurchaseToHoldings(userId, stockPurchase.Purchase); } } } }
public async Task <IActionResult> Post([FromBody] StockPurchase purchaseData) { try { if (!ModelState.IsValid) { return(BadRequest()); } await _stockAndPurchaseService.AddStockAndPurchaseInfo(purchaseData); await _stockHoldingService.AddPurchaseToHoldings(purchaseData.UserId, purchaseData.Purchase); return(Ok()); } catch (ArgumentException ex) { return(BadRequest(ex.Message)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }