public MealTO Add(MealTO Entity)
 {
     //if (!mealContext.Meals.Any(x => x.Id == Entity.Id))
     return(mealContext.Meals
            .Add(Entity.ToEF())
            .Entity
            .ToTranfertsObject());
 }
        public MealTO Update(MealTO Entity)
        {
            if (!mealContext.Meals.Any(x => x.Id == Entity.Id))
            {
                throw new Exception($"MealRepository. Update(MealTransfertObject) no record to update.");
            }

            var attachedMeal = mealContext.Meals
                               .Include(x => x.MealsComposition)
                               .ThenInclude(x => x.Ingredient)
                               .FirstOrDefault(x => x.Id == Entity.Id);

            if (attachedMeal != default)
            {
                attachedMeal.UpdateFromDetached(Entity.ToEF());
                //attachedMeal.MealsComposition = attachedMeal.MealsComposition
                //    .ToList()
                //    .UpdateListFromDetached(Entity.ToEF().MealsComposition.ToList());
            }

            return(mealContext.Meals.Update(attachedMeal).Entity.ToTranfertsObject());
        }
Exemple #3
0
 public void Delete(MealTO entityToDelete)
 {
     Context.Meals.Remove(entityToDelete.ToEF());
 }
Exemple #4
0
 public void Update(MealTO entityToUpdate)
 {
     Context.Meals.Update(entityToUpdate.ToEF());
 }