public static MealEF UpdateFromDetached(this MealEF AttachedEF, MealEF DetachedEF) { if (AttachedEF is null) { throw new ArgumentNullException(nameof(AttachedEF)); } if (DetachedEF is null) { throw new ArgumentNullException(nameof(DetachedEF)); } if (AttachedEF.Id != DetachedEF.Id) { throw new Exception("Cannot update MealEF entity as it is not the same."); } if ((AttachedEF != default) && (DetachedEF != default)) { //AttachedEF.MealsComposition = //DetachedEF.MealsComposition; //AttachedEF.MealsComposition // .ToList() // .UpdateListFromDetached(DetachedEF.MealsComposition.ToList()); AttachedEF = AttachedEF.FillFromMultiLanguageString(DetachedEF.ExtractToMultiLanguageString()); AttachedEF.Supplier = DetachedEF.Supplier; AttachedEF.MealType = DetachedEF.MealType; } return(AttachedEF); }
public static MealEF ToEF(this MealTO mealTO) { if (mealTO is null) { throw new ArgumentNullException(nameof(mealTO)); } var mealEF = new MealEF { Id = mealTO.Id, MealType = mealTO.MealType, NameEnglish = mealTO.Name.English, NameFrench = mealTO.Name.French, NameDutch = mealTO.Name.Dutch, Supplier = mealTO.Supplier.ToEF() }; mealEF.MealCompositions = mealTO.Ingredients?.Select(x => new MealCompositionEF { Ingredient = x.ToEF(), IngredientId = x.Id, Meal = mealEF, MealId = mealTO.Id }).ToList(); return(mealEF); }
public static MealTO ToTranfertsObject(this MealEF Meal) { if (Meal is null) { throw new ArgumentNullException(nameof(Meal)); } return(new MealTO { Id = Meal.Id, Name = Meal.ExtractToMultiLanguageString(), Ingredients = Meal.MealsComposition?.Select(x => x.Ingredient.ToTranfertsObject()).ToList(), Supplier = Meal.Supplier.ToTranfertsObject(), MealType = Meal.MealType, }); }
public static MealTO ToTO(this MealEF mealEF) { if (mealEF is null) { throw new ArgumentNullException(nameof(mealEF)); } return(new MealTO { Id = mealEF.Id, MealType = mealEF.MealType, Name = new TranslatedString(mealEF.NameEnglish, mealEF.NameFrench, mealEF.NameDutch), Supplier = mealEF.Supplier.ToTO(), Ingredients = mealEF.MealCompositions?.Select(x => x.Ingredient.ToTO()).ToList() }); }
public static MealEF ToEF(this MealTO Meal) { if (Meal is null) { throw new ArgumentNullException(nameof(Meal)); } var ReturnValue = new MealEF() { Id = Meal.Id, Supplier = Meal.Supplier.ToEF(), MealType = Meal.MealType, MealsComposition = new List <MealCompositionEF>() //Ingredients = MealTO.Ingredients.Select(x => x.ToEF()).ToList() }; ReturnValue = ReturnValue.FillFromMultiLanguageString(Meal.Name); //TODO IngredientsTO to MealComposition Extention to use as // andwichDTO.Ingredients.Select(x => x.ToMealCompositionEF()).ToList()??? or method in this file as toMEalComposition... foreach (var i in Meal.Ingredients) { ReturnValue.MealsComposition.Add( new MealCompositionEF() { IngredientId = i.Id, Ingredient = i.ToEF(), MealId = ReturnValue.Id, Meal = ReturnValue }); } return(ReturnValue); }