Beispiel #1
0
        public async Task AddFood(string name, DateTime at)
        {
            if (foodEntities == null)
            {
                foodEntities = await database.GetFood();
            }
            var foodEntity = foodEntities.SingleOrDefault(fm => fm.Name == name);

            if (foodEntity == null)
            {
                foodEntity = new FoodEntity {
                    Name = name
                };
                await database.Save(foodEntity);

                foodEntities = await database.GetFood();

                foodEntity = foodEntities.Single(fm => fm.Name == name);
            }

            var foodRecordEntity = new FoodRecordEntity {
                FoodId = foodEntity.Id, At = at
            };
            await database.Save(foodRecordEntity);

            foodRecordEntities = await database.GetFoodRecords();
        }
Beispiel #2
0
 public async Task Save(FoodRecordEntity entity)
 {
     if (entity.Id == 0)
     {
         await connection.InsertAsync(entity);
     }
     else
     {
         await connection.UpdateAsync(entity);
     }
 }