Exemplo n.º 1
0
        public async void AddFood()
        {
            if (SelectedCategory == null || SelectedSlot == null)
            {
                return;
            }

            Food food = new Food {
                Id             = 0,
                Name           = Name,
                Quantity       = int.Parse(Quantity),
                ExpiryDateTime = Expiry,
                //Category = SelectedCategory,
                CategoryId = SelectedCategory.Id,
                //Slot = SelectedSlot,
                SlotId = SelectedSlot.Id
            };

            using (var httpClient = new HttpClient())
            {
                FoodClient foodClient = new FoodClient(httpClient);
                await foodClient.PostFoodAsync(food);
            }
            RefreshAsync();
        }
Exemplo n.º 2
0
 public async void EatAll(Food food)
 {
     using (var httpClient = new HttpClient())
     {
         FoodClient foodClient = new FoodClient(httpClient);
         await foodClient.DeleteFoodAsync(food.Id, food.RowVersion);
     }
     RefreshAsync();
 }
Exemplo n.º 3
0
        public async void RefreshAsync()
        {
            while (true)
            {
                try
                {
                    using (var httpClient = new HttpClient())
                    {
                        FoodClient foodClient = new FoodClient(httpClient);
                        Task <ICollection <Food> > allFoodTask = foodClient.GetAllFoodAsync();
                        FoodList.Clear();
                        foreach (var item in await allFoodTask)
                        {
                            FoodList.Add(item);
                        }

                        CategoryClient categoryClient = new CategoryClient(httpClient);
                        Task <ICollection <Category> > allCategoryTask = categoryClient.GetAllCategoryAsync();
                        CategoryList.Clear();
                        foreach (var item in await allCategoryTask)
                        {
                            CategoryList.Add(item);
                        }

                        StorageClient storageClient = new StorageClient(httpClient);
                        Task <ICollection <Storage> > allStorageTask = storageClient.GetAllStorageAsync();
                        StorageList.Clear();
                        foreach (var item in await allStorageTask)
                        {
                            StorageList.Add(item);
                        }

                        SlotClient slotClient = new SlotClient(httpClient);
                        Task <ICollection <Slot> > allSlotTask = slotClient.GetAllSlotAsync();
                        SlotList.Clear();
                        foreach (var item in await allSlotTask)
                        {
                            SlotList.Add(item);
                        }
                    }
                    return;
                }
                catch
                {
                    Thread.Sleep(500);
                }
            }
        }
Exemplo n.º 4
0
        public async void EatOne(Food food)
        {
            --food.Quantity;
            bool success = false;

            while (!success)
            {
                try
                {
                    using (var httpClient = new HttpClient())
                    {
                        FoodClient foodClient = new FoodClient(httpClient);
                        await foodClient.PutFoodAsync(food.Id, food);

                        success = true;
                    }
                }
                catch
                {
                    MessageBoxResult rsltMessageBox = MessageBox.Show("Do you want to force your value?", "Update error!", MessageBoxButton.YesNo, MessageBoxImage.Warning);

                    switch (rsltMessageBox)
                    {
                    case MessageBoxResult.Yes:
                    {
                        using (var httpClient = new HttpClient())
                        {
                            FoodClient foodClient = new FoodClient(httpClient);
                            food.RowVersion = (await foodClient.GetFoodAsync(food.Id)).RowVersion;
                        }
                    }
                    break;

                    case MessageBoxResult.No:
                        success = true;
                        break;
                    }
                }
            }
            RefreshAsync();
        }
Exemplo n.º 5
0
 public FoodController(FoodClient foodClient, IConfiguration configuration)
 {
     _foodClient = foodClient;
     _foodClient.ApplicationId  = configuration["FoodDatabaseAPI:ApplicationId"];
     _foodClient.ApplicationKey = configuration["FoodDatabaseAPI:ApplicationKey"];
 }