Пример #1
0
		public ActionResult RecipePrint(int recipeId)
		{
			var recipe = this.RecipeService.GetRecipeById(recipeId);

            if (recipe == null)
                return this.Issue404();

            var recipeViewModel = Mapper.Map(recipe, new RecipeViewModel());
			recipeViewModel.CommentWrapperViewModel = new CommentWrapperViewModel { CommentViewModels = new List<CommentViewModel>() };

			// Get Additional Data
			var user = this.UserService.GetUserById(recipe.CreatedBy);

			var recipeDetailViewModel = new RecipeDetailViewModel
			{
				RecipeViewModel = recipeViewModel,
				UserSummary = Mapper.Map(user, new UserSummary()),
				TastingNotes = new List<TastingNote>()
			};

			return this.View(recipeDetailViewModel);
		}
Пример #2
0
		/// <summary>
		/// Executes the View for RecipeDetail
		/// </summary>
		public ActionResult RecipeDetail(int recipeId)
		{
			var recipe = this.RecipeService.GetRecipeById(recipeId);

			if(recipe == null)
			{
				return this.Issue404();
			}

			// Auto Redirect to EDIT page for owner
			if (this.ActiveUser != null && recipe.CreatedBy == this.ActiveUser.UserId && string.IsNullOrWhiteSpace(Request["public"]))
			{
				return this.Redirect(Url.RecipeEditUrl(recipeId));
			}

			// Notify use if the recipe is not public
			if(!recipe.IsPublic)
			{
				this.AppendMessage(new WarnMessage { Text = "This recipe is not complete and only you can see it.  Add Fermentables and Yeast to make it public."});
			}

			// Get Similar Recipes
			ViewBag.SimilarRecipes = this.RecipeService.GetSimilarRecipes(recipe, 4);

			var recipeViewModel = Mapper.Map(recipe, new RecipeViewModel());

			// Fetch Brew Session Count (this should really go in a service as part of recipe get)
			recipeViewModel.BrewSessionCount = this.RecipeService.GetRecipeBrewSessionsCount(recipeId);

			// Fetch most recent brew session
			if(recipeViewModel.BrewSessionCount > 0)
			{
				recipeViewModel.MostRecentBrewSession = this.RecipeService.GetMostRecentBrewSession(recipeId);
			}

			// Fetch Tasting Notes
			var tastingNotes = this.RecipeService.GetRecipeTastingNotes(recipe.RecipeId);

			// Get Additional Data
            var user = this.UserService.GetUserById(recipe.CreatedBy);
			
            if ((recipeViewModel.OriginalRecipeId ?? 0) != 0)
            { 
                var originalRecipe = this.RecipeService.GetRecipeById((recipeViewModel.OriginalRecipeId ?? 0));
	            if(originalRecipe != null)
	            {
		            recipeViewModel.OriginalRecipe = Mapper.Map(originalRecipe, new RecipeViewModel());
	            }
            }
            
            var recipeDetailViewModel = new RecipeDetailViewModel();
            recipeDetailViewModel.RecipeViewModel = recipeViewModel;
            recipeDetailViewModel.UserSummary = Mapper.Map(user, new UserSummary());
			recipeDetailViewModel.TastingNotes = tastingNotes;
			
            var commentWrapperViewModel = new CommentWrapperViewModel();
            commentWrapperViewModel.CommentViewModels = Mapper.Map(this.RecipeService.GetRecipeComments(recipeId), new List<CommentViewModel>());
            commentWrapperViewModel.GenericId = recipeId;
            commentWrapperViewModel.CommentType = CommentType.Recipe;
            recipeDetailViewModel.RecipeViewModel.CommentWrapperViewModel = commentWrapperViewModel;

			// TODO: Check if the name passed in the URL is different than what
			// TODO: is in the DB.  If it is....do a 301 Redirect.  This is for SEO.
            ViewData["DisableEditing"] = true;


			// Get Send To Shop Settings (if any)
			ViewBag.SendToShopSettings = this.SendToShopService.GetRecipeCreationSendToShopSettings(false);

            return View(recipeDetailViewModel);
		}