public async Task <DetailResponse> GetValidatedMarketDetail(OriginalDetailRequest request) { OriginalDetailResponse originalDetailResponse = await GetOriginalDetails(request); originalDetailResponse.marketDetails.Schedule = originalDetailResponse.marketDetails.Schedule.Replace("<br>", "").Trim(); if (originalDetailResponse.marketDetails.Products == "") { originalDetailResponse.marketDetails.Products = null; } if (originalDetailResponse.marketDetails.Schedule == "") { originalDetailResponse.marketDetails.Schedule = null; } else { originalDetailResponse.marketDetails.Schedule = originalDetailResponse.marketDetails.Schedule.Substring(25); } Models.DatabaseModels.Market databaseMarket = new Models.DatabaseModels.Market { MarketNumber = request.MarketId, Address = originalDetailResponse.marketDetails.Address, GoogleAddress = originalDetailResponse.marketDetails.GoogleLink, Products = originalDetailResponse.marketDetails.Products, Schedule = originalDetailResponse.marketDetails.Schedule }; databaseMarket = await dbService.AddUpdateMarketToDatabase(databaseMarket); await dbService.SaveChanges(); var item = new DetailResponse { Address = databaseMarket.Address, GoogleAddressUrl = databaseMarket.GoogleAddress }; if (databaseMarket.Products != null) { item.Products = databaseMarket.Products.Split("; "); } if (databaseMarket.Schedule != null) { item.Schedule = databaseMarket.Schedule.Split(";"); } return(item); }
public async Task <ListResponse> GetValidatedMarketList(OriginalListRequest request) { OriginalListResponse originalListResponse = await GetOriginalList(request); ListResponse listResponse = new ListResponse(); List <Models.DatabaseModels.Market> databaseMarkets = new List <Models.DatabaseModels.Market>(); listResponse.Response = new List <Market>(); if (originalListResponse != null) { originalListResponse.results.ForEach(async item => { int decimalIndex = item.marketname.IndexOf(".", 0, 5); string name = item.marketname.Substring(decimalIndex + 3); string distance = item.marketname.Substring(0, decimalIndex + 2); Models.DatabaseModels.Market databaseMarket = new Models.DatabaseModels.Market { MarketNumber = item.id, Name = name, IsFavorite = false }; databaseMarkets.Add(databaseMarket); databaseMarket = await dbService.AddUpdateMarketToDatabase(databaseMarket); listResponse.Response.Add(new Market { MarketNumber = item.id, Name = name, Distance = distance, IsFavorite = databaseMarket.IsFavorite }); }); await dbService.SaveChanges(); //databaseMarkets = await dbService.AddUpdateMarketsToDatabase(databaseMarkets); return(listResponse); } return(null); }