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)); }
/// <summary> /// Adds a new BrewSessionComment /// </summary> public void AddBrewSessionComment(BrewSessionComment brewSessionComment) { if (brewSessionComment == null) { throw new ArgumentNullException("brewSessionComment"); } brewSessionComment.UserId = this.UserResolver.Resolve().UserId; brewSessionComment.DateCreated = DateTime.Now; brewSessionComment.IsActive = true; this.Repository.Add(brewSessionComment); }