/// <summary>
		/// ctor the Mighty
		/// </summary>
		public RecipeCommentEmailMessage(IWebSettings webSettings, RecipeSummary recipeSummary, string commenterUsername, 
			UserSummary userToNotify, RecipeComment recipeComment, BrewgrUrlBuilder brewgrUrlBuilder) : base(webSettings)
		{
			this.WebSettings = webSettings;
			this.RecipeSummary = recipeSummary;
			this.CommenterUsername = commenterUsername;
			this.UserToNotify = userToNotify;
			this.RecipeComment = recipeComment;
			this.BrewgrUrlBuilder = brewgrUrlBuilder;

			// Set Sender
			this.SenderAddress = webSettings.SenderAddress;
			this.SenderDisplayName = webSettings.SenderDisplayName;

			// Set Recipient
			this.ToRecipients.Add(userToNotify.EmailAddress);

			// Build Subject
			if (recipeSummary.CreatedBy == userToNotify.UserId)
			{
				this.Subject = string.Format("{0} commented on your recipe, {1}", commenterUsername, recipeSummary.RecipeName);
			}
			else
			{
				this.Subject = string.Format("{0} also left a comment on the recipe, {1}", commenterUsername, recipeSummary.RecipeName);
			}
		}
        /// <summary>
        /// ctor the Mighty
        /// </summary>
        public RecipeCommentEmailMessage(IWebSettings webSettings, RecipeSummary recipeSummary, string commenterUsername,
                                         UserSummary userToNotify, RecipeComment recipeComment, BrewgrUrlBuilder brewgrUrlBuilder) : base(webSettings)
        {
            this.WebSettings       = webSettings;
            this.RecipeSummary     = recipeSummary;
            this.CommenterUsername = commenterUsername;
            this.UserToNotify      = userToNotify;
            this.RecipeComment     = recipeComment;
            this.BrewgrUrlBuilder  = brewgrUrlBuilder;

            // Set Sender
            this.SenderAddress     = webSettings.SenderAddress;
            this.SenderDisplayName = webSettings.SenderDisplayName;

            // Set Recipient
            this.ToRecipients.Add(userToNotify.EmailAddress);

            // Build Subject
            if (recipeSummary.CreatedBy == userToNotify.UserId)
            {
                this.Subject = string.Format("{0} commented on your recipe, {1}", commenterUsername, recipeSummary.RecipeName);
            }
            else
            {
                this.Subject = string.Format("{0} also left a comment on the recipe, {1}", commenterUsername, recipeSummary.RecipeName);
            }
        }
Exemplo n.º 3
0
        public ActionResult AddComment(CommentAddViewModel commentAddViewModel)
        {
            if (!commentAddViewModel.Validate().IsValid)
            {
                return this.Issue404();
            }

            // Normalize the Line Breaks
            commentAddViewModel.CommentText = commentAddViewModel.CommentText.Replace("\n", Environment.NewLine);

            switch (commentAddViewModel.CommentType)
            {
                case CommentType.Recipe:
                    RecipeComment recipeComment;

                    using (var unitOfWork = this.UnitOfWorkFactory.NewUnitOfWork())
                    {
                        recipeComment = new RecipeComment();
                        recipeComment.CommentText = commentAddViewModel.CommentText;
                        recipeComment.RecipeId = commentAddViewModel.GenericId;
                        this.RecipeService.AddRecipeComment(recipeComment);
                        unitOfWork.Commit();
                    }

                    // Queue Comment Notification
                    this.NotificationService.QueueNotification(NotificationType.RecipeComment, recipeComment);
                    break;
                case CommentType.Session:
                    BrewSessionComment brewSessionComment;

                    using (var unitOfWork = this.UnitOfWorkFactory.NewUnitOfWork())
                    {
                        brewSessionComment = new BrewSessionComment();
                        brewSessionComment.CommentText = commentAddViewModel.CommentText;
                        brewSessionComment.BrewSessionId = commentAddViewModel.GenericId;
                        this.RecipeService.AddBrewSessionComment(brewSessionComment);
                        unitOfWork.Commit();
                    }

                    // Queue Comment Notification
                    this.NotificationService.QueueNotification(NotificationType.BrewSessionComment, brewSessionComment);
                    break;
                default:
                    return this.Issue404();
            }
            
            var commentViewModel = new CommentViewModel();
            commentViewModel.CommentText = commentAddViewModel.CommentText;
            commentViewModel.UserId = this.ActiveUser.UserId;
            commentViewModel.UserName = this.ActiveUser.Username;
            commentViewModel.UserAvatarUrl = UserAvatar.GetAvatar(59, this.ActiveUser.EmailAddress);
            commentViewModel.DateCreated = DateTime.Now;

            return View("_Comment", commentViewModel);
        }