Beispiel #1
0
 internal static RecipeModel ConvertRecipeViewModelToRecipeModel(RecipeViewModel recipeModel)
 {
     return(new RecipeModel
     {
         Name = recipeModel.Name,
         Composition = recipeModel.Composition?.Select(CompositionViewMapper.ConvertCompositonViewModelToCompositionModel).ToList(),
         Category = recipeModel.Category,
         Review = recipeModel.Review?.Select(ReviewViewMapper.ConvertReviewViewModelToReviewModel).ToList(),
         User = UserViewMapper.ConvertUserViewModelToUserModel(recipeModel.User)
     });
 }
 public ActionResult ViewRecipeList()
 {
     try
     {
         var recipeList = RecipeService.GetList().Select(RecipeViewMapper.ConvertRecipeModelToRecipeViewModel).ToList();
         recipeList.Select(x => x.User = UserViewMapper.ConvertUserModelToUserViewModel(UserService.GetList().FirstOrDefault(y => y.Id == x.UserId))).ToList();
         return(View("ViewRecipeList", recipeList));
     }
     catch (Exception e)
     {
         Logger.InitLogger();
         Logger.Log.Error("Error: " + e);
         return(View("_Error"));
     }
 }
 public ActionResult AddRecipe(RecipeViewModel recipe)
 {
     try
     {
         if (ModelState.IsValid)
         {
             recipe.User = UserViewMapper.ConvertUserModelToUserViewModel(UserService.GetList().FirstOrDefault());
             RecipeService.AddItem(RecipeViewMapper.ConvertRecipeViewModelToRecipeModel(recipe));
             return(RedirectToAction("ViewRecipeList"));
         }
         return(View("AddRecipe"));
     }
     catch (Exception e)
     {
         Logger.InitLogger();
         Logger.Log.Error("Error: " + e);
         return(View("_Error"));
     }
 }