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 void UpdateFoodPerDay(FoodPerDayView foodPerDay) { var allEntries = new List <FoodEntryEntity>(); foreach (var entry in foodPerDay.AllFoodEntries) { var entryEntity = new FoodEntryEntity() { Id = entry.EntryId, FoodId = entry.FoodId, FoodName = entry.FoodName, Amount = entry.Amount, Calories = entry.Calories }; allEntries.Add(entryEntity); } var foodPerDayEntity = new FoodPerDayEntity() { Id = foodPerDay.Id, Day = foodPerDay.Day, AllEntries = allEntries }; _repoFoodPerDay.Update(foodPerDayEntity); }
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); }
public void AddFoodPerDay(FoodPerDayView foodPerDay) { var foodPerDayEntity = new FoodPerDayEntity() { Day = foodPerDay.Day }; _repoFoodPerDay.Add(foodPerDayEntity); }
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 UpdateFoodPerDay(FoodPerDayView foodPerDay) { var dataFoodEntry = JsonSerializer.Serialize(foodPerDay); var contentFoodEntry = new StringContent(dataFoodEntry, Encoding.UTF8, "application/json"); await HttpClient.PutAsync("api/countcalorie", contentFoodEntry); }
public IActionResult Put(FoodPerDayView foodPerDay) { _countCaloriesService.UpdateFoodPerDay(foodPerDay); return(Ok()); }
public IActionResult Post(FoodPerDayView foodPerDay) { _countCaloriesService.AddFoodPerDay(foodPerDay); return(Ok()); }