Example #1
0
        public ActionResult BrewSessionEdit(int brewSessionId)
        {
            var brewSession = this.RecipeService.GetBrewSessionById(brewSessionId);

            if (!this.VerifyBrewSessionAccess(brewSession))
            {
                return(this.Issue404());
            }

            // Ensure only Active Tasting Notes
            brewSession.TastingNotes = brewSession.TastingNotes.Where(x => x.IsActive && x.IsPublic).OrderByDescending(x => x.TasteDate).ToList();

            var brewSessionViewModel = Mapper.Map(brewSession, new BrewSessionViewModel());

            brewSessionViewModel.RecipeSummary = Mapper.Map(this.RecipeService.GetRecipeSummaryById(brewSessionViewModel.RecipeId), new RecipeSummaryViewModel());

            // TODO: Encapsulate into Service and Mapper
            var commentWrapperViewModel = new CommentWrapperViewModel();

            commentWrapperViewModel.CommentViewModels    = Mapper.Map(this.RecipeService.GetBrewSessionComments(brewSessionId), new List <CommentViewModel>());
            commentWrapperViewModel.GenericId            = brewSessionId;
            commentWrapperViewModel.CommentType          = CommentType.Session;
            brewSessionViewModel.CommentWrapperViewModel = commentWrapperViewModel;

            return(View(brewSessionViewModel));
        }
Example #2
0
        public ActionResult BrewSessionDetail(int brewSessionId)
        {
            var brewSession = this.RecipeService.GetBrewSessionById(brewSessionId);

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

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

            // Ensure only Active Tasting Notes
            brewSession.TastingNotes = brewSession.TastingNotes.Where(x => x.IsActive && x.IsPublic).OrderByDescending(x => x.TasteDate).ToList();

            var brewSessionViewModel = Mapper.Map(brewSession, new BrewSessionViewModel());

            brewSessionViewModel.RecipeSummary = Mapper.Map(this.RecipeService.GetRecipeSummaryById(brewSessionViewModel.RecipeId), new RecipeSummaryViewModel());

            // TODO: Encapsulate into Service and Mapper
            var commentWrapperViewModel = new CommentWrapperViewModel();

            commentWrapperViewModel.CommentViewModels    = Mapper.Map(this.RecipeService.GetBrewSessionComments(brewSessionId), new List <CommentViewModel>());
            commentWrapperViewModel.GenericId            = brewSessionId;
            commentWrapperViewModel.CommentType          = CommentType.Session;
            brewSessionViewModel.CommentWrapperViewModel = commentWrapperViewModel;

            return(View(brewSessionViewModel));
        }
Example #3
0
        public ActionResult RecipeEdit(int recipeId)
        {
            var recipe = this.RecipeService.GetRecipeById(recipeId);

            // Issue 404 if recipe does not exists or not owned by user
            if (recipe == null || !recipe.WasCreatedBy(this.ActiveUser.UserId))
            {
                return(this.Issue404());
            }

            // Notify user that the recipe is not yet 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."
                });
            }

            ViewBag.RecipeCreationOptions = this.RecipeService.GetRecipeCreationOptions();

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


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

            recipeModel.TastingNotes = tastingNotes;

            var commentWrapperViewModel = new CommentWrapperViewModel();

            commentWrapperViewModel.CommentViewModels = Mapper.Map(this.RecipeService.GetRecipeComments(recipeId), new List <CommentViewModel>());
            commentWrapperViewModel.GenericId         = recipeId;
            commentWrapperViewModel.CommentType       = CommentType.Recipe;
            recipeModel.CommentWrapperViewModel       = commentWrapperViewModel;

            // Get the most recent brew session -- this should be added to the recipe in the service, really but hey
            recipeModel.MostRecentBrewSession = this.RecipeService.GetMostRecentBrewSession(recipeId);

            //if (Request["version"] != null && Request["Version"].ToString() == "2")
            //{
            return(View("RecipeEdit_V2", recipeModel));
            //}
            //else
            //{
            //    return View(recipeModel);
            //}
        }
Example #4
0
        public ActionResult MyBrewSessions()
        {
            var dashboardViewModel = new DashboardViewModel();

            dashboardViewModel.DashboardItems = new List <IDashboardItem>();

            // Sessions
            foreach (var brewSessionSummary in this.RecipeService.GetUserBrewSessions(this.ActiveUser.UserId))
            {
                var commentWrapperViewModel = new CommentWrapperViewModel();
                commentWrapperViewModel.CommentViewModels = Mapper.Map(brewSessionSummary.BrewSessionComments, new List <CommentViewModel>());
                commentWrapperViewModel.GenericId         = brewSessionSummary.BrewSessionId;
                commentWrapperViewModel.CommentType       = CommentType.Session;
                var brewSessionSummaryViewModel = Mapper.Map(brewSessionSummary, new BrewSessionSummaryViewModel());
                brewSessionSummaryViewModel.CommentWrapperViewModel = commentWrapperViewModel;
                brewSessionSummaryViewModel.ShowAddedBy             = false;
                dashboardViewModel.DashboardItems.Add(new DashboardItem {
                    Item = brewSessionSummaryViewModel
                });
            }

            return(View("_DashboardList", dashboardViewModel));
        }
Example #5
0
        public ActionResult AllMyRecipes()
        {
            var dashboardViewModel = new DashboardViewModel();

            dashboardViewModel.DashboardItems = new List <IDashboardItem>();

            // Recipes
            foreach (var recipeSummary in this.RecipeService.GetUserRecipes(this.ActiveUser.UserId))
            {
                var commentWrapperViewModel = new CommentWrapperViewModel();
                commentWrapperViewModel.CommentViewModels = Mapper.Map(recipeSummary.RecipeComments, new List <CommentViewModel>());
                commentWrapperViewModel.GenericId         = recipeSummary.RecipeId;
                commentWrapperViewModel.CommentType       = CommentType.Recipe;
                var recipeSummaryViewModel = Mapper.Map(recipeSummary, new RecipeSummaryViewModel());
                recipeSummaryViewModel.ShowAddedBy             = false;
                recipeSummaryViewModel.CommentWrapperViewModel = commentWrapperViewModel;
                dashboardViewModel.DashboardItems.Add(new DashboardItem {
                    Item = recipeSummaryViewModel
                });
            }

            return(View("_DashboardList", dashboardViewModel));
        }
        /// <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));
        }
Example #7
0
        public ActionResult AllMyDashboardItems(int?numberToReturn)
        {
            if (!numberToReturn.HasValue)
            {
                numberToReturn = 10;
            }

            var searchOlderThan = (!String.IsNullOrWhiteSpace(Request["SearchOlderThan"])) ? DateTime.Parse(Server.UrlDecode(Request["SearchOlderThan"])) : DateTime.Now;

            var dashboardItemHolder = this.RecipeService.GetDashboardItems(this.ActiveUser.UserId, searchOlderThan, (int)numberToReturn);

            var dashboardViewModel = new DashboardViewModel();

            dashboardViewModel.DashboardItems = new List <IDashboardItem>();

            // Recipes
            foreach (var recipeSummary in dashboardItemHolder.RecipeSummaries)
            {
                var commentWrapperViewModel = new CommentWrapperViewModel();
                commentWrapperViewModel.CommentViewModels = Mapper.Map(recipeSummary.RecipeComments, new List <CommentViewModel>());
                commentWrapperViewModel.GenericId         = recipeSummary.RecipeId;
                commentWrapperViewModel.CommentType       = CommentType.Recipe;

                var recipeSummaryViewModel = Mapper.Map(recipeSummary, new RecipeSummaryViewModel());
                recipeSummaryViewModel.ShowAddedBy             = true;
                recipeSummaryViewModel.CommentWrapperViewModel = commentWrapperViewModel;
                dashboardViewModel.DashboardItems.Add(new DashboardItem
                {
                    Item        = recipeSummaryViewModel,
                    DateCreated = recipeSummaryViewModel.DateCreated
                });
            }

            // Sessions
            foreach (var brewSessionSummary in dashboardItemHolder.BrewSessionSummaries)
            {
                var commentWrapperViewModel = new CommentWrapperViewModel();
                commentWrapperViewModel.CommentViewModels = Mapper.Map(brewSessionSummary.BrewSessionComments, new List <CommentViewModel>());
                commentWrapperViewModel.GenericId         = brewSessionSummary.BrewSessionId;
                commentWrapperViewModel.CommentType       = CommentType.Session;

                var brewSessionSummaryViewModel = Mapper.Map(brewSessionSummary, new BrewSessionSummaryViewModel());
                brewSessionSummaryViewModel.CommentWrapperViewModel = commentWrapperViewModel;
                brewSessionSummaryViewModel.ShowAddedBy             = true;
                dashboardViewModel.DashboardItems.Add(new DashboardItem
                {
                    Item        = brewSessionSummaryViewModel,
                    DateCreated = brewSessionSummaryViewModel.DateCreated
                });
            }

            // Tasting Notes
            foreach (var tastingNoteSummary in dashboardItemHolder.TastingNoteSummaries)
            {
                dashboardViewModel.DashboardItems.Add(new DashboardItem
                {
                    Item        = tastingNoteSummary,
                    DateCreated = tastingNoteSummary.DateCreated
                });
            }

            return(View("_DashboardList", dashboardViewModel));
        }