public FoodPerDayView GetFoodPerDayByDate(string date) { var foodPerDayEntity = _repoFoodPerDay.GetByDate(date); if (foodPerDayEntity == null) { return(null); } var viewEntries = new List <FoodEntryView>(); foreach (var entityEntry in foodPerDayEntity.AllEntries) { var entry = new FoodEntryView() { EntryId = entityEntry.Id, FoodId = entityEntry.FoodId, FoodName = entityEntry.FoodName, Amount = entityEntry.Amount, Calories = entityEntry.Calories }; viewEntries.Add(entry); } var foodPerDayView = new FoodPerDayView { Id = foodPerDayEntity.Id, Day = foodPerDayEntity.Day, AllFoodEntries = viewEntries }; return(foodPerDayView); }
public async void DeleteEntry(FoodEntryView foodEntry) { FoodToday.AllFoodEntries.Remove(foodEntry); await CalorieService.UpdateFoodPerDay(FoodToday); StateHasChanged(); }
private int CalculateCalories(FoodEntryView foodEntry) { var food = AllFoodItems.FirstOrDefault(f => f.Name.Equals(Name)); var relative = foodEntry.Amount / 100.0f; return((int)(relative * (food?.CaloriesPer100G ?? 0.0f))); }
private async void btnOpenFoodDialog_Click(object sender, RoutedEventArgs e) { //Open DialogHost for Insertion of a nutrition entry FoodEntryView View = new FoodEntryView(); View.FoodSelections = PersistentDataProvider.Current.AllFoods; await DialogHost.Show(View, "RootDialog"); }
public async Task AddFoodPerDay(FoodPerDayView foodPerDay, FoodEntryView foodEntryView) { var dataFood = JsonSerializer.Serialize(foodPerDay); var content = new StringContent(dataFood, Encoding.UTF8, "application/json"); await HttpClient.PostAsync($"api/countcalorie/{foodPerDay}", content); await UpdateFoodPerDay(foodPerDay); }
protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); AllFoodItems = await FoodService.GetAllFood(); if (AllFoodItems.Any()) { Name = AllFoodItems.ElementAt(0)?.Name; } FoodToday = await CalorieService.GetFoodPerDay(DateTime.Now.Date) ?? FoodToday; FoodEntry = new FoodEntryView(); FoodEntry.Calories = CalculateCalories(FoodEntry); }
protected override void OnInitialized() { base.OnInitialized(); FoodEntry = new FoodEntryView() { Amount = 0, FoodId = 0 }; FoodToday = new FoodPerDayView() { Day = DateTime.Now.Date.ToString("dd.MM.yyyy"), AllFoodEntries = new List <FoodEntryView>() }; CurrentDate = DateTime.Now.ToShortDateString(); AllFoodItems = new List <FoodView>(); }
public async Task AddFoodEntry() { var food = AllFoodItems.FirstOrDefault(f => f.Name.Equals(Name)); FoodEntry.FoodName = food.Name; FoodEntry.FoodId = food.FoodId; FoodEntry.Calories = CalculateCalories(FoodEntry); FoodToday.AllFoodEntries.Add(FoodEntry); await CalorieService.UpdateFoodPerDay(FoodToday); FoodEntry = new FoodEntryView() { Amount = 0, FoodId = 0 }; StateHasChanged(); }
private void DialogHost_DialogClosing(object sender, DialogClosingEventArgs eventArgs) { try { //Get Parameter and check for type var input = eventArgs.Parameter; //To do: Make Insertion possible for any datetime #region Insert Food Entry if (input.GetType() == typeof(FoodEntryView)) { try { //Insert Food Entry into DB FoodEntryView helper = (FoodEntryView)input; if (helper.SelectedFood != null && helper.Weight != 0) { Food lebensmittelHinzugefuegt = helper.SelectedFood; FoodEntry eintrag = new FoodEntry(lebensmittelHinzugefuegt, helper.Weight, helper.SelectedDate.ToString()); PersistentDataProvider.Current.databaseService.InsertValues("Foodentries", typeof(FoodEntry), eintrag); } else { MessageBox.Show("Eintrag unvollständig, bitte erneut versuchen."); } } catch (System.InvalidOperationException) { MessageBox.Show("Datum auswählen!"); } } #endregion } catch (System.NullReferenceException) { } }