Пример #1
0
    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();
    }
Пример #2
0
    /// <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));
    }
Пример #3
0
    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));
    }
Пример #4
0
    /// <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));
    }
Пример #5
0
    /// <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();
    }
Пример #6
0
    /// <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();
    }
Пример #7
0
    /// <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);
    }
Пример #8
0
    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();
    }