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(); }
public async void EatAll(Food food) { using (var httpClient = new HttpClient()) { FoodClient foodClient = new FoodClient(httpClient); await foodClient.DeleteFoodAsync(food.Id, food.RowVersion); } RefreshAsync(); }
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); } } }
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(); }
public FoodController(FoodClient foodClient, IConfiguration configuration) { _foodClient = foodClient; _foodClient.ApplicationId = configuration["FoodDatabaseAPI:ApplicationId"]; _foodClient.ApplicationKey = configuration["FoodDatabaseAPI:ApplicationKey"]; }