public ArticleService(IArticleAction articleAction, EfCoreContext context, IMapper mapper, SimpleCrudHelper simpleCrudHelper) { ArticleAction = articleAction; Context = context; Mapper = mapper; SimpleCrudHelper = simpleCrudHelper; }
public void UpdateArticle(ExistingArticleDto existingArticleDto) { var articleGroup = SimpleCrudHelper.Find <ArticleGroup>(existingArticleDto.ArticleGroup.ArticleGroupId); var article = SimpleCrudHelper.Find <Article>(existingArticleDto.ArticleId); article.ArticleGroup = articleGroup; article.IsInventory = existingArticleDto.IsInventory; article.Name = existingArticleDto.Name; Context.SaveChanges(); }
/// <inheritdoc /> public ExistingMealDto CreateMeal(NewMealDto newMealDto) { // TODO mu88: Try to avoid this manual mapping logic var recipe = SimpleCrudHelper.Find <Recipe>(newMealDto.Recipe.RecipeId); var mealType = SimpleCrudHelper.Find <MealType>(newMealDto.MealType.MealTypeId); var newMeal = new Meal(newMealDto.Day, mealType, recipe); var createdMeal = Context.Meals.Add(newMeal); Context.SaveChanges(); return(Mapper.Map <ExistingMealDto>(createdMeal.Entity)); }
public ExistingArticleDto CreateArticle(NewArticleDto newArticleDto) { // TODO mu88: Try to avoid this manual mapping logic var articleGroup = SimpleCrudHelper.Find <ArticleGroup>(newArticleDto.ArticleGroup.ArticleGroupId); var newArticle = new Article { Name = newArticleDto.Name, ArticleGroup = articleGroup, IsInventory = newArticleDto.IsInventory }; var createdArticle = Context.Articles.Add(newArticle); Context.SaveChanges(); return(Mapper.Map <ExistingArticleDto>(createdArticle.Entity)); }
/// <inheritdoc /> public IEnumerable <NewPurchaseItemDto> GetOrderedPurchaseItems(IEnumerable <ExistingRecipeDto> existingRecipeDtos, ExistingStoreDto existingStoreDto) { var recipes = SimpleCrudHelper.FindMany <Recipe>(existingRecipeDtos.Select(x => x.RecipeId)); var store = SimpleCrudHelper.Find <Store>(existingStoreDto.StoreId); var orderedPurchaseItemsByStore = OrderPurchaseItemsByStoreAction.OrderPurchaseItemsByStore(store, GeneratePurchaseItemsForRecipesAction .GeneratePurchaseItems(recipes)); return(Mapper.Map <IEnumerable <NewPurchaseItemDto> >(orderedPurchaseItemsByStore)); }
/// <inheritdoc /> public void DeleteRecipe(DeleteRecipeDto recipeToDelete) { var existingMeals = SimpleCrudHelper.GetAllAsDto <Meal, ExistingMealDto>(); existingMeals.Where(x => x.Recipe.RecipeId == recipeToDelete.RecipeId) .ToList() .ForEach(x => SimpleCrudHelper.Delete <Meal>(x.MealId)); var existingRecipe = SimpleCrudHelper.Find <Recipe>(recipeToDelete.RecipeId); existingRecipe.Ingredients.Select(x => x.IngredientId).ToList().ForEach(x => SimpleCrudHelper.Delete <Ingredient>(x)); SimpleCrudHelper.Delete <Recipe>(recipeToDelete.RecipeId); Context.SaveChanges(); }
public MealService(IGeneratePurchaseItemsForRecipesAction generatePurchaseItemsForRecipesAction, IOrderPurchaseItemsByStoreAction orderPurchaseItemsByStoreAction, IGetRecipesForMealsAction getRecipesForMealsAction, EfCoreContext context, SimpleCrudHelper simpleCrudHelper, IMapper mapper) { GeneratePurchaseItemsForRecipesAction = generatePurchaseItemsForRecipesAction; OrderPurchaseItemsByStoreAction = orderPurchaseItemsByStoreAction; Context = context; SimpleCrudHelper = simpleCrudHelper; Mapper = mapper; GetRecipesForMealsAction = getRecipesForMealsAction; }
/// <inheritdoc /> public void CreateNewRecipe(NewRecipeDto newRecipeDto) { var newIngredients = new List <Ingredient>(); foreach (var newIngredientDto in newRecipeDto.Ingredients) { var unit = SimpleCrudHelper.Find <Unit>(newIngredientDto.Unit.UnitId); var article = SimpleCrudHelper.Find <Article>(newIngredientDto.Article.ArticleId); newIngredients.Add(Context.Ingredients.Add(new Ingredient(article, newIngredientDto.Quantity, unit)).Entity); } var newRecipe = new Recipe(newRecipeDto.Name, newRecipeDto.NumberOfDays, newIngredients); Context.Recipes.Add(newRecipe); Context.SaveChanges(); }
/// <inheritdoc /> public IEnumerable <NewPurchaseItemDto> GetOrderedPurchaseItems(ExistingStoreDto existingStoreDto) { var meals = Context.Meals.Where(x => !x.HasBeenShopped); var recipes = GetRecipesForMealsAction.GetRecipesForMeals(meals); var store = SimpleCrudHelper.Find <Store>(existingStoreDto.StoreId); var orderedPurchaseItemsByStore = OrderPurchaseItemsByStoreAction.OrderPurchaseItemsByStore(store, GeneratePurchaseItemsForRecipesAction .GeneratePurchaseItems(recipes)); foreach (var meal in meals) { meal.HasBeenShopped = true; } var newPurchaseItemDtos = Mapper.Map <IEnumerable <NewPurchaseItemDto> >(orderedPurchaseItemsByStore); // TODO MUL: Investigate why conversion has to be done before calling SaveChanges() Context.SaveChanges(); return(newPurchaseItemDtos); }
/// <inheritdoc /> public IEnumerable <ExistingMealDto> GetFutureMeals() { var allMeals = SimpleCrudHelper.GetAllAsDto <Meal, ExistingMealDto>(); var results = new Collection <ExistingMealDto>(); foreach (var meal in allMeals.Where(x => IsInFuture(x.Day))) { if (meal.Recipe.NumberOfDays > 1) { for (var i = 0; i < meal.Recipe.NumberOfDays; i++) { results.Add(new ExistingMealDto(meal.Day.AddDays(i), meal.MealType, meal.Recipe, meal.MealId, meal.HasBeenShopped)); } } else { results.Add(meal); } } return(results.OrderBy(x => x.Day).ThenBy(x => x.MealType.Order)); }
public void UpdateRecipe(UpdateRecipeDto existingRecipeDto) { var recipe = SimpleCrudHelper.Find <Recipe>(existingRecipeDto.RecipeId); foreach (var ingredientId in recipe.Ingredients.Select(x => x.IngredientId).ToList()) { SimpleCrudHelper.Delete <Ingredient>(ingredientId); } var newIngredients = new List <Ingredient>(); foreach (var newIngredientDto in existingRecipeDto.Ingredients) { var unit = SimpleCrudHelper.Find <Unit>(newIngredientDto.Unit.UnitId); var article = SimpleCrudHelper.Find <Article>(newIngredientDto.Article.ArticleId); newIngredients.Add(Context.Ingredients.Add(new Ingredient(article, newIngredientDto.Quantity, unit)).Entity); } recipe.Name = existingRecipeDto.Name; recipe.NumberOfDays = existingRecipeDto.NumberOfDays; recipe.Ingredients = newIngredients; Context.SaveChanges(); }
public UnitService(SimpleCrudHelper simpleCrudHelper) { SimpleCrudHelper = simpleCrudHelper; }
public MealTypeService(SimpleCrudHelper simpleCrudHelper) { SimpleCrudHelper = simpleCrudHelper; }
/// <inheritdoc /> public IEnumerable <ExistingRecipeDto> GetAllRecipes() { return(SimpleCrudHelper.GetAllAsDto <Recipe, ExistingRecipeDto>().OrderBy(recipe => recipe.Name)); }
/// <inheritdoc /> public void DeleteMeal(DeleteMealDto mealToDelete) { SimpleCrudHelper.Delete <Meal>(mealToDelete.MealId); Context.SaveChanges(); }
public ArticleGroupService(SimpleCrudHelper simpleCrudHelper) { SimpleCrudHelper = simpleCrudHelper; }
public StoreService(SimpleCrudHelper simpleCrudHelper) { SimpleCrudHelper = simpleCrudHelper; }
public RecipeService(SimpleCrudHelper simpleCrudHelper, EfCoreContext context) { SimpleCrudHelper = simpleCrudHelper; Context = context; }