private void Initialize(CommentsInputModel commentsInputModel, bool useReviews) { const string ReviewsSuffix = "_review"; if (commentsInputModel == null) { return; } if (!string.IsNullOrEmpty(commentsInputModel.ThreadType)) { this.ThreadType = commentsInputModel.ThreadType; } if (!string.IsNullOrEmpty(commentsInputModel.ThreadKey)) { this.ThreadKey = commentsInputModel.ThreadKey; } else if (string.IsNullOrEmpty(this.ThreadKey)) { if (SiteMapBase.GetActualCurrentNode() != null) { this.ThreadKey = ControlUtilities.GetLocalizedKey(SiteMapBase.GetActualCurrentNode().Id, null, CommentsBehaviorUtilities.GetLocalizedKeySuffix(this.ThreadType)); } else { this.ThreadKey = string.Empty; } } if (useReviews && !this.ThreadKey.EndsWith(ReviewsSuffix)) { this.ThreadKey = this.ThreadKey + ReviewsSuffix; } else if (!useReviews && this.ThreadKey.EndsWith(ReviewsSuffix)) { this.ThreadKey = this.ThreadKey.Left(this.ThreadKey.Length - ReviewsSuffix.Length); } if (!string.IsNullOrEmpty(commentsInputModel.ThreadTitle)) { this.ThreadTitle = commentsInputModel.ThreadTitle; } if (!string.IsNullOrEmpty(commentsInputModel.GroupKey)) { this.GroupKey = commentsInputModel.GroupKey; } if (!string.IsNullOrEmpty(commentsInputModel.DataSource)) { this.DataSource = commentsInputModel.DataSource; } }
/// <inheritDoc/> public CommentsListViewModel GetCommentsListViewModel(CommentsInputModel inputModel, bool useReviews) { this.Initialize(inputModel, useReviews); var allowComments = (inputModel != null && inputModel.AllowComments.HasValue) ? inputModel.AllowComments.Value : this.AllowComments; if (allowComments) { var widgetResources = this.GetCommentsListWidgetResources(); var widgetSettings = this.GetCommentsListWidgetSettings(this.ThreadTitle, useReviews); var jsonSerializerSettings = new JsonSerializerSettings() { ContractResolver = new CamelCasePropertyNamesContractResolver() }; var viewModel = new CommentsListViewModel() { AllowSubscription = this.ThreadConfig.AllowSubscription && !this.ThreadIsClosed, CssClass = this.CssClass, EnablePaging = this.CommentsConfig.EnablePaging, LoginPageUrl = this.ThreadConfig.RequiresAuthentication ? this.LoginPageUrl : null, ThreadIsClosed = this.ThreadIsClosed, UserAvatarImageUrl = this.UserAvatarImageUrl, RequiresAuthentication = this.ThreadConfig.RequiresAuthentication, RequiresApproval = this.ThreadConfig.RequiresApproval, RequiresCaptcha = this.CommentsConfig.UseSpamProtectionImage, SerializedWidgetResources = JsonConvert.SerializeObject(widgetResources, Formatting.None, jsonSerializerSettings), SerializedWidgetSettings = JsonConvert.SerializeObject(widgetSettings, Formatting.None, jsonSerializerSettings), ThreadKey = widgetSettings.CommentsThreadKey, ThreadType = widgetSettings.CommentsThreadType }; return(viewModel); } else { return(null); } }
/// <summary> /// Gets comments view /// </summary> /// <returns></returns> public ActionResult Index(CommentsInputModel commentsInputModel) { if (commentsInputModel == null || !commentsInputModel.AllowComments.HasValue || commentsInputModel.AllowComments.Value) { var model = this.Model.GetCommentsListViewModel(commentsInputModel, false); if (model != null) { return this.View(this.templateNamePrefix + this.TemplateName, model); } } return new EmptyResult(); }