Exemplo n.º 1
0
 public ArticleService(IArticleAction articleAction,
                       EfCoreContext context,
                       IMapper mapper,
                       SimpleCrudHelper simpleCrudHelper)
 {
     ArticleAction    = articleAction;
     Context          = context;
     Mapper           = mapper;
     SimpleCrudHelper = simpleCrudHelper;
 }
Exemplo n.º 2
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();
    }
Exemplo n.º 3
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));
    }
Exemplo n.º 4
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));
    }
Exemplo n.º 5
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));
    }
Exemplo n.º 6
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();
    }
Exemplo n.º 7
0
 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;
 }
Exemplo n.º 8
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();
    }
Exemplo n.º 9
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);
    }
Exemplo n.º 10
0
    /// <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));
    }
Exemplo n.º 11
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();
    }
Exemplo n.º 12
0
 public UnitService(SimpleCrudHelper simpleCrudHelper)
 {
     SimpleCrudHelper = simpleCrudHelper;
 }
Exemplo n.º 13
0
 public MealTypeService(SimpleCrudHelper simpleCrudHelper)
 {
     SimpleCrudHelper = simpleCrudHelper;
 }
Exemplo n.º 14
0
 /// <inheritdoc />
 public IEnumerable <ExistingRecipeDto> GetAllRecipes()
 {
     return(SimpleCrudHelper.GetAllAsDto <Recipe, ExistingRecipeDto>().OrderBy(recipe => recipe.Name));
 }
Exemplo n.º 15
0
 /// <inheritdoc />
 public void DeleteMeal(DeleteMealDto mealToDelete)
 {
     SimpleCrudHelper.Delete <Meal>(mealToDelete.MealId);
     Context.SaveChanges();
 }
Exemplo n.º 16
0
 public ArticleGroupService(SimpleCrudHelper simpleCrudHelper)
 {
     SimpleCrudHelper = simpleCrudHelper;
 }
Exemplo n.º 17
0
 public StoreService(SimpleCrudHelper simpleCrudHelper)
 {
     SimpleCrudHelper = simpleCrudHelper;
 }
Exemplo n.º 18
0
 public RecipeService(SimpleCrudHelper simpleCrudHelper, EfCoreContext context)
 {
     SimpleCrudHelper = simpleCrudHelper;
     Context          = context;
 }