public async Task <ActionResult> Post([FromBody] Asset model) { var validator = new AssetValidator(); var validatrionResult = validator.Validate(model); if (validatrionResult.IsValid) { try { model.CountryOfDepartment = await _CountryRepository.GetCountryName(model.CountryOfDepartment); } catch (Exception ex) { var errors = new List <ValidationFailure>() { new ValidationFailure("CountryOfDepartment", ex.Message) }; return(new BadRequestObjectResult(errors)); } _Repository.InsertAsset(model); _Repository.Save(); return(Ok()); } else { return(new BadRequestObjectResult(validatrionResult.Errors)); } }
/// <summary> /// First initialize collections of assets and markets /// </summary> /// <returns></returns> public async Task MarketCollectionInitialize() { var tickerResult = await BinanceConnector.TickerAllPrices(); var allSymbols = tickerResult.Select(i => i.Symbol).ToList(); var newAssets = DefineNewAssets(allSymbols); AssetRepository.Save(newAssets); var newMarkets = DefineNewMarkets(allSymbols); MarketRepository.Save(newMarkets); }
public async Task <Transaction> GetTransaction(string id) { Transaction transaction; try { transaction = await TransactionRepository.GetById(id); if (transaction == null) { transaction = await BlockchainDataProvider.GetTransaction(id); if (transaction != null) { await BlockService.GetBlock(transaction.Blockhash); foreach (var asset in transaction.Assets) { var assetExists = await AssetRepository.Exists(asset.Id); if (!assetExists && !String.IsNullOrWhiteSpace(asset.MetadataUrl)) { var assetData = await BlockchainDataProvider.GetMetadataContent(new Uri(asset.MetadataUrl)); await AssetRepository.Save(assetData); } } await TransactionRepository.Save(transaction); } } } catch (Exception ex) { await Log.WriteError(this.GetType().ToString(), "GetTransaction", $"transaction_id:{id}", ex, DateTime.Now); return(null); } return(transaction); }
public async Task <Asset> GetAsset(string id) { Asset asset; try { asset = await AssetRepository.GetById(id); if (asset == null) { asset = await BlockchainDataProvider.GetAsset(id); await AssetRepository.Save(asset); } } catch (Exception ex) { await Log.WriteError(this.GetType().ToString(), "GetAsset", $"asset_id:{id}", ex, DateTime.Now); return(null); } return(asset); }