Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public DalRouter(IEventAggregator eventAggregator)
 {
     _eventAggregator = eventAggregator;
     DbContext        = new DB.SmartLifeDbContext();
     GetLogin         = new Login(_eventAggregator);
 }