public ActionResult AddRecipe(MealViewModel viewModel)
 {
     var user = SessionFacade.User;
     ViewData[CommonValues.Authors] = _authorRepository.GetAll().OrderBy(author => author.User.Name);
     if (ModelState.IsValid)
     {
         var recipe = Mapper.Map<RecipeViewModel, Recipe>(viewModel.Recipe);
         if (_recipeRepository.Contains(r => r.MealId == viewModel.Id))
         {
             _recipeRepository.Update(recipe);
         }
         else
         {
             recipe.DateAdded = DateTime.Now;
             if (recipe.User == null && user != null)
                 recipe.UserId = user.Id;
             recipe.MealId = viewModel.Id;
             _recipeRepository.Create(recipe);
         }
         return View("Meal", viewModel);
     }
     return View(viewModel);
 }
 public ActionResult Create(MealViewModel viewModel)
 {
     ViewData["Categories"] = _categoryRepository.GetAll().OrderBy(category => category.Name);
     if (ModelState.IsValid)
     {
         var user = SessionFacade.User;
         HttpPostedFileBase file = viewModel.File;
         if (file != null && file.ContentLength > 0)
         {
             viewModel.ImgUrl = string.Format("/Uploads/{0}", file.FileName);
             string filePath = Path.Combine(HttpContext.Server.MapPath("~/Uploads"), Path.GetFileName(file.FileName));
             file.SaveAs(filePath);
         }
         var meal = Mapper.Map<MealViewModel, Meal>(viewModel);
         meal.DateAdded = DateTime.Today;
         if(user != null)
             meal.UserId = user.Id;
         meal.Name = viewModel.Name;
         if (meal.Id > 0)
             _mealRepository.Update(meal);
         else
             _mealRepository.Add(meal);
         return RedirectToAction("AddIngredients", new { mealId = meal.Id });
     }
     return View(viewModel);
 }