public async Task <List <FoodUnit> > SearchFood(string search) { var db = new DAL.DB.SmartLifeDbContext(); var result = new List <FoodUnit>(); try { var response = await Request(search, NutritionixReqType.searchFoods); if (response.TryGetValue("success", out object payload)) { var foodAutoComplete = SearchFoodsResult.FromJson(JsonConvert.SerializeObject(response)); foreach (var item in foodAutoComplete.Success.Select(Success => Success.Common).First()) { var food = new FoodUnit() { Id = Guid.NewGuid(), Name = item.FoodName, ImageUrl = item.Photo.Thumb }; result.Add(food); } SaveData(search, db, result); } } catch (Exception) { } return(result); }
public DalRouter(IEventAggregator eventAggregator) { _eventAggregator = eventAggregator; DbContext = new DB.SmartLifeDbContext(); GetLogin = new Login(_eventAggregator); }